Skip to content

Incorrect namespace for cross-session memory retrieval in generated code #1279

@markproy

Description

@markproy

Description

Environment

  • AgentCore CLI Version: 0.14.0
  • Command used: agentcore create --memory longAndShortTerm
  • Framework: Strands (Python)

Description

When creating a new agent with long-term memory, the CLI generates a memory/session.py file that incorrectly scopes summary retrieval to only the current session, preventing cross-session memory recall.

Technical Explanation

According to the bedrock_agentcore.memory SDK implementation:

  1. The retrieve_customer_context() method in AgentCoreMemorySessionManager resolves namespace templates and passes them to memory_client.retrieve_memories()
  2. When using namespace_path parameter, it performs hierarchical prefix matching
  3. By including the specific {session_id} in the path, it only matches records under that exact session
  4. Removing /{session_id} allows prefix matching across all sessions for the actor

Reference: bedrock_agentcore/memory/integrations/strands/session_manager.py lines 847-871

Impact

  • High: Affects all agents created with --memory longAndShortTerm
  • Returning users don't benefit from conversation history across sessions
  • Significantly reduces the value proposition of long-term memory
  • Users may not notice the issue immediately, leading to suboptimal agent behavior in production

Workaround

Manually edit the generated memory/session.py to remove /{session_id} from the summaries namespace path.

Suggested Fix

Update the code generation template for Python/Strands agents with long-term memory to omit {session_id} from the summaries namespace configuration.

Steps to Reproduce

Reproduction Steps

  1. Run: agentcore create --project-name TestAgent --name TestAgent --language Python --framework Strands --model-provider Bedrock --memory longAndShortTerm
  2. Open: TestAgent/app/TestAgent/memory/session.py
  3. Observe line 22: f"/summaries/{actor_id}/{session_id}": RetrievalConfig(...)

Expected Behavior

Expected Behavior

Summaries should be retrieved across all sessions for the actor to enable true long-term memory:

retrieval_config = {
    f"/users/{actor_id}/facts": RetrievalConfig(top_k=3, relevance_score=0.5),
    f"/users/{actor_id}/preferences": RetrievalConfig(top_k=3, relevance_score=0.5),
    f"/summaries/{actor_id}": RetrievalConfig(top_k=3, relevance_score=0.5),  # ← Fixed: removed /{session_id}
}

Actual Behavior

Current Behavior (Bug)

The generated retrieval_config in app/<AgentName>/memory/session.py includes {session_id} in the summaries namespace:

retrieval_config = {
    f"/users/{actor_id}/facts": RetrievalConfig(top_k=3, relevance_score=0.5),
    f"/users/{actor_id}/preferences": RetrievalConfig(top_k=3, relevance_score=0.5),
    f"/summaries/{actor_id}/{session_id}": RetrievalConfig(top_k=3, relevance_score=0.5),  # ← Bug here
}

This means the agent only retrieves summaries from the current session, not from previous sessions.

CLI Version

0.14.0

Operating System

macOS

Additional Context

Additional Context

This issue was discovered when analyzing memory retrieval behavior in a banking assistant agent. The agent was unable to recall conversation summaries from previous sessions, which broke the personalization experience for returning users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions