Skip to content

Strands integration ignores RetrievalConfig.relevance_score when injecting AgentCore Memory context #190

@nakedible

Description

@nakedible

Summary

In the Strands integration, RetrievalConfig.relevance_score is defined/configurable but appears to be ignored when retrieving and injecting AgentCore Memory results into agent.messages. This leads to low-relevance memories being injected even when a high threshold is configured.

Where

src/bedrock_agentcore/memory/integrations/strands/session_manager.py

  • AgentCoreMemorySessionManager.retrieve_customer_context(...) (and its inner retrieval/injection logic)

Expected behavior

If RetrievalConfig.relevance_score is set (e.g. 0.9), only memory records with relevanceScore >= relevance_score should be injected into the <user_context>...</user_context> block, mirroring the behavior in:

  • src/bedrock_agentcore/memory/session.pyMemorySessionManager._retrieve_memories_for_llm(...) (client-side filtering by relevanceScore)

Actual behavior

The Strands integration injects whatever the service returns in the top_k results (and concatenates their content.text), without applying the configured minimum relevance threshold.

Why this matters

  • Injects irrelevant context → worse model outputs
  • Increased context size / token usage
  • Confusing UX because the option exists (and has a default) but does not affect behavior

Steps to reproduce

  1. Configure Strands with AgentCore Memory session manager and a high threshold:
    RetrievalConfig(top_k=10, relevance_score=0.9, ...)
  2. Ensure retrieval returns at least one record with a low relevanceScore (e.g. 0.1–0.3) and at least one with a high score (e.g. 0.9+). (This can be done by mocking memory_client.retrieve_memories(...) in a unit test.)
  3. Send a user message that triggers retrieve_customer_context.
  4. Observe that the injected <user_context> includes the low-score record(s) despite the threshold.

Suggested fix

Apply the same client-side filtering used by MemorySessionManager._retrieve_memories_for_llm(...) inside the Strands retrieval path before building the injected context:

  • If relevance_score is non-zero, filter memory records by record.get("relevanceScore", ...) >= relevance_score.

Environment

  • bedrock-agentcore-sdk-python: v1.1.1 (also reproducible on main as of Dec 2025)
  • strands-agents: (please fill)
  • Python: (please fill)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions