-
Notifications
You must be signed in to change notification settings - Fork 70
Description
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.py→MemorySessionManager._retrieve_memories_for_llm(...)(client-side filtering byrelevanceScore)
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
- Configure Strands with AgentCore Memory session manager and a high threshold:
RetrievalConfig(top_k=10, relevance_score=0.9, ...)
- 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 mockingmemory_client.retrieve_memories(...)in a unit test.) - Send a user message that triggers
retrieve_customer_context. - 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_scoreis non-zero, filter memory records byrecord.get("relevanceScore", ...) >= relevance_score.
Environment
- bedrock-agentcore-sdk-python: v1.1.1 (also reproducible on
mainas of Dec 2025) - strands-agents: (please fill)
- Python: (please fill)