By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Agents need to remember things across conversations, but raw event logs are too noisy. You need to decide what gets extracted and stored long-term—and you need to do it in a way that respects user privacy. AgentCore handles extraction for you, but you still choose the strategy and build the namespace isolation.
A strategy is a rule that tells AgentCore what to extract from raw events. The four built-in ones are semantic (durable facts like 'order #4521 is pending a refund'), user preference (choices and styles like 'prefers email, never SMS'), summary (a running summary of each session), and episodic (structured episodes with scenario, intent, actions, and outcome—lets agents learn from past experience).
If the built-ins don't fit your domain, you can write a custom strategy by appending to the extraction prompt and picking the model yourself. Built-in strategies run in a service-managed account, so you don't operate any extraction pipeline.
The pattern is always the same: create memory once, write events during conversation, retrieve records later. Method names evolve across SDK versions, so check what you've installed. The underlying shape stays stable.
from bedrock_agentcore.memory import MemoryClient
client = MemoryClient(region_name="us-west-2")
# 1) Create the memory resource ONCE (infra-level step)
memory = client.create_memory_and_wait(
name="SupportMemory",
strategies=[
{"semanticMemoryStrategy": {"name": "Facts", "namespaces": ["/facts/{actorId}"]}},
{"userPreferenceMemoryStrategy": {"name": "Prefs", "namespaces": ["/prefs/{actorId}"]}},
],
event_expiry_days=30, # how long RAW events are kept
)
memory_id = memory["id"]
Step one creates the memory resource and configures which strategies to run. You pass a list of strategies with their namespaces. The event_expiry_days parameter controls how long raw events are kept before they're discarded.
# 2) During a conversation: save what happened (short-term)
client.create_event(
memory_id=memory_id,
actor_id="user-alice",
session_id="session-001",
messages=[
("I wear size 9 and I love Nike shoes.", "USER"),
("Great, noted!", "ASSISTANT"),
],
)
# 3) Later, in ANY session: semantic search over long-term records
records = client.retrieve_memories(
memory_id=memory_id,
namespace="/prefs/user-alice",
query="what shoes does she like?",
top_k=3,
)
for r in records:
print(r["content"]["text"])
Step two happens during a conversation: you call create_event with the actor ID, session ID, and messages. Step three runs later—in any session—when you call retrieve_memories with a namespace and a semantic query. The service returns the top-k records that match.
The {actorId} placeholder in your namespace path gives every user their own isolated silo. When you retrieve with /prefs/user-alice, you can only ever see Alice's records. The critical rule: always build the namespace from the authenticated user, never from text the user typed.
Enable only the strategies you will actually retrieve from. Each one adds processing cost. Expect a short delay—often around a minute—before long-term records appear in retrieval. Episodic extraction is the slowest of the four.
In your agent code, wrap retrieval in a tool or a pre-prompt step. Fetch the top few records and add them to the system prompt before the agent runs. AgentCore integrates with LangGraph, LangChain, Strands, and LlamaIndex, so you can slot memory retrieval into whatever framework you're already using.
Always build the namespace from the authenticated user, never from text the user typed.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.