Persistent Context with Bedrock AgentCore Memory
Standard AI agents often suffer from "goldfish memory"βthey forget everything once a session ends. Bedrock AgentCore Memory solves this by providing a managed vector-based storage layer that persists across different conversations. By integrating this with Strands Agents, you can create personalized assistants that remember user preferences, past decisions, and key semantic facts over days, weeks, or months.
The framework supports multiple retrieval strategies, such as Summarization (to recap long histories), Preferences (to remember how a user likes their data formatted), and Semantic Facts (to store specific data points like "The user's favorite stock is AMZN"). This allows the agent to inject relevant long-term context into the prompt window only when needed, keeping the conversation efficient and relevant.
A. Initializing a Managed Memory Store
First, you create a memory resource in AgentCore. This setup defines how the agent should summarize and store incoming information into the underlying vector database.
from bedrock_agentcore.tools.memory_client import MemoryClient
# Initialize the Memory Client
memory_client = MemoryClient(region="us-east-1")
# Create a memory resource with specialized strategies
memory = memory_client.create_memory(
name="UserPersonaMemory",
storage_type="VECTOR",
strategies=[
{"type": "SUMMARY", "description": "Summarize the key points of the conversation."},
{"type": "PREFERENCE", "description": "Extract user-specific settings or likes."},
{"type": "SEMANTIC_FACT", "description": "Store specific facts mentioned by the user."}
]
)
memory_id = memory["id"]
print(f"Memory Store created with ID: {memory_id}")
B. Building an Agent with Cross-Session Continuity
By attaching the AgentCoreMemory tool to a Strands Agent, the agent automatically saves conversation events to the cloud. When a new session starts for the same user, the agent queries its memory to "remember" who it is talking to.
from strands import Agent
from strands.models import BedrockModel
from strands_tools.memory import AgentCoreMemory
# Initialize the memory tool for the agent
agentcore_memory = AgentCoreMemory(region="us-east-1", memory_id=memory_id)
# Create the agent with memory capabilities
agent = Agent(
model=BedrockModel(model_id="us.amazon.nova-pro-v1:0"),
system_prompt="You are a personal assistant. Use your memory to provide personalized help.",
tools=[agentcore_memory.memory]
)
# Session 1: User shares information
agent("Hi, my name is Alex and I prefer all financial reports in Markdown format.")
# Session 2 (Later): Agent remembers the user
response = agent("Can you generate a summary of the latest market trends for me?")
# Output: "Certainly, Alex! I've prepared that market trend summary in your preferred Markdown format..."
Key Takeaway: Bedrock AgentCore Memory transforms stateless bots into long-term digital companions. It manages the complex logic of vector embedding and retrieval behind the scenes, allowing developers to focus on building agents that provide a truly continuous and personalized user experience.

Top comments (0)