fix: scope summaries retrieval to actor for cross-session memory recall#1299
Conversation
…on memory
The generated session.py template included {session_id} in the summaries
namespace path, limiting retrieval to the current session only. This
prevented agents with longAndShortTerm memory from recalling conversation
summaries across sessions. Remove {session_id} so the hierarchical prefix
match finds summaries from all sessions for the given actor.
Closes aws#1279
Package TarballHow to installnpm install https://github.com/aws/agentcore-cli/releases/download/pr-1299-tarball/aws-agentcore-0.12.1.tgz |
agentcore-cli-automation
left a comment
There was a problem hiding this comment.
Fix looks correct and consistent with how retrieve_memories does hierarchical prefix matching. The write-side namespace (/summaries/{actorId}/{sessionId}) configured on the SUMMARIZATION strategy is unchanged, so existing data still organizes by session — only the read scope widens. Nice touch that this also brings create-time templates in line with the import translators (langgraph-translator.ts, strands-translator.ts), which already used /summaries/{user_id}/.
One thing worth addressing before merging:
docs/memory.md (line 95) still shows the buggy pattern this PR is fixing:
f"/summaries/{actor_id}/{session_id}": RetrievalConfig(top_k=3, relevance_score=0.5)Since that section is the canonical "set up memory by hand" example, leaving it as-is will steer users toward the same bug the PR fixes in the templates. Suggest updating it to f"/summaries/{actor_id}" to match, with a short note explaining the asymmetry (writes go under /summaries/{actor_id}/{session_id}, reads use prefix matching for cross-session recall).
Summary
/{session_id}from the summaries namespace path in the generatedmemory/session.pytemplate--memory longAndShortTermcan retrieve conversation summaries across sessions via hierarchical prefix matchingProblem
The generated retrieval config scoped summaries to
/summaries/{actor_id}/{session_id}, meaning the agent could only recall summaries from the current session. This completely defeated the purpose of long-term memory for returning users.Fix
Change the retrieval path from
/summaries/{actor_id}/{session_id}to/summaries/{actor_id}. The SDK'sretrieve_memories()uses hierarchical prefix matching, so this now finds summaries stored under any session for the actor.Writes still store under
/summaries/{actor_id}/{session_id}(SDK behavior), so session-level organization is preserved — only the read scope is widened.Test plan
npm run test:update-snapshots— snapshots regenerated--memory longAndShortTerm, invoke across two sessions, confirm second session retrieves first session's summariesCloses #1279