-
Notifications
You must be signed in to change notification settings - Fork 103
RFC 788: Bedrock AgentCore Memory L2 construct #825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
||
| | Name | Type | Required | Description | | ||
| |------|------|----------|-------------| | ||
| | `name` | `string` | No | The name of the memory | |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) | |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in 02ffb0d
| ## 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], | ||
| }); | ||
| ``` |
There was a problem hiding this comment.
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",
},
});
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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. |
There was a problem hiding this comment.
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]). |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in
12000c5
Discussed and agreed on the proposal
|
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 |
|
No comments made. Merging. |
### 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*
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