Skip to content

Commit 6a2e17e

Browse files
authored
feat(memory): add agentcore memory l2 construct (#35757)
### 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*
1 parent 9bec236 commit 6a2e17e

File tree

22 files changed

+6134
-2
lines changed

22 files changed

+6134
-2
lines changed

packages/@aws-cdk/aws-bedrock-agentcore-alpha/README.md

Lines changed: 319 additions & 0 deletions
Large diffs are not rendered by default.

packages/@aws-cdk/aws-bedrock-agentcore-alpha/agentcore/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
export * from './memory/memory';
2+
export * from './memory/strategies/managed-strategy';
3+
export * from './memory/strategies/self-managed-strategy';
4+
export * from './memory/memory-strategy';
15
// ===================================
26
// Network Configuration
37
// ===================================
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance
5+
* with the License. A copy of the License is located at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
10+
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*/
13+
14+
import * as bedrockagentcore from 'aws-cdk-lib/aws-bedrockagentcore';
15+
import * as iam from 'aws-cdk-lib/aws-iam';
16+
// Internal libs
17+
import { ManagedMemoryStrategy, ManagedStrategyProps } from './strategies/managed-strategy';
18+
import { SelfManagedMemoryStrategy, SelfManagedStrategyProps } from './strategies/self-managed-strategy';
19+
20+
/******************************************************************************
21+
* CONSTANTS
22+
*****************************************************************************/
23+
/**
24+
* Minimum length for memory strategy name
25+
* @internal
26+
*/
27+
export const MEMORY_NAME_MIN_LENGTH = 1;
28+
/**
29+
* Maximum length for memory strategy name
30+
* @internal
31+
*/
32+
export const MEMORY_NAME_MAX_LENGTH = 48;
33+
34+
/**
35+
* Long-term memory extraction strategy types.
36+
*/
37+
export enum MemoryStrategyType {
38+
/**
39+
* Summarization strategy - extracts concise summaries to preserve critical context and key insights
40+
*/
41+
SUMMARIZATION = 'SUMMARIZATION',
42+
/**
43+
* Semantic memory strategy - extracts general factual knowledge, concepts and meanings from raw conversations
44+
* using vector embeddings for similarity search.
45+
*/
46+
SEMANTIC = 'SEMANTIC',
47+
/**
48+
* User preferences strategy - extracts user behavior patterns from raw conversations.
49+
*/
50+
USER_PREFERENCE = 'USER_PREFERENCE',
51+
/**
52+
* Customize memory processing through custom foundation model and prompt templates.
53+
*/
54+
CUSTOM = 'CUSTOM',
55+
}
56+
57+
/******************************************************************************
58+
* Common
59+
*****************************************************************************/
60+
/**
61+
* Configuration parameters common for any memory strategy
62+
*/
63+
export interface MemoryStrategyCommonProps {
64+
/**
65+
* The name for the strategy
66+
* @required - Yes
67+
*/
68+
readonly name: string;
69+
/**
70+
* The description of the strategy
71+
* @default No description
72+
* @required - No
73+
*/
74+
readonly description?: string;
75+
}
76+
77+
/******************************************************************************
78+
* Interface
79+
*****************************************************************************/
80+
/**
81+
* Interface for Memory strategies
82+
*/
83+
export interface IMemoryStrategy {
84+
/**
85+
* The name of the memory strategy
86+
*/
87+
readonly name: string;
88+
/**
89+
* The description of the memory strategy
90+
*/
91+
readonly description?: string;
92+
/**
93+
* The type of memory strategy
94+
*/
95+
readonly strategyType: MemoryStrategyType;
96+
/**
97+
* Renders internal attributes to CloudFormation
98+
*/
99+
render(): bedrockagentcore.CfnMemory.MemoryStrategyProperty;
100+
/**
101+
* Grants the necessary permissions to the role
102+
* @param grantee - The grantee to grant permissions to
103+
* @returns The Grant object for chaining
104+
*/
105+
grant(grantee: iam.IGrantable): iam.Grant | undefined;
106+
}
107+
108+
/******************************************************************************
109+
* Factory
110+
*****************************************************************************/
111+
/**
112+
* Factory class for creating memory strategies
113+
* 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.
114+
* Use built-in strategies for quick setup, use built-in strategies with override to specify models and prompt templates.
115+
*
116+
* @see https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory-strategies.html
117+
*/
118+
export class MemoryStrategy {
119+
/**
120+
* Default strategies for organizing and extracting memory data, each optimized for specific use cases.
121+
* This strategy compresses conversations into concise overviews, preserving essential context and key insights for quick recall.
122+
* Extracted memory example: Users confused by cloud setup during onboarding.
123+
* @returns A ManagedMemoryStrategy.
124+
*/
125+
public static usingBuiltInSummarization(): ManagedMemoryStrategy {
126+
return new ManagedMemoryStrategy(MemoryStrategyType.SUMMARIZATION, {
127+
name: 'summary_builtin_cdkGen0001',
128+
description: 'Summarize interactions to preserve critical context and key insights',
129+
namespaces: ['/strategies/{memoryStrategyId}/actors/{actorId}/sessions/{sessionId}'],
130+
});
131+
}
132+
/**
133+
* Default strategies for organizing and extracting memory data, each optimized for specific use cases.
134+
* Distills general facts, concepts, and underlying meanings from raw conversational data, presenting the information in a context-independent format.
135+
* Extracted memory example: In-context learning = task-solving via examples, no training needed.
136+
* @returns A ManagedMemoryStrategy.
137+
*/
138+
public static usingBuiltInSemantic(): ManagedMemoryStrategy {
139+
return new ManagedMemoryStrategy(MemoryStrategyType.SEMANTIC, {
140+
name: 'semantic_builtin_cdkGen0001',
141+
description:
142+
'Extract general factual knowledge, concepts and meanings from raw conversations in a context-independent format.',
143+
namespaces: ['/strategies/{memoryStrategyId}/actors/{actorId}'],
144+
});
145+
}
146+
/**
147+
* Default strategies for organizing and extracting memory data, each optimized for specific use cases.
148+
* Captures individual preferences, interaction patterns, and personalized settings to enhance future experiences.
149+
* Extracted memory example: User needs clear guidance on cloud storage account connection during onboarding.
150+
* @returns A ManagedMemoryStrategy.
151+
*/
152+
public static usingBuiltInUserPreference(): ManagedMemoryStrategy {
153+
return new ManagedMemoryStrategy(MemoryStrategyType.USER_PREFERENCE, {
154+
name: 'preference_builtin_cdkGen0001',
155+
description: 'Capture individual preferences, interaction patterns, and personalized settings to enhance future experiences.',
156+
namespaces: ['/strategies/{memoryStrategyId}/actors/{actorId}'],
157+
});
158+
}
159+
/**
160+
* Creates a semantic memory strategy with custom configuration.
161+
* Distills general facts, concepts, and underlying meanings from raw conversational data, presenting the information in a context-independent format.
162+
* Extracted memory example: In-context learning = task-solving via examples, no training needed.
163+
* @param config - The configuration for the semantic memory strategy.
164+
* @returns A ManagedMemoryStrategy.
165+
*/
166+
public static usingSemantic(config: ManagedStrategyProps): ManagedMemoryStrategy {
167+
return new ManagedMemoryStrategy(MemoryStrategyType.SEMANTIC, config);
168+
}
169+
/**
170+
* Creates a user preference memory strategy with custom configuration.
171+
* Captures individual preferences, interaction patterns, and personalized settings to enhance future experiences.
172+
* Extracted memory example: User needs clear guidance on cloud storage account connection during onboarding.
173+
* @param config - The configuration for the user preference memory strategy.
174+
* @returns A ManagedMemoryStrategy.
175+
*/
176+
public static usingUserPreference(config: ManagedStrategyProps): ManagedMemoryStrategy {
177+
return new ManagedMemoryStrategy(MemoryStrategyType.USER_PREFERENCE, config);
178+
}
179+
/**
180+
* Creates a summarization memory strategy with custom configuration.
181+
* This strategy compresses conversations into concise overviews, preserving essential context and key insights for quick recall.
182+
* Extracted memory example: Users confused by cloud setup during onboarding.
183+
* @param config - The configuration for the summarization memory strategy.
184+
* @returns A ManagedMemoryStrategy.
185+
*/
186+
public static usingSummarization(config: ManagedStrategyProps): ManagedMemoryStrategy {
187+
return new ManagedMemoryStrategy(MemoryStrategyType.SUMMARIZATION, config);
188+
}
189+
/**
190+
* Creates a self-managed memory strategy.
191+
* A self-managed strategy gives you complete control over your memory extraction and consolidation pipelines.
192+
* @param config - The configuration for the self-managed memory strategy.
193+
* @returns A SelfManagedMemoryStrategy.
194+
*/
195+
public static usingSelfManaged(config: SelfManagedStrategyProps): SelfManagedMemoryStrategy {
196+
// Scope is passed for future use in permission granting
197+
return new SelfManagedMemoryStrategy(MemoryStrategyType.CUSTOM, config);
198+
}
199+
}

0 commit comments

Comments
 (0)