> **Experimental**
>
> `@aws-cdk/aws-bedrock-agentcore-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# Memory

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.

Extends: Construct › Resource › MemoryBase › Memory
Implements: IMemory, IResource, IGrantable, IEnvironmentAware, IMemoryRef, IConstruct, IDependable

- Stability: [Experimental](/cdk/api/stability.html)
- CloudFormation: [`AWS::BedrockAgentCore::Memory`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-bedrockagentcore-memory.html)
- L1 type: [`CfnMemory`](/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.CfnMemory.html)
- Source: [`lib/memory/memory.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0-alpha.0/packages/@aws-cdk/aws-bedrock-agentcore-alpha/lib/memory/memory.ts#L578)

## Example

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as bedrock_agentcore_alpha from '@aws-cdk/aws-bedrock-agentcore-alpha';
import * as cdk from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';
import { aws_kms as kms } from 'aws-cdk-lib';

declare const key: kms.Key;
declare const memoryStrategy: bedrock_agentcore_alpha.IMemoryStrategy;
declare const role: iam.Role;
const memory = new bedrock_agentcore_alpha.Memory(this, 'MyMemory', /* all optional props */ {
  description: 'description',
  executionRole: role,
  expirationDuration: cdk.Duration.minutes(30),
  kmsKey: key,
  memoryName: 'memoryName',
  memoryStrategies: [memoryStrategy],
  tags: {
    tagsKey: 'tags',
  },
});
```

## Initializer

```ts
new Memory(scope: Construct, id: string, props?: MemoryProps)
```

## Construct Props

- `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.

  **Default:** No description

- `executionRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role that provides permissions for the memory to access AWS services when using custom strategies.

  **Default:** A new role will be created.

- `expirationDuration`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — Short-term memory expiration in days (between 7 and 365).

  **Default:** 90 days

  Sets the short-term (raw event) memory retention.
  Events older than the specified duration will expire and no longer be stored.

- `kmsKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) — Custom KMS key to use for encryption.

  **Default:** Your data is encrypted with a key that AWS owns and manages for you

- `memoryName`: 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}.

  **Default:** auto generate

- `memoryStrategies`: [IMemoryStrategy](/cdk/api/v2/docs/@aws-cdk_aws-bedrock-agentcore-alpha.IMemoryStrategy.html)[] — 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.

  **Default:** No extraction strategies (short term memory only)

- `tags`: { [key: string]: string } — Tags (optional) A list of key:value pairs of tags to apply to this memory resource.

  **Default:** no tags

## Properties

- `createdAt`: string — The created timestamp of the memory.

- `description`: string — The description of the memory.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — 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.

- `executionRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The execution role of the memory.

- `expirationDuration`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — The expiration days of the memory.

- `failureReason`: string — The failure reason of the browser.

- `grantPrincipal`: [IPrincipal](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IPrincipal.html) — The principal to grant permissions to.

- `kmsKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) — The KMS key used to encrypt the memory.

- `memoryArn`: string — The ARN of the memory resource.

- `memoryId`: string — The id of the memory.

- `memoryName`: string — The name of the memory.

- `memoryRef`: [MemoryReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_bedrockagentcore.MemoryReference.html) — A reference to a Memory resource.

- `memoryStrategies`: [IMemoryStrategy](/cdk/api/v2/docs/@aws-cdk_aws-bedrock-agentcore-alpha.IMemoryStrategy.html)[] — The memory strategies used by the memory.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

- `status`: string — The status of the memory.

- `tags`: { [key: string]: string } — Tags applied to this browser resource A map of key-value pairs for resource tagging.

  **Default:** No tags applied

- `updatedAt`: string — The updated at timestamp of the memory.

## Methods

- `addMemoryStrategy(memoryStrategy: IMemoryStrategy): void` — Add memory strategy to the memory.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — 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`).

- `fromMemoryAttributes(scope: Construct, id: string, attrs: MemoryAttributes): IMemory` (static) — Creates an Memory reference from an existing memory's attributes.

  **Parameters**

  - `scope` — - The construct scope.
  - `id` — - Identifier of the construct.
  - `attrs` — - Attributes of the existing browser custom.

  **Returns:** An IBrowserCustom reference to the existing browser

- `grant(grantee: IGrantable, ...actions: string[]): Grant` — Grants IAM actions to the IAM Principal.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant permissions to.
  - `actions` — - The actions to grant.

  **Returns:** An IAM Grant object representing the granted permissions

- `grantAdmin(grantee: IGrantable): Grant` — Grant the given principal identity permissions to manage the control plane of this memory.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant admin permissions to.

  **Returns:** An IAM Grant object representing the granted permissions

- `grantDelete(grantee: IGrantable): Grant` — Grant the given principal identity permissions to delete content on this memory.

  Both Short-Term Memory (STM) and Long-Term Memory (LTM).

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant delete permissions to.

  **Returns:** An IAM Grant object representing the granted permissions

- `grantDeleteLongTermMemory(grantee: IGrantable): Grant` — Grant the given principal identity permissions to delete Long-Term Memory (LTM) content on this memory.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant delete permissions to.

  **Returns:** An IAM Grant object representing the granted permissions

- `grantDeleteShortTermMemory(grantee: IGrantable): Grant` — Grant the given principal identity permissions to delete Short-Term Memory (STM) content on this memory.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant delete permissions to.

  **Returns:** An IAM Grant object representing the granted permissions

- `grantFullAccess(grantee: IGrantable): Grant` — Grant the given principal identity permissions to do every action on this memory.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant full access permissions to.

  **Returns:** An IAM Grant object representing the granted permissions

- `grantRead(grantee: IGrantable): Grant` — Grant the given principal identity permissions to read the contents of this memory.

  Both Short-Term Memory (STM) and Long-Term Memory (LTM).

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant read permissions to.

  **Returns:** An IAM Grant object representing the granted permissions

- `grantReadLongTermMemory(grantee: IGrantable): Grant` — Grant the given principal identity permissions to read the Long-Term Memory (LTM) contents of this memory.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant read permissions to.

  **Returns:** An IAM Grant object representing the granted permissions

- `grantReadShortTermMemory(grantee: IGrantable): Grant` — Grant the given principal identity permissions to read the Short-Term Memory (STM) contents of this memory.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant read permissions to.

  **Returns:** An IAM Grant object representing the granted permissions

- `grantWrite(grantee: IGrantable): Grant` — Grant the given principal identity permissions to write content to short-term memory.

  [disable-awslint:no-grants]

  **Parameters**

  - `grantee` — - The IAM principal to grant read permissions to.

  **Returns:** An IAM Grant object representing the granted permissions

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `metric(metricName: string, dimensions: { [key: string]: string }, props?: MetricOptions): Metric` — 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: string, props?: MetricOptions): Metric` — Return a metric containing the number of errors for a specific API operation performed on this memory.

- `metricEventCreationCount(props?: MetricOptions): Metric` — Returns the metric containing the number of short-term memory events.

- `metricForApiOperation(metricName: string, operation: string, props?: MetricOptions): Metric` — Return the given named metric related to the API operation performed on this memory.

- `metricInvocationsForApiOperation(operation: string, props?: MetricOptions): Metric` — Return a metric containing the total number of API requests made for a specific memory operation like `CreateEvent`, `ListEvents`, `RetrieveMemoryRecords` ...

- `metricLatencyForApiOperation(operation: string, props?: MetricOptions): Metric` — 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?: MetricOptions): Metric` — Returns the metric containing the number of long-term memory records created by the long-term extraction strategies.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
