Skip to content

Commit 1b127d6

Browse files
jariy17claude
andcommitted
Add Project class for agentcore.json configuration management
- Create Project class to load/save agentcore.json format (starter-toolkit) - Create ProjectConfig Pydantic models matching agentcore.json schema - Move YAML loading/saving logic from Agent/Memory to Project - Remove from_yaml() and save() methods from Agent and Memory classes - Add tests for Project class - Export Project from bedrock_agentcore package Project provides: - from_json() to load agentcore.json and create Agent/Memory objects - save() to generate agentcore.json from Agent/Memory objects - save_deployed_state() for deployed-state.json output - save_aws_targets() for aws-targets.json output - Bulk operations: launch_all(), destroy_all(), status() Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1a2ab51 commit 1b127d6

File tree

9 files changed

+988
-475
lines changed

9 files changed

+988
-475
lines changed

src/bedrock_agentcore/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""BedrockAgentCore Runtime SDK - A Python SDK for building and deploying AI agents."""
22

3+
from .project import Project
34
from .runtime import BedrockAgentCoreApp, BedrockAgentCoreContext, RequestContext
45
from .runtime.models import PingStatus
56

67
__all__ = [
78
"BedrockAgentCoreApp",
89
"PingStatus",
10+
"Project",
911
"RequestContext",
1012
"BedrockAgentCoreContext",
1113
]

src/bedrock_agentcore/memory/memory.py

Lines changed: 9 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
"""Memory class for managing Bedrock AgentCore Memory resources.
22
33
This module provides a high-level Memory class that wraps memory operations
4-
with YAML-based configuration persistence.
4+
for Bedrock AgentCore Memory resources.
55
"""
66

77
import logging
88
import time
9-
from pathlib import Path
109
from typing import TYPE_CHECKING, Any, Dict, List, Optional
1110

12-
import yaml
1311
from botocore.exceptions import ClientError
1412

1513
from .client import MemoryClient
@@ -22,19 +20,20 @@
2220

2321

2422
class Memory:
25-
"""Represents a Bedrock AgentCore Memory with YAML-based configuration.
23+
"""Represents a Bedrock AgentCore Memory resource.
2624
27-
Each Memory instance manages a single memory resource. Configuration is provided
28-
at construction time and can be saved to/loaded from YAML files.
25+
Each Memory instance manages a single memory resource. Use Project.from_json()
26+
to load memories from configuration files.
2927
3028
Example:
3129
# Create with config
32-
memory = Memory(name="my-memory", strategies=[...])
33-
memory.save("my-memory.agentcore.yaml")
30+
memory = Memory(
31+
name="my-memory",
32+
strategies=[{"type": "SEMANTIC", "namespace": "facts/{sessionId}/"}]
33+
)
3434
memory.launch()
3535
36-
# Or load from file
37-
memory = Memory.from_yaml("my-memory.agentcore.yaml")
36+
# Get a session for conversational operations
3837
session = memory.get_session(actor_id="user-123", session_id="sess-456")
3938
4039
Attributes:
@@ -92,56 +91,6 @@ def __init__(
9291

9392
logger.info("Initialized Memory '%s' in region %s", name, self._client.region_name)
9493

95-
@classmethod
96-
def from_yaml(cls, file_path: str, region: Optional[str] = None) -> "Memory":
97-
"""Load a memory from a YAML configuration file.
98-
99-
Args:
100-
file_path: Path to the YAML config file
101-
region: AWS region (overrides any region in config)
102-
103-
Returns:
104-
Memory instance with loaded configuration
105-
106-
Raises:
107-
FileNotFoundError: If config file doesn't exist
108-
"""
109-
path = Path(file_path)
110-
if not path.exists():
111-
raise FileNotFoundError(f"Config file not found: {file_path}")
112-
113-
with open(path, "r") as f:
114-
data = yaml.safe_load(f)
115-
116-
config = MemoryConfigModel.model_validate(data)
117-
118-
# Convert strategy models to dicts
119-
strategies = None
120-
if config.strategies:
121-
strategies = [
122-
{
123-
"type": s.strategy_type.value,
124-
"namespace": s.namespace,
125-
"customPrompt": s.custom_prompt,
126-
}
127-
for s in config.strategies
128-
]
129-
130-
memory = cls(
131-
name=config.name,
132-
description=config.description,
133-
strategies=strategies,
134-
encryption_key_arn=config.encryption_key_arn,
135-
tags=config.tags,
136-
region=region,
137-
)
138-
139-
# Try to find existing memory
140-
memory._refresh_memory_state()
141-
142-
logger.info("Loaded Memory '%s' from %s", config.name, file_path)
143-
return memory
144-
14594
# ==================== PROPERTIES ====================
14695

14796
@property
@@ -172,24 +121,6 @@ def is_active(self) -> bool:
172121

173122
# ==================== OPERATIONS ====================
174123

175-
def save(self, file_path: str) -> str:
176-
"""Save the memory configuration to a YAML file.
177-
178-
Args:
179-
file_path: Path to save the YAML config file
180-
181-
Returns:
182-
The file path where config was saved
183-
"""
184-
path = Path(file_path)
185-
data = self._config.model_dump(mode="json", by_alias=True, exclude_none=True)
186-
187-
with open(path, "w") as f:
188-
yaml.dump(data, f, default_flow_style=False, sort_keys=False)
189-
190-
logger.info("Saved Memory config to %s", file_path)
191-
return str(path)
192-
193124
def launch(
194125
self,
195126
max_wait: int = 600,

0 commit comments

Comments
 (0)