Skip to content

Conversation

@dineshSajwan
Copy link
Contributor

This is a request for Amazon Bedrock AgentCore L2 construct that simplifies the deployment and management of AI agents at scale by wrapping the AgentCore L1 constructs. It provides a high-level, object-oriented approach to creating and managing Amazon Bedrock AgentCore resources. This enables developers to deploy highly effective agents securely using any framework and model. The package will provide constructs for the following primitives:

AgentCore Memory

See # #785 for
additional details.

APIs are signed off by @{BAR_RAISER}.


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache-2.0 license

dinsajwa and others added 30 commits January 27, 2025 11:11
@dineshSajwan dineshSajwan changed the title RFC 788: Bedrock AgentCore Runtime L2 construct RFC 788: Bedrock AgentCore Memory L2 construct Oct 14, 2025

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | `string` | No | The name of the memory |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is required on the Cloudformation Name property. If the name will be autogenerated on the L2, can you describe how the name will be generated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in 02ffb0d

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `name` | `string` | No | The name of the memory |
| `expirationDays` | `Duration` | No | Short-term memory expiration in days (between 7 and 365) |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a default for the expirationDays if not specified?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated in 02ffb0d

Comment on lines 132 to 283
## Memory with Built-in Strategies

The library provides three built-in LTM strategies:

1. **Summarization Strategy** (`MemoryStrategy.BUILT_IN_SUMMARIZATION`)
- Extracts concise summaries to preserve critical context and key insights
- Namespace: `/strategies/{memoryStrategyId}/actors/{actorId}/sessions/{sessionId}`

2. **Semantic Memory Strategy** (`MemoryStrategy.BUILT_IN_SEMANTIC`)
- Extracts general factual knowledge, concepts and meanings from raw conversations
- Namespace: `/strategies/{memoryStrategyId}/actors/{actorId}`

3. **User Preference Strategy** (`MemoryStrategy.BUILT_IN_USER_PREFERENCE`)
- Extracts user behavior patterns from raw conversations
- Namespace: `/strategies/{memoryStrategyId}/actors/{actorId}`

```typescript
import * as cdk from "aws-cdk-lib";
import {
Memory,
MemoryStrategy,
} from "aws-cdk/bedrock-agentcore-alpha/memory";

// Create memory with built-in strategies
const memory = new Memory(this, "MyMemory", {
name: "my_memory",
description: "Memory with built-in strategies",
expirationDays: cdk.Duration.days(90),
memoryStrategies: [
MemoryStrategy.BUILT_IN_SUMMARIZATION,
MemoryStrategy.BUILT_IN_SEMANTIC,
MemoryStrategy.BUILT_IN_USER_PREFERENCE,
],
});
```

## Memory with Built-in Strategies - Custom Namespace

You can customise the namespace, i.e. where the memories are stored by using the following methods:

1. **Summarization Strategy** (`MemoryStrategy.fromBuiltInSummarization(props)`)
2. **Semantic Memory Strategy** (`MemoryStrategy.fromBuiltInSemantic(props)`)
3. **User Preference Strategy** (`MemoryStrategy.fromBuiltInUserPreference(props)`)

```typescript
import * as cdk from "aws-cdk-lib";
import {
Memory,
MemoryStrategy,
} from "aws-cdk/bedrock-agentcore-alpha/memory";

// Create memory with built-in strategies using custom namespaces
const memory = new Memory(this, "MyMemory", {
name: "my_memory",
description: "Memory with built-in strategies",
expirationDays: cdk.Duration.days(90),
memoryStrategies: [
MemoryStrategy.fromBuiltInUserPreference({
name: "CustomerPreferences",
namespaces: ["support/customer/{actorId}/preferences"]
}),
MemoryStrategy.fromBuiltInSemantic({
name: "CustomerSupportSemantic",
namespaces: ["support/customer/{actorId}/semantic"]
}),
MemoryStrategy.fromBuiltInSummarization({
name: "SessionSummaries",
namespaces: ["support/sessions/{sessionId}/summary"]
}),
],
});
```

## Custom Strategies

You can also create custom memory strategies using your specified models and prompts.
According to the strategy that you will be customizing, you will have to specify extraction and/or consolidation FMs
and prompt templates to append to the system prompt of the memory strategy. You can do so by using:

1. **Summarization Strategy** (`MemoryStrategy.fromCustomSummaryOverride(props)`)
2. **Semantic Memory Strategy** (`MemoryStrategy.fromCustomSemanticOverride(props)`)
3. **User Preference Strategy** (`MemoryStrategy.fromCustomUserPreferenceOverride(props)`)

Since a custom strategy requires you to invoke certain FMs, you need a role with appropriate permissions. For that, you can:

- Let the L2 construct create a minimum permission role for you when use L2 Bedrock Foundation Models.
- Use a custom role with the overly permissive `AmazonBedrockAgentCoreMemoryBedrockModelInferenceExecutionRolePolicy` managed policy.
- Use a custom role with your own custom policies.

### Memory with Custom Execution Role

Keep in mind that memories that **do not** use custom strategies do not require a service role. So even if you provide it,
it will be ignored as it will never be used.

```typescript
import * as cdk from "aws-cdk-lib";
import * as iam from "aws-cdk-lib/aws-iam";
import { Memory } from "aws-cdk/bedrock-agentcore-alpha/memory";

// 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 Memory(this, "MyMemory", {
name: "my_memory",
description: "Memory with custom execution role",
expirationDays: cdk.Duration.days(90),
executionRole: executionRole,
});
```

### Custom Strategy Example

```typescript
import * as cdk from "aws-cdk-lib";
import * as bedrock from "@aws-cdk/aws-bedrock-alpha";
import {
Memory,
MemoryStrategy,
MemoryStrategyType,
} from "aws-cdk/bedrock-agentcore-alpha/memory";

// Create a custom semantic memory strategy
const customSemanticStrategy = MemoryStrategy.fromCustomSemanticOverride({
name: "custom-semantic-strategy",
description: "Custom semantic memory strategy",
namespaces: ["/custom/strategies/{memoryStrategyId}/actors/{actorId}"],
customConsolidation: {
model: "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0",
customPrompt: "Custom consolidation prompt for semantic memory",
},
customExtraction: {
model: "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0",
customPrompt: "Custom extraction prompt for semantic memory",
},
});

// Create memory with custom strategy
const memory = new Memory(this, "MyMemory", {
name: "my-custom-memory",
description: "Memory with custom strategy",
expirationDays: cdk.Duration.days(90),
memoryStrategies: [customSemanticStrategy],
});
```
Copy link
Member

@Abogical Abogical Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this interface could be simplified with one function with default props.

Without custom namespaces:

const memory = new Memory(this, "MyMemory", {
  name: "my_memory",
  description: "Memory with built-in strategies",
  expirationDays: cdk.Duration.days(90),
  memoryStrategies: [
    MemoryStrategy.userPreference(),
    MemoryStrategy.semantic(),
    MemoryStrategy.summarization(),
  ],
});

With custom strategies:

const memory = new Memory(this, "MyMemory", {
  name: "my_memory",
  description: "Memory with built-in strategies",
  expirationDays: cdk.Duration.days(90),
  memoryStrategies: [
    MemoryStrategy.userPreference({
      name: "CustomerPreferences",
      namespaces: ["support/customer/{actorId}/preferences"]
    }),
    MemoryStrategy.semantic({
      name: "CustomerSupportSemantic",
      namespaces: ["support/customer/{actorId}/semantic"]
    }),
    MemoryStrategy.summarization({
      name: "SessionSummaries",
      namespaces: ["support/sessions/{sessionId}/summary"]
    }),
  ],
});

Custom memory strategy:

const customSemanticStrategy = MemoryStrategy.semantic({
  name: "custom-semantic-strategy",
  description: "Custom semantic memory strategy",
  namespaces: ["/custom/strategies/{memoryStrategyId}/actors/{actorId}"],
  customConsolidation: {
    model: "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0",
    customPrompt: "Custom consolidation prompt for semantic memory",
  },
  customExtraction: {
    model: "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0",
    customPrompt: "Custom extraction prompt for semantic memory",
  },
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 02ffb0d
using a standardized naming

memoryName: "my_memory",
description: "Memory with custom execution role",
expirationDays: cdk.Duration.days(90),
// executionRole: executionRole,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line shouldn't be a comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1ce3d0c


### Are there any open issues that need to be addressed later?

Self managed strategy is not available yet, it will be added as a long term memory strategy.
Copy link
Member

@Abogical Abogical Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Self managed strategy is not available yet, it will be added as a long term memory strategy.
The [Self-managed memory strategy](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory-self-managed-strategies.html) does not have an exposed CloudFormation interface yet. It will be added later as a long term memory strategy once it is exposed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in
12000c5

- For Semantic:`semantic_builtin_<suffix>`
- For User Preferences: `preference_builtin_<suffix>`

Where the suffix is a 5 characters string ([a-z, A-Z, 0-9]).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suffix will be generated via the Names.uniqueId(scope) using the memory's scope as discussed in slack.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in
12000c5

@alvazjor alvazjor marked this pull request as ready for review October 21, 2025 13:54
@alvazjor alvazjor dismissed Abogical’s stale review October 21, 2025 13:57

Discussed and agreed on the proposal

@alvazjor alvazjor added pr/do-not-merge Let mergify know not to auto merge status/api-approved API Bar Raiser signed-off the API of this RFC labels Oct 21, 2025
@alvazjor
Copy link
Contributor

Signing off the RFC. Will keep it open for the final comments period. If no additional comments are added, this can be merged on October 28th

@alvazjor alvazjor self-assigned this Oct 21, 2025
@Abogical Abogical removed the pr/do-not-merge Let mergify know not to auto merge label Oct 28, 2025
@Abogical
Copy link
Member

No comments made. Merging.

@Abogical Abogical merged commit 5d7c11f into aws:main Oct 28, 2025
2 checks passed
mergify bot pushed a commit to aws/aws-cdk that referenced this pull request Oct 29, 2025
### Issue # (if applicable)

Related to aws/aws-cdk-rfcs#825

### Reason for this change

Adding a new alpha package for Amazon Bedrock AgentCore and add support for memory.

### Description of changes

- Create a new alpha package
- Add L2 constructs for memory
- Add documentation
- Add tests

### Describe any new or updated permissions being added

Using permissions for agent core defined in https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazonbedrockagentcore.html


### Description of how you validated changes

Unit tests, integration tests, manual tests

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status/api-approved API Bar Raiser signed-off the API of this RFC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants