You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MemorySessionManager.process_turn_with_llm raises KeyError: 'memoryStrategyId' for the default namespace templates #759
MemorySessionManager.process_turn_with_llm (and process_turn_with_llm_async, and the MemorySession wrappers) raise KeyError: 'memoryStrategyId' when a retrieval_config namespace contains {memoryStrategyId}.
The docstring of both methods says the namespace "can contain template variables like {actorId}, {sessionId}, {memoryStrategyId} that will be resolved at runtime". {memoryStrategyId} is also the variable in every default namespace the SDK creates (memory/constants.py:76-79, e.g. /strategies/{memoryStrategyId}/actors/{actorId}/), and the Strands session manager resolves it. So passing the namespace of a strategy created with the SDK fails before any retrieval or LLM call.
resolved_namespace=namespace.format(
actorId=actor_id,
sessionId=session_id,
strategyId=config.strategy_idor"", # the templates use memoryStrategyId
)
To Reproduce
Runs offline, boto3 is mocked.
fromunittest.mockimportMagicMock, patchfrombedrock_agentcore.memory.constantsimportRetrievalConfigfrombedrock_agentcore.memory.sessionimportMemorySessionManagerwithpatch("boto3.Session") assession_cls:
session_cls.return_value.region_name="us-west-2"dp=MagicMock()
session_cls.return_value.client.return_value=dpmanager=MemorySessionManager(memory_id="mem-1", region_name="us-west-2")
dp.retrieve_memory_records.return_value= {"memoryRecordSummaries": []}
dp.create_event.return_value= {"event": {"eventId": "e1"}}
# The SDK's default namespace for SEMANTIC and USER_PREFERENCE strategiesretrieval_config= {"/strategies/{memoryStrategyId}/actors/{actorId}/": RetrievalConfig(strategy_id="pref-123")}
manager.process_turn_with_llm(
actor_id="user-1",
session_id="s-1",
user_input="What do I like?",
llm_callback=lambdaq, m: "You like tea",
retrieval_config=retrieval_config,
)
Output:
File ".../bedrock_agentcore/memory/session.py", line 397, in _retrieve_memories_for_llm
resolved_namespace = namespace.format(
KeyError: 'memoryStrategyId'
Expected behavior
{memoryStrategyId} is replaced with RetrievalConfig.strategy_id, as documented, and the search runs on /strategies/pref-123/actors/user-1/. This is what AgentCoreMemorySessionManager.retrieve_customer_context already does.
The fix is one line: also pass memoryStrategyId=config.strategy_id or "" to format(), keeping strategyId so existing templates still work. A tested fix with a regression test is ready on branch chaitanya0305:fix/memory-strategy-id-template.
Activity