Skip to content

MemorySessionManager.process_turn_with_llm raises KeyError: 'memoryStrategyId' for the default namespace templates #759

Backlog

Description

@chaitanya0305

Describe the bug

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.

Root cause, src/bedrock_agentcore/memory/session.py:397 (_retrieve_memories_for_llm):

resolved_namespace = namespace.format(
    actorId=actor_id,
    sessionId=session_id,
    strategyId=config.strategy_id or "",   # the templates use memoryStrategyId
)

To Reproduce

Runs offline, boto3 is mocked.

from unittest.mock import MagicMock, patch

from bedrock_agentcore.memory.constants import RetrievalConfig
from bedrock_agentcore.memory.session import MemorySessionManager

with patch("boto3.Session") as session_cls:
    session_cls.return_value.region_name = "us-west-2"
    dp = MagicMock()
    session_cls.return_value.client.return_value = dp
    manager = 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 strategies
retrieval_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=lambda q, 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.

Environment

  • bedrock-agentcore 1.28.0 (main @ 9ab8cea)
  • Python 3.12, macOS

Additional context

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

  1. added
    bug
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions