DEV Community

Vimal Venugopal
Vimal Venugopal

Posted on

Amazon Bedrock AgentCore Memory: Building Stateful AI Agents

AgentCore Memory is a fully managed service that lets AI agents retain past interactions, so they can deliver smarter, more context-aware, and personalized experiences. It offers a clean, powerful way to manage both short-term context and long-term knowledge without you having to design or maintain complex infrastructure.

At its core, AgentCore Memory solves a key limitation in agentic AI: stateless behavior. Without memory, agents reset on every interaction and lose all prior context. AgentCore Memory fills this gap by enabling agents to remember, learn, and build a consistent understanding of users over time.

Why we need AgentCore Memory what problem does it solve

AgentCoreMemory

AgentCoreMemory Summary

Architecture of AgentCore Memory - Key Components

AgentCoreMemory Architecture

AgentCoreMemory

# Creating a new memory resource 
response = agentcore_client.create_memory(
    name="CustomerSupportMemory",
    description="Memory store for our customer support agent",
    eventExpiryDuration=45,  # Store raw events for 45 days
    encryptionKeyArn="arn:aws:kms:us-east-1:123456789012:key/abcd1234-...",  # Optional customer-managed KMS key
)

# Storing a user message as an event
response = agentcore_client.create_event(
    memoryId="mem-908abcd",
    actorId="customer-345",
    sessionId="session-678",
    eventTimestamp=int(time.time() * 1000),
    payload=[
        {
            "conversational": {
                "content": {"text": "I'm looking for a Digital Camera under $500"},
                "role": "USER"
            }
        }
    ]
)

# Retrieving recent conversation history
events = agentcore_client.list_events(
    memoryId="mem-908abcd",
    actorId="customer-345",
    sessionId="session-678",
    maxResults=20,
)
Enter fullscreen mode Exit fullscreen mode

3. Long-term memory
Long-term memory identifies and preserves important information from conversations across multiple sessions, such as user preferences, key facts, and summarized context, enabling durable knowledge retention over time. Long-term memory contains extracted insights, preferences, and knowledge derived from raw events. Unlike short-term memory, which stores verbatim data, long-term memory captures meaningful information that persists across sessions—such as user preferences, conversation summaries, and key insights.

Example: If a customer says they prefer window seats when booking a flight, the agent saves this preference and can automatically offer window seats in future bookings, delivering a more personalized experience.

AgentCoreMemory

The extraction process happens asynchronously after events are created, using the memory strategies defined within your memory resource. This managed asynchronous process extracts and consolidates long term memory records for efficient retrieval.

Let’s explore how to create the long-term memory resource for the customer support agent we saw before:

# Creating a new memory resource with long term
response = agentcore_client.create_memory(
    name="CustomerSupportMemory",
    description="Memory store for our support portal",
    eventExpiryDuration=45,  # Store raw events for 45 days
    encryptionKeyArn="arn:aws:kms:us-east-1:123456789012:key/abcderf1234-...",  # Optional customer-managed KMS key
    memoryStrategies=[{
        "userPreferenceMemoryStrategy": {
            "name": "Preferences",
            "namespaces": ["support-portal/{actorId}/preferences"]
        }
    }]
)
Enter fullscreen mode Exit fullscreen mode

AgentCoreMemory

AgentCoreMemory - Strategies

AgentCoreMemory

AgentCoreMemory

Conclusion
Amazon Bedrock AgentCore Memory provides a comprehensive solution to maintaining state, context and learning from interactions. By combining flexible short-term event storage with intelligent long-term memory extraction, you can create more personalized, contextual AI experiences without managing complex memory infrastructure.

Refer to the basic Implementation Guide

Final Overall Architecture
Now that we understand the key components, here’s what the overall AgentCore Memory architecture looks like:

AgentCoreMemory

References
https://aws.amazon.com/blogs/machine-learning/amazon-bedrock-agentcore-memory-building-context-aware-agents/

https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory.html

Top comments (0)