AWS Bedrock AgentCore Memory: retrieval returns stale or empty context
Fix AgentCore Memory retrieval returning empty or stale context by diagnosing the async long-term consolidation delay, short-term vs long-term memory, actor/session scoping, and namespace mismatches.
This runbook covers AgentCore Memory retrieval failures. For where Memory fits in the platform, see Amazon Bedrock AgentCore architecture and pricing. For ongoing agent operations, book a consulting session.
Symptoms
The failure shows up in one of two shapes. Identify yours first, because the fix differs.
# 1. Empty retrieval - the query returns nothing
retrieveMemoryRecords -> { "memoryRecords": [] }
# ...even though events were written earlier in the same or a prior session.
# 2. Stale retrieval - the query returns old context
# The agent answers with facts from a previous session and misses what the
# user said moments ago, or long-term preferences never show up at all.
Observable impact:
- The agent “forgets” a fact the user gave it seconds ago (short-term path)
- Long-term preferences or summaries never surface, even across sessions (long-term path)
- Retrieval works in one session but returns empty for the same user in another
Cause
AgentCore Memory has two distinct layers, and most retrieval bugs come from confusing them or from scoping records to the wrong keys.
- Short-term memory is immediate; long-term memory is not. Raw events you write are available right away for the current session. Long-term memory (facts, preferences, session summaries) is produced by an asynchronous consolidation step that runs after events are written. Query long-term records immediately and you get an empty result, not because the write failed, but because consolidation has not finished yet.
- Retrieval is scoped by actor, session, and namespace. Records are written against an
actorIdandsessionIdand organised into namespaces by strategy. If you retrieve with a differentactorId(for example a per-request identifier instead of a stable user id), a differentsessionIdthan you expect, or a namespace that does not match the strategy that produced the records, you get empty or stale results even though the data exists.
Common triggers:
- Reading long-term memory right after writing - querying before async consolidation has run
- Unstable actor id - a new
actorIdper request instead of a stable per-user id, so history never lines up - Session vs long-term confusion - expecting cross-session recall from short-term (session-scoped) reads
- Namespace / strategy mismatch - retrieving from a namespace the configured memory strategy never wrote to
Fix
Step 1: Confirm which failure mode you have
First check whether the events were written at all, then whether long-term records exist yet.
# Are the raw events present for this actor + session? (short-term path)
aws bedrock-agentcore list-events \
--memory-id your-memory-id \
--actor-id user-123 \
--session-id session-abc \
--region us-west-2
# Do consolidated long-term records exist for this actor? (long-term path)
aws bedrock-agentcore retrieve-memory-records \
--memory-id your-memory-id \
--namespace "/strategies/your-strategy/actor/user-123" \
--search-criteria '{"searchQuery":"user preferences"}' \
--region us-west-2
If events exist but long-term records are empty, it is the consolidation delay (Step 2). If events themselves are missing for the id you expect, it is a scoping problem (Step 3).
Step 2: Account for the async long-term consolidation delay
Long-term memory is produced asynchronously after events are written. Do not read a long-term record on the same turn you wrote the source event and expect it to be there.
- For the current turn, read from short-term (recent events / session context), which is immediate
- Let long-term consolidation happen between turns; retrieve long-term records on subsequent turns or sessions
- Do not block a user response waiting for a long-term record that has not consolidated yet
# Anti-pattern: write an event, then immediately expect a long-term record
client.create_event(memoryId=mid, actorId=uid, sessionId=sid, payload=turn)
prefs = client.retrieve_memory_records(...) # likely still empty this turn
# Better: use recent events for the current turn; read long-term next turn
recent = client.list_events(memoryId=mid, actorId=uid, sessionId=sid)
# long-term prefs are read on a later turn, after consolidation
Step 3: Make actor, session, and namespace scoping consistent
Write and read with the same stable actorId, the intended sessionId, and a namespace that matches the strategy that produced the records.
- Use a stable per-user
actorId(e.g. your internal user id), never a per-request or random value - Scope short-term recall to the correct
sessionId; scope cross-session recall to the actor’s long-term namespace - Confirm the namespace path matches the configured memory strategy - a query against a namespace no strategy writes to always returns empty
Step 4: Verify the memory strategy is configured for what you retrieve
If you expect summaries or extracted preferences but only ever wrote raw events, check that a long-term strategy (e.g. summarisation or preference extraction) is actually enabled on the memory resource. Without a matching strategy, there is nothing to consolidate and long-term retrieval stays empty by design.
aws bedrock-agentcore get-memory \
--memory-id your-memory-id \
--region us-west-2
# Confirm the expected long-term strategy is present and ENABLED.
Validation
Confirm the intended memory path returns what you expect.
# Short-term: recent events for the session return immediately
aws bedrock-agentcore list-events \
--memory-id your-memory-id --actor-id user-123 --session-id session-abc \
--region us-west-2
# Long-term: after consolidation, a retrieval for the same actor returns records
aws bedrock-agentcore retrieve-memory-records \
--memory-id your-memory-id \
--namespace "/strategies/your-strategy/actor/user-123" \
--search-criteria '{"searchQuery":"user preferences"}' \
--region us-west-2
Expected: short-term events return on the current turn; long-term records return non-empty on a subsequent turn for the same stable actorId. If long-term is still empty after consolidation, the strategy or namespace is mismatched (Steps 3-4).
Related
- Amazon Bedrock AgentCore: architecture, components, and pricing - where Memory fits among the components
- AWS Loom: governing AI agents on AWS - the wider platform Memory sits inside
- AWS Bedrock AgentCore Memory documentation