Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/bedrock_agentcore/memory/integrations/strands/config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
"""Configuration for AgentCore Memory Session Manager."""

from typing import Dict, Optional
from typing import Dict, List, Optional

from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, field_validator

from bedrock_agentcore.memory.constants import MessageRole
from bedrock_agentcore.memory.models import StringValue


class BranchConfig(BaseModel):
"""Configuration for AgentCore Memory branching.

Attributes:
name: Descriptive name for the branch
root_event_id: ID of the event from which this branch originates
"""

name: str = Field(min_length=1)
root_event_id: Optional[str] = ""

def to_agentcore_format(self) -> dict:
"""Convert to AgentCore Memory API format."""
return {"name": self.name, "rootEventId": self.root_event_id}


class RetrievalConfig(BaseModel):
Expand All @@ -21,6 +40,13 @@ class RetrievalConfig(BaseModel):
initialization_query: Optional[str] = None


class ShortTermRetrievalConfig(BaseModel):
"""Configuration for Short term memory retrieval operations"""

branch_filter: Optional[bool] = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a plan to have branching on LTM? We can refactor later but then we should consider lifting the branch_filter into a base class

metadata: Optional[Dict[str, StringValue]] = None


class AgentCoreMemoryConfig(BaseModel):
"""Configuration for AgentCore Memory Session Manager.

Expand All @@ -29,9 +55,29 @@ class AgentCoreMemoryConfig(BaseModel):
session_id: Required unique ID for the session
actor_id: Required unique ID for the agent instance/user
retrieval_config: Optional dictionary mapping namespaces to retrieval configurations
default_branch: Optional default branch configuration for the session
message_types: Optional list of message types to filter
metadata: Optional dictionary of metadata to include with events
"""

memory_id: str = Field(min_length=1)
session_id: str = Field(min_length=1)
actor_id: str = Field(min_length=1)
retrieval_config: Optional[Dict[str, RetrievalConfig]] = None
default_branch: Optional[BranchConfig] = Field(
default_factory=lambda: BranchConfig(name="main", root_event_id="")
)
short_term_retrieval_config: Optional[ShortTermRetrievalConfig] = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this needs it's own variable? Can we allow for this to be set to the retrieval_config? Or do we anticipate users passing in both STM and LTM config for the same session?

ShortTermRetrievalConfig()
)
message_types: Optional[List[str]] = Field(default=["user", "assistant"])
metadata: Optional[Dict[str, StringValue]] = (
None # Currently only supports agent_id. Will be extended further.
)

@field_validator("memory_id", "session_id", "actor_id")
@classmethod
def validate_non_empty_strings(cls, v: str) -> str:
if not v or not v.strip():
raise ValueError("must be a non-empty string")
return v
Loading