class Memory (construct)
| Language | Type name |
|---|---|
.NET | Amazon.CDK.AWS.Bedrock.Agentcore.Alpha.Memory |
Go | github.com/aws/aws-cdk-go/awsbedrockagentcorealpha/v2#Memory |
Java | software.amazon.awscdk.services.bedrock.agentcore.alpha.Memory |
Python | aws_cdk.aws_bedrock_agentcore_alpha.Memory |
TypeScript (source) | @aws-cdk/aws-bedrock-agentcore-alpha ยป Memory |
Implements
IConstruct, IDependable, IResource, IEnvironment, IMemory, IGrantable
Long-term memory store for extracted insights like user preferences, semantic facts and summaries.
Enables knowledge retention across sessions by storing user preferences (e.g. coding style), semantic facts (e.g. learned info) and interaction summaries for context optimization.
See also: https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory.html
Example
// Create a custom execution role
const executionRole = new iam.Role(this, "MemoryExecutionRole", {
assumedBy: new iam.ServicePrincipal("bedrock-agentcore.amazonaws.com"),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName(
"AmazonBedrockAgentCoreMemoryBedrockModelInferenceExecutionRolePolicy"
),
],
});
// Create memory with custom execution role
const memory = new agentcore.Memory(this, "MyMemory", {
memoryName: "my_memory",
description: "Memory with custom execution role",
expirationDuration: cdk.Duration.days(90),
executionRole: executionRole,
});
Initializer
new Memory(scope: Construct, id: string, props: MemoryProps)
Parameters
- scope
Construct - id
string - props
MemoryProps
Construct Props
| Name | Type | Description |
|---|---|---|
| memory | string | The name of the memory Valid characters are a-z, A-Z, 0-9, _ (underscore) The name must start with a letter and can be up to 48 characters long Pattern: [a-zA-Z][a-zA-Z0-9_]{0,47}. |
| description? | string | Optional description for the memory Valid characters are a-z, A-Z, 0-9, _ (underscore), - (hyphen) and spaces The description can have up to 200 characters. |
| execution | IRole | The IAM role that provides permissions for the memory to access AWS services when using custom strategies. |
| expiration | Duration | Short-term memory expiration in days (between 7 and 365). |
| kms | IKey | Custom KMS key to use for encryption. |
| memory | IMemory[] | If you need long-term memory for context recall across sessions, you can setup memory extraction strategies to extract the relevant memory from the raw events. |
| tags? | { [string]: string } | Tags (optional) A list of key:value pairs of tags to apply to this memory resource. |
memoryName
Type:
string
The name of the memory Valid characters are a-z, A-Z, 0-9, _ (underscore) The name must start with a letter and can be up to 48 characters long Pattern: [a-zA-Z][a-zA-Z0-9_]{0,47}.
description?
Type:
string
(optional, default: No description)
Optional description for the memory Valid characters are a-z, A-Z, 0-9, _ (underscore), - (hyphen) and spaces The description can have up to 200 characters.
executionRole?
Type:
IRole
(optional, default: A new role will be created.)
The IAM role that provides permissions for the memory to access AWS services when using custom strategies.
expirationDuration?
Type:
Duration
(optional, default: 90)
Short-term memory expiration in days (between 7 and 365).
Sets the short-term (raw event) memory retention. Events older than the specified duration will expire and no longer be stored.
kmsKey?
Type:
IKey
(optional, default: Your data is encrypted with a key that AWS owns and manages for you)
Custom KMS key to use for encryption.
memoryStrategies?
Type:
IMemory[]
(optional, default: No extraction strategies (short term memory only))
If you need long-term memory for context recall across sessions, you can setup memory extraction strategies to extract the relevant memory from the raw events.
tags?
Type:
{ [string]: string }
(optional, default: {} no tags)
Tags (optional) A list of key:value pairs of tags to apply to this memory resource.
Properties
| Name | Type | Description |
|---|---|---|
| env | Resource | The environment this resource belongs to. |
| grant | IPrincipal | The principal to grant permissions to. |
| memory | string | The ARN of the memory resource. |
| memory | string | The id of the memory. |
| memory | string | The name of the memory. |
| memory | IMemory[] | The memory strategies used by the memory. |
| node | Node | The tree node. |
| stack | Stack | The stack in which this resource is defined. |
| created | string | The created timestamp of the memory. |
| description? | string | The description of the memory. |
| execution | IRole | The execution role of the memory. |
| expiration | Duration | The expiration days of the memory. |
| failure | string | The failure reason of the browser. |
| kms | IKey | The KMS key used to encrypt the memory. |
| status? | string | The status of the memory. |
| tags? | { [string]: string } | Tags applied to this browser resource A map of key-value pairs for resource tagging. |
| updated | string | The updated at timestamp of the memory. |
| static PROPERTY_INJECTION_ID | string | Uniquely identifies this class. |
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed in a Stack (those created by
creating new class instances like new Role(), new Bucket(), etc.), this
is always the same as the environment of the stack they belong to.
For referenced resources (those obtained from referencing methods like
Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be
different than the stack they were imported into.
grantPrincipal
Type:
IPrincipal
The principal to grant permissions to.
memoryArn
Type:
string
The ARN of the memory resource.
memoryId
Type:
string
The id of the memory.
memoryName
Type:
string
The name of the memory.
memoryStrategies
Type:
IMemory[]
The memory strategies used by the memory.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
createdAt?
Type:
string
(optional)
The created timestamp of the memory.
description?
Type:
string
(optional)
The description of the memory.
executionRole?
Type:
IRole
(optional)
The execution role of the memory.
expirationDuration?
Type:
Duration
(optional)
The expiration days of the memory.
failureReason?
Type:
string
(optional)
The failure reason of the browser.
kmsKey?
Type:
IKey
(optional)
The KMS key used to encrypt the memory.
status?
Type:
string
(optional)
The status of the memory.
tags?
Type:
{ [string]: string }
(optional, default: No tags applied)
Tags applied to this browser resource A map of key-value pairs for resource tagging.
updatedAt?
Type:
string
(optional)
The updated at timestamp of the memory.
static PROPERTY_INJECTION_ID
Type:
string
Uniquely identifies this class.
Methods
| Name | Description |
|---|---|
| add | Add memory strategy to the memory. |
| apply | Apply the given removal policy to this resource. |
| grant(grantee, ...actions) | Grants IAM actions to the IAM Principal. |
| grant | Grant the given principal identity permissions to manage the control plane of this memory. |
| grant | Grant the given principal identity permissions to delete content on this memory. |
| grant | Grant the given principal identity permissions to delete Long-Term Memory (LTM) content on this memory. |
| grant | Grant the given principal identity permissions to delete Short-Term Memory (STM) content on this memory. |
| grant | Grant the given principal identity permissions to do every action on this memory. |
| grant | Grant the given principal identity permissions to read the contents of this memory. |
| grant | Grant the given principal identity permissions to read the Long-Term Memory (LTM) contents of this memory. |
| grant | Grant the given principal identity permissions to read the Short-Term Memory (STM) contents of this memory. |
| grant | Grant the given principal identity permissions to write content to short-term memory. |
| metric(metricName, dimensions, props?) | Return the given named metric for this memory. |
| metric | Return a metric containing the number of errors for a specific API operation performed on this memory. |
| metric | Returns the metric containing the number of short-term memory events. |
| metric | Return the given named metric related to the API operation performed on this memory. |
| metric | Return a metric containing the total number of API requests made for a specific memory operation like CreateEvent, ListEvents, RetrieveMemoryRecords ... |
| metric | Return a metric measuring the latency of a specific API operation performed on this memory. |
| metric | Returns the metric containing the number of long-term memory records created by the long-term extraction strategies. |
| to | Returns a string representation of this construct. |
| static from | Creates an Memory reference from an existing memory's attributes. |
addMemoryStrategy(memoryStrategy)
public addMemoryStrategy(memoryStrategy: IMemoryStrategy): void
Parameters
- memoryStrategy
IMemoryStrategy
Add memory strategy to the memory.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
RemovalPolicy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN).
grant(grantee, ...actions)
public grant(grantee: IGrantable, ...actions: string[]): Grant
Parameters
- grantee
IGrantableโ - The IAM principal to grant permissions to. - actions
stringโ - The actions to grant.
Returns
Grants IAM actions to the IAM Principal.
grantAdmin(grantee)
public grantAdmin(grantee: IGrantable): Grant
Parameters
- grantee
IGrantableโ - The IAM principal to grant admin permissions to.
Returns
Grant the given principal identity permissions to manage the control plane of this memory.
grantDelete(grantee)
public grantDelete(grantee: IGrantable): Grant
Parameters
- grantee
IGrantableโ - The IAM principal to grant delete permissions to.
Returns
Grant the given principal identity permissions to delete content on this memory.
Both Short-Term Memory (STM) and Long-Term Memory (LTM).
grantDeleteLongTermMemory(grantee)
public grantDeleteLongTermMemory(grantee: IGrantable): Grant
Parameters
- grantee
IGrantableโ - The IAM principal to grant delete permissions to.
Returns
Grant the given principal identity permissions to delete Long-Term Memory (LTM) content on this memory.
grantDeleteShortTermMemory(grantee)
public grantDeleteShortTermMemory(grantee: IGrantable): Grant
Parameters
- grantee
IGrantableโ - The IAM principal to grant delete permissions to.
Returns
Grant the given principal identity permissions to delete Short-Term Memory (STM) content on this memory.
grantFullAccess(grantee)
public grantFullAccess(grantee: IGrantable): Grant
Parameters
- grantee
IGrantableโ - The IAM principal to grant full access permissions to.
Returns
Grant the given principal identity permissions to do every action on this memory.
grantRead(grantee)
public grantRead(grantee: IGrantable): Grant
Parameters
- grantee
IGrantableโ - The IAM principal to grant read permissions to.
Returns
Grant the given principal identity permissions to read the contents of this memory.
Both Short-Term Memory (STM) and Long-Term Memory (LTM).
grantReadLongTermMemory(grantee)
public grantReadLongTermMemory(grantee: IGrantable): Grant
Parameters
- grantee
IGrantableโ - The IAM principal to grant read permissions to.
Returns
Grant the given principal identity permissions to read the Long-Term Memory (LTM) contents of this memory.
grantReadShortTermMemory(grantee)
public grantReadShortTermMemory(grantee: IGrantable): Grant
Parameters
- grantee
IGrantableโ - The IAM principal to grant read permissions to.
Returns
Grant the given principal identity permissions to read the Short-Term Memory (STM) contents of this memory.
grantWrite(grantee)
public grantWrite(grantee: IGrantable): Grant
Parameters
- grantee
IGrantableโ - The IAM principal to grant read permissions to.
Returns
Grant the given principal identity permissions to write content to short-term memory.
metric(metricName, dimensions, props?)
public metric(metricName: string, dimensions: { [string]: string }, props?: MetricOptions): Metric
Parameters
- metricName
string - dimensions
{ [string]: string } - props
MetricOptions
Returns
Return the given named metric for this memory.
By default, the metric will be calculated as a sum over a period of 5 minutes.
You can customize this by using the statistic and period properties.
metricErrorsForApiOperation(operation, props?)
public metricErrorsForApiOperation(operation: string, props?: MetricOptions): Metric
Parameters
- operation
string - props
MetricOptions
Returns
Return a metric containing the number of errors for a specific API operation performed on this memory.
metricEventCreationCount(props?)
public metricEventCreationCount(props?: MetricOptions): Metric
Parameters
- props
MetricOptions
Returns
Returns the metric containing the number of short-term memory events.
metricForApiOperation(metricName, operation, props?)
public metricForApiOperation(metricName: string, operation: string, props?: MetricOptions): Metric
Parameters
- metricName
string - operation
string - props
MetricOptions
Returns
Return the given named metric related to the API operation performed on this memory.
metricInvocationsForApiOperation(operation, props?)
public metricInvocationsForApiOperation(operation: string, props?: MetricOptions): Metric
Parameters
- operation
string - props
MetricOptions
Returns
Return a metric containing the total number of API requests made for a specific memory operation like CreateEvent, ListEvents, RetrieveMemoryRecords ...
metricLatencyForApiOperation(operation, props?)
public metricLatencyForApiOperation(operation: string, props?: MetricOptions): Metric
Parameters
- operation
string - props
MetricOptions
Returns
Return a metric measuring the latency of a specific API operation performed on this memory.
The latency metric represents the total time elapsed between receiving the request and sending the final response token, measuring complete end-to-end processing time.
For memory creation events specifically, this measures the time from the last CreateEvent that met strategy criteria until memory storage is completed.
metricMemoryRecordCreationCount(props?)
public metricMemoryRecordCreationCount(props?: MetricOptions): Metric
Parameters
- props
MetricOptions
Returns
Returns the metric containing the number of long-term memory records created by the long-term extraction strategies.
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromMemoryAttributes(scope, id, attrs)
public static fromMemoryAttributes(scope: Construct, id: string, attrs: MemoryAttributes): IMemory
Parameters
- scope
Constructโ - The construct scope. - id
stringโ - Identifier of the construct. - attrs
Memoryโ - Attributes of the existing browser custom.Attributes
Returns
Creates an Memory reference from an existing memory's attributes.

.NET
Go
Java
Python
TypeScript (