• Documentation
  • Pricing
© 2026 Serverless, Inc. All rights reserved.

Framework

  • Overview
  • Documentation
  • Plugins360
  • Pricing

Learn

  • Blog
  • GuidesUpdated
  • Examples240
  • Courses

Resources

  • Support
  • Security
  • Trust Center
  • Status

Community

  • Slack
  • GitHub47k
  • Forum
  • Meetups

Company

  • About
  • Careers
  • Contact
  • Partners

Legal

  • Terms of Service
  • Privacy Policy
  • Trademark
  • DMCA
Serverless Framework Logo

Serverless Framework

Intro
SetupUpgrading To V4ConceptsTutorialAWS CredentialsLicense Keys
DeployingPackagingBuildingTestingDev ModeServicesFunctions
OverviewHTTP (API Gateway v2)REST (API Gateway v1)ActiveMQApplication Load BalancerAlexa SkillAlexa Smart HomeCloudWatch EventCloudWatch LogCloudFrontCognito User PoolEventBridge EventIoTIoT Fleet ProvisioningKafkaKinesis & DynamoDBMSKRabbitMQS3ScheduleSNSSQSWebsocket
LayersManaged InstancesWeb Apps (Lambda Web Functions)Sandboxes (Lambda MicroVMs)MCP ServersAlertsVersion PruningDomainsIAM Function PermissionsParameters
OverviewSelf-reference serverless.ymlServerless CoreEnvironment VariablesCLI OptionsExternal YAML/JSON FilesJavascript propertiesGitDoppler
OverviewS3 ObjectsSSM Parameter Store & Secrets ManagerCloudFormation Stack Outputs
OverviewVaultTerraform State Output
ResourcesComposing ServicesDeployment BucketStateAgent SkillsPython support
OverviewRuntimeGatewayMemoryBrowserCode InterpreterDev Mode
API Gateway Proxy
OverviewGeneral ConfigurationAuthenticationAPI KeysData SourcesResolversPipeline FunctionsSubstitutionsCachingDelta SyncCustom DomainWAFCLI Commands
Deploying SAM/CFN TemplatesWorkflow Tips
OverviewCreating PluginsCLI OutputCustom CommandsCustom VariablesExtending the Configuration schemaExtending and overriding configuration
OverviewDashboardAxiom
Overviewagent docsagent inspectagent setupagent skills installagent skills list / readdeploydeploy functiondeploy listdevdiffinfoinvokeinvoke localloginlogin awslogin aws ssologsmetricspackageplugin installplugin uninstallprintprunereconcileremoverollbackrollback functionusage
OverviewConcepts
OverviewMetricsTracesTroubleshoot
OverviewNode.jsPython
OutputsProviders
OverviewBranch DeploymentsPreview DeploymentsCustom ScriptsTestingPrivate PackagesNotificationsMono ReposDeploy in your own CI/CDBest PracticesTroubleshootingFAQ
OverviewSetupToolsAWS Integration
Serverless.yml Reference
Examples and TutorialsConfiguration Validation
  1. Usage
  2. AI Agents
  3. Memory

AgentCore Memory for agents

Amazon Bedrock AgentCore Memory stores an agent's conversation events (short-term memory) and, with memory strategies, extracts facts, summaries and preferences from them (long-term memory). In serverless.yml, set memory on an agent, or define memory under ai.memory and share it between agents; the Framework creates the memory resource and its role, gives the agent access, and sets BEDROCK_AGENTCORE_MEMORY_ID in the agent's environment.

This agent gets its own memory, which keeps events for 30 days:

# serverless.yml
ai:
  agents:
    assistant:
      memory:
        expiration: 30

AgentCore Memory doesn't record conversations by itself: the agent code saves each turn and reads history back, as Use memory in agent code shows.

Use memory in agent code

Memory organizes events by actor ID (the user or entity the memory belongs to) and session ID (one conversation). The agent chooses both: for example, the user ID from the request and the AgentCore session ID. Requests with the same actor and session read the same history.

In Python, the Amazon Bedrock AgentCore SDK provides MemoryClient:

import os

from bedrock_agentcore.memory import MemoryClient

MEMORY_ID = os.environ["BEDROCK_AGENTCORE_MEMORY_ID"]
memory = MemoryClient(region_name=os.environ["AWS_REGION"])

memory.create_event(
    memory_id=MEMORY_ID,
    actor_id="user-123",
    session_id="session-456",
    messages=[
        ("What's the weather?", "USER"),
        ("Today is sunny.", "ASSISTANT"),
    ],
)

events = memory.list_events(
    memory_id=MEMORY_ID,
    actor_id="user-123",
    session_id="session-456",
    max_results=10,
)

For Strands Agents, the same SDK provides AgentCoreMemorySessionManager in bedrock_agentcore.memory.integrations.strands, which saves and loads the conversation for you.

In JavaScript, use @aws-sdk/client-bedrock-agentcore:

import {
  BedrockAgentCoreClient,
  CreateEventCommand,
  ListEventsCommand,
} from '@aws-sdk/client-bedrock-agentcore'

const MEMORY_ID = process.env.BEDROCK_AGENTCORE_MEMORY_ID
const client = new BedrockAgentCoreClient()

await client.send(
  new CreateEventCommand({
    memoryId: MEMORY_ID,
    actorId: 'user-123',
    sessionId: 'session-456',
    eventTimestamp: new Date(),
    payload: [
      {
        conversational: {
          content: { text: "What's the weather?" },
          role: 'USER',
        },
      },
      {
        conversational: {
          content: { text: 'Today is sunny.' },
          role: 'ASSISTANT',
        },
      },
    ],
  }),
)

const { events } = await client.send(
  new ListEventsCommand({
    memoryId: MEMORY_ID,
    actorId: 'user-123',
    sessionId: 'session-456',
    maxResults: 10,
  }),
)

The agent's generated role allows CreateEvent, GetEvent, ListEvents, DeleteEvent, ListSessions, ListActors, RetrieveMemoryRecords, ListMemoryRecords, GetMemoryRecord and GetMemory on its memory.

Share memory between agents

To let several agents read and write the same memory, define it under ai.memory and reference it by name in each agent's memory:

ai:
  memory:
    conversations:
      expiration: 90
      description: Conversation memory shared by the support agents

  agents:
    triage:
      memory: conversations
    specialist:
      memory: conversations

An agent's memory is either the name of an entry in ai.memory or an inline memory object. An inline memory belongs to one agent and is named <agent>-memory in the stack. A name that isn't in ai.memory stops the deployment.

Extract long-term memory with strategies

Memory strategies turn events into long-term memory records that the agent retrieves with RetrieveMemoryRecords. Each entry in strategies has one strategy type as its key, with the AWS property names:

ai:
  memory:
    conversations:
      expiration: 90
      strategies:
        - SemanticMemoryStrategy:
            Name: Facts
            Description: Facts the user shared
            Namespaces:
              - /facts/{actorId}/
        - SummaryMemoryStrategy:
            Name: SessionSummaries
            Namespaces:
              - /summaries/{actorId}/{sessionId}/
        - UserPreferenceMemoryStrategy:
            Name: Preferences
            Namespaces:
              - /preferences/{actorId}/
StrategyExtracts
SemanticMemoryStrategyFacts and knowledge from conversations
SummaryMemoryStrategyA running summary of each session
UserPreferenceMemoryStrategyUser preferences and choices
EpisodicMemoryStrategyEpisodes of interactions, with optional reflections (ReflectionConfiguration)
CustomMemoryStrategyOne of the above with your own prompt and model (Configuration)

Every strategy needs Name, which matches ^[a-zA-Z][a-zA-Z0-9_]{0,47}$. Description and Namespaces are optional. A namespace is a path that groups the extracted records, and can use the variables {actorId}, {sessionId} and {memoryStrategyId}; see Memory organization. The Framework passes the strategies to AWS unchanged, so every property of AWS::BedrockAgentCore::Memory MemoryStrategy works.

CustomMemoryStrategy takes a Configuration with one override, for example to change the extraction prompt and model of semantic memory:

ai:
  memory:
    travel:
      strategies:
        - CustomMemoryStrategy:
            Name: TravelFacts
            Namespaces:
              - /travel/{actorId}/
            Configuration:
              SemanticOverride:
                Extraction:
                  AppendToPrompt: Extract only facts about the user's travel plans.
                  ModelId: us.anthropic.claude-sonnet-4-5-20250929-v1:0

Configuration takes one of SemanticOverride, SummaryOverride, UserPreferenceOverride, EpisodicOverride or SelfManagedConfiguration, as defined in CustomMemoryStrategy.

Event expiration and encryption

expiration is the number of days AgentCore keeps events, from 3 to 365; the default is 30. encryptionKey takes the ARN of an AWS KMS key that encrypts the memory; without it, AgentCore encrypts the memory with a service-managed key. The credentials that deploy the service need kms:CreateGrant, kms:Decrypt, kms:DescribeKey and kms:GenerateDataKey on the key, as Encrypt your AgentCore Memory describes:

ai:
  memory:
    conversations:
      expiration: 180
      encryptionKey: arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab

IAM role for memory

AgentCore uses the memory's execution role to call Bedrock models when it extracts long-term memory. Without role, the Framework creates one per memory, named <service>_<memory>_memory_role_<stage> (truncated to 48 characters), with the AWS managed policy AmazonBedrockAgentCoreMemoryBedrockModelInferenceExecutionRolePolicy.

To add permissions, set role to an object. The managed policy stays attached, and statements go into an extra inline policy:

ai:
  memory:
    conversations:
      role:
        statements:
          - Effect: Allow
            Action: kms:Decrypt
            Resource: arn:aws:kms:us-east-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab
        tags:
          Team: ai

role takes the same forms as an agent's role: an object with name, statements, managedPolicies, permissionsBoundary and tags, or an ARN, a logical ID or a CloudFormation intrinsic to use a role you manage. See IAM role for an agent.

Memory configuration reference

These keys apply to entries in ai.memory and to inline memory objects on agents:

KeyTypeDefaultValue
expirationnumber30Days to keep events, 3 to 365
strategieslistNoneLong-term memory strategies
encryptionKeystringService-managed keyKMS key ARN
descriptionstringNone1 to 1,200 characters
rolestring or objectGenerated roleSee IAM role for memory
tagsmap of stringsNoneTags on the memory

For a memory named conversations, the stack contains ConversationsMemory (an AWS::BedrockAgentCore::Memory named <service>_conversations_<stage>, truncated to 48 characters) and ConversationsMemoryRole, and outputs ConversationsMemoryArn (exported as <service>-<stage>-conversations-MemoryArn), ConversationsMemoryId and ConversationsMemoryRoleArn.

Examples

  • LangGraph with memory (JavaScript) and (Python).
  • More in the Amazon Bedrock AgentCore examples.

Related pages

  • AgentCore Runtime agents: the agent settings, including memory.
  • AgentCore Gateway tools: give the agent tools.
  • Amazon Bedrock AgentCore Memory in the AgentCore developer guide.
Edit this page
Prev GatewayNextBrowser

Contents

  • AgentCore Memory for agents
  • Use memory in agent code
  • Share memory between agents
  • Extract long-term memory with strategies
  • Event expiration and encryption
  • IAM role for memory
  • Memory configuration reference
  • Examples
  • Related pages

Related

GuidesPluginsExamplesSlack CommunitySupport