@aws-cdk/aws-bedrock-agentcore-alpha 2.221.0-alpha.0 → 2.222.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/.jsii +3794 -502
  2. package/.jsii.tabl.json.gz +0 -0
  3. package/.warnings.jsii.js +69 -1
  4. package/README.md +327 -5
  5. package/agentcore/index.d.ts +4 -0
  6. package/agentcore/index.js +5 -1
  7. package/agentcore/memory/memory-strategy.d.ts +164 -0
  8. package/agentcore/memory/memory-strategy.js +174 -0
  9. package/agentcore/memory/memory.d.ts +538 -0
  10. package/agentcore/memory/memory.js +661 -0
  11. package/agentcore/memory/perms.d.ts +63 -0
  12. package/agentcore/memory/perms.js +90 -0
  13. package/agentcore/memory/strategies/managed-strategy.d.ts +133 -0
  14. package/agentcore/memory/strategies/managed-strategy.js +209 -0
  15. package/agentcore/memory/strategies/self-managed-strategy.d.ts +127 -0
  16. package/agentcore/memory/strategies/self-managed-strategy.js +254 -0
  17. package/agentcore/memory/validation-helpers.d.ts +41 -0
  18. package/agentcore/memory/validation-helpers.js +89 -0
  19. package/agentcore/network/network-configuration.js +4 -4
  20. package/agentcore/runtime/runtime-artifact.js +1 -1
  21. package/agentcore/runtime/runtime-authorizer-configuration.d.ts +4 -4
  22. package/agentcore/runtime/runtime-authorizer-configuration.js +13 -32
  23. package/agentcore/runtime/runtime-base.js +3 -13
  24. package/agentcore/runtime/runtime-endpoint-base.js +1 -1
  25. package/agentcore/runtime/runtime-endpoint.js +1 -1
  26. package/agentcore/runtime/runtime.d.ts +2 -2
  27. package/agentcore/runtime/runtime.js +16 -17
  28. package/agentcore/runtime/types.d.ts +5 -1
  29. package/agentcore/runtime/types.js +5 -1
  30. package/agentcore/tools/browser.js +2 -2
  31. package/agentcore/tools/code-interpreter.js +2 -2
  32. package/package.json +14 -7
  33. package/rosetta/default.ts-fixture +4 -0
Binary file
package/.warnings.jsii.js CHANGED
@@ -1,3 +1,71 @@
1
+ function _aws_cdk_aws_bedrock_agentcore_alpha_IMemory(p) {
2
+ }
3
+ function _aws_cdk_aws_bedrock_agentcore_alpha_MemoryBase(p) {
4
+ }
5
+ function _aws_cdk_aws_bedrock_agentcore_alpha_MemoryProps(p) {
6
+ if (p == null)
7
+ return;
8
+ visitedObjects.add(p);
9
+ try {
10
+ if (p.memoryStrategies != null)
11
+ for (const o of p.memoryStrategies)
12
+ if (!visitedObjects.has(o))
13
+ _aws_cdk_aws_bedrock_agentcore_alpha_IMemoryStrategy(o);
14
+ }
15
+ finally {
16
+ visitedObjects.delete(p);
17
+ }
18
+ }
19
+ function _aws_cdk_aws_bedrock_agentcore_alpha_MemoryAttributes(p) {
20
+ }
21
+ function _aws_cdk_aws_bedrock_agentcore_alpha_Memory(p) {
22
+ }
23
+ function _aws_cdk_aws_bedrock_agentcore_alpha_OverrideConfig(p) {
24
+ }
25
+ function _aws_cdk_aws_bedrock_agentcore_alpha_ManagedStrategyProps(p) {
26
+ if (p == null)
27
+ return;
28
+ visitedObjects.add(p);
29
+ try {
30
+ if (!visitedObjects.has(p.customConsolidation))
31
+ _aws_cdk_aws_bedrock_agentcore_alpha_OverrideConfig(p.customConsolidation);
32
+ if (!visitedObjects.has(p.customExtraction))
33
+ _aws_cdk_aws_bedrock_agentcore_alpha_OverrideConfig(p.customExtraction);
34
+ }
35
+ finally {
36
+ visitedObjects.delete(p);
37
+ }
38
+ }
39
+ function _aws_cdk_aws_bedrock_agentcore_alpha_ManagedMemoryStrategy(p) {
40
+ }
41
+ function _aws_cdk_aws_bedrock_agentcore_alpha_TriggerConditions(p) {
42
+ }
43
+ function _aws_cdk_aws_bedrock_agentcore_alpha_InvocationConfiguration(p) {
44
+ }
45
+ function _aws_cdk_aws_bedrock_agentcore_alpha_SelfManagedStrategyProps(p) {
46
+ if (p == null)
47
+ return;
48
+ visitedObjects.add(p);
49
+ try {
50
+ if (!visitedObjects.has(p.invocationConfiguration))
51
+ _aws_cdk_aws_bedrock_agentcore_alpha_InvocationConfiguration(p.invocationConfiguration);
52
+ if (!visitedObjects.has(p.triggerConditions))
53
+ _aws_cdk_aws_bedrock_agentcore_alpha_TriggerConditions(p.triggerConditions);
54
+ }
55
+ finally {
56
+ visitedObjects.delete(p);
57
+ }
58
+ }
59
+ function _aws_cdk_aws_bedrock_agentcore_alpha_SelfManagedMemoryStrategy(p) {
60
+ }
61
+ function _aws_cdk_aws_bedrock_agentcore_alpha_MemoryStrategyType(p) {
62
+ }
63
+ function _aws_cdk_aws_bedrock_agentcore_alpha_MemoryStrategyCommonProps(p) {
64
+ }
65
+ function _aws_cdk_aws_bedrock_agentcore_alpha_IMemoryStrategy(p) {
66
+ }
67
+ function _aws_cdk_aws_bedrock_agentcore_alpha_MemoryStrategy(p) {
68
+ }
1
69
  function _aws_cdk_aws_bedrock_agentcore_alpha_VpcConfigProps(p) {
2
70
  if (p == null)
3
71
  return;
@@ -180,4 +248,4 @@ class DeprecationError extends Error {
180
248
  });
181
249
  }
182
250
  }
183
- module.exports = { print, getPropertyDescriptor, DeprecationError, _aws_cdk_aws_bedrock_agentcore_alpha_VpcConfigProps, _aws_cdk_aws_bedrock_agentcore_alpha_NetworkConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_BrowserNetworkConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_CodeInterpreterNetworkConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeNetworkConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_ProtocolType, _aws_cdk_aws_bedrock_agentcore_alpha_IBedrockAgentRuntime, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeBase, _aws_cdk_aws_bedrock_agentcore_alpha_AgentRuntimeAttributes, _aws_cdk_aws_bedrock_agentcore_alpha_AgentRuntimeArtifact, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeAuthorizerConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_IRuntimeEndpoint, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeEndpointBase, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeEndpointAttributes, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeEndpointProps, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeEndpoint, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeProps, _aws_cdk_aws_bedrock_agentcore_alpha_AddEndpointOptions, _aws_cdk_aws_bedrock_agentcore_alpha_Runtime, _aws_cdk_aws_bedrock_agentcore_alpha_ICodeInterpreterCustom, _aws_cdk_aws_bedrock_agentcore_alpha_CodeInterpreterCustomBase, _aws_cdk_aws_bedrock_agentcore_alpha_CodeInterpreterCustomProps, _aws_cdk_aws_bedrock_agentcore_alpha_CodeInterpreterCustomAttributes, _aws_cdk_aws_bedrock_agentcore_alpha_CodeInterpreterCustom, _aws_cdk_aws_bedrock_agentcore_alpha_IBrowserCustom, _aws_cdk_aws_bedrock_agentcore_alpha_BrowserCustomBase, _aws_cdk_aws_bedrock_agentcore_alpha_RecordingConfig, _aws_cdk_aws_bedrock_agentcore_alpha_BrowserCustomProps, _aws_cdk_aws_bedrock_agentcore_alpha_BrowserCustomAttributes, _aws_cdk_aws_bedrock_agentcore_alpha_BrowserCustom };
251
+ module.exports = { print, getPropertyDescriptor, DeprecationError, _aws_cdk_aws_bedrock_agentcore_alpha_IMemory, _aws_cdk_aws_bedrock_agentcore_alpha_MemoryBase, _aws_cdk_aws_bedrock_agentcore_alpha_MemoryProps, _aws_cdk_aws_bedrock_agentcore_alpha_MemoryAttributes, _aws_cdk_aws_bedrock_agentcore_alpha_Memory, _aws_cdk_aws_bedrock_agentcore_alpha_OverrideConfig, _aws_cdk_aws_bedrock_agentcore_alpha_ManagedStrategyProps, _aws_cdk_aws_bedrock_agentcore_alpha_ManagedMemoryStrategy, _aws_cdk_aws_bedrock_agentcore_alpha_TriggerConditions, _aws_cdk_aws_bedrock_agentcore_alpha_InvocationConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_SelfManagedStrategyProps, _aws_cdk_aws_bedrock_agentcore_alpha_SelfManagedMemoryStrategy, _aws_cdk_aws_bedrock_agentcore_alpha_MemoryStrategyType, _aws_cdk_aws_bedrock_agentcore_alpha_MemoryStrategyCommonProps, _aws_cdk_aws_bedrock_agentcore_alpha_IMemoryStrategy, _aws_cdk_aws_bedrock_agentcore_alpha_MemoryStrategy, _aws_cdk_aws_bedrock_agentcore_alpha_VpcConfigProps, _aws_cdk_aws_bedrock_agentcore_alpha_NetworkConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_BrowserNetworkConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_CodeInterpreterNetworkConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeNetworkConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_ProtocolType, _aws_cdk_aws_bedrock_agentcore_alpha_IBedrockAgentRuntime, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeBase, _aws_cdk_aws_bedrock_agentcore_alpha_AgentRuntimeAttributes, _aws_cdk_aws_bedrock_agentcore_alpha_AgentRuntimeArtifact, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeAuthorizerConfiguration, _aws_cdk_aws_bedrock_agentcore_alpha_IRuntimeEndpoint, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeEndpointBase, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeEndpointAttributes, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeEndpointProps, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeEndpoint, _aws_cdk_aws_bedrock_agentcore_alpha_RuntimeProps, _aws_cdk_aws_bedrock_agentcore_alpha_AddEndpointOptions, _aws_cdk_aws_bedrock_agentcore_alpha_Runtime, _aws_cdk_aws_bedrock_agentcore_alpha_ICodeInterpreterCustom, _aws_cdk_aws_bedrock_agentcore_alpha_CodeInterpreterCustomBase, _aws_cdk_aws_bedrock_agentcore_alpha_CodeInterpreterCustomProps, _aws_cdk_aws_bedrock_agentcore_alpha_CodeInterpreterCustomAttributes, _aws_cdk_aws_bedrock_agentcore_alpha_CodeInterpreterCustom, _aws_cdk_aws_bedrock_agentcore_alpha_IBrowserCustom, _aws_cdk_aws_bedrock_agentcore_alpha_BrowserCustomBase, _aws_cdk_aws_bedrock_agentcore_alpha_RecordingConfig, _aws_cdk_aws_bedrock_agentcore_alpha_BrowserCustomProps, _aws_cdk_aws_bedrock_agentcore_alpha_BrowserCustomAttributes, _aws_cdk_aws_bedrock_agentcore_alpha_BrowserCustom };
package/README.md CHANGED
@@ -45,6 +45,11 @@ This construct library facilitates the deployment of Bedrock AgentCore primitive
45
45
  - [Code Interpreter Network Modes](#code-interpreter-network-modes)
46
46
  - [Basic Code Interpreter Creation](#basic-code-interpreter-creation)
47
47
  - [Code Interpreter IAM permissions](#code-interpreter-iam-permissions)
48
+ - [Memory](#memory)
49
+ - [Memory properties](#memory-properties)
50
+ - [Basic Memory Creation](#basic-memory-creation)
51
+ - [LTM Memory Extraction Stategies](#ltm-memory-extraction-stategies)
52
+ - [Memory Strategy Methods](#memory-strategy-methods)
48
53
 
49
54
 
50
55
  ## AgentCore Runtime
@@ -115,9 +120,9 @@ const runtime = new agentcore.Runtime(this, "MyAgentRuntime", {
115
120
 
116
121
  To grant the runtime permission to invoke a Bedrock model or inference profile:
117
122
 
118
- ```text
123
+ ```typescript fixture=default
119
124
  // Note: This example uses @aws-cdk/aws-bedrock-alpha which must be installed separately
120
- import * as bedrock from '@aws-cdk/aws-bedrock-alpha';
125
+ declare const runtime: agentcore.Runtime;
121
126
 
122
127
  // Create a cross-region inference profile for Claude 3.7 Sonnet
123
128
  const inferenceProfile = bedrock.CrossRegionInferenceProfile.fromConfig({
@@ -298,6 +303,10 @@ IAM authentication is the default mode, when no authorizerConfiguration is set t
298
303
  To configure AWS Cognito User Pool authentication:
299
304
 
300
305
  ```typescript
306
+ declare const userPool: cognito.UserPool;
307
+ declare const userPoolClient: cognito.UserPoolClient;
308
+ declare const anotherUserPoolClient: cognito.UserPoolClient;
309
+
301
310
  const repository = new ecr.Repository(this, "TestRepository", {
302
311
  repositoryName: "test-agent-runtime",
303
312
  });
@@ -307,9 +316,8 @@ const runtime = new agentcore.Runtime(this, "MyAgentRuntime", {
307
316
  runtimeName: "myAgent",
308
317
  agentRuntimeArtifact: agentRuntimeArtifact,
309
318
  authorizerConfiguration: agentcore.RuntimeAuthorizerConfiguration.usingCognito(
310
- "us-west-2_ABC123", // User Pool ID (required)
311
- "client123", // Client ID (required)
312
- "us-west-2" // Region (optional, defaults to stack region)
319
+ userPool, // User Pool (required)
320
+ [userPoolClient, anotherUserPoolClient], // User Pool Clients
313
321
  ),
314
322
  });
315
323
  ```
@@ -794,3 +802,317 @@ const codeInterpreter = new agentcore.CodeInterpreterCustom(this, "MyCodeInterpr
794
802
  },
795
803
  });
796
804
  ```
805
+
806
+ ## Memory
807
+
808
+ Memory is a critical component of intelligence. While Large Language Models (LLMs) have impressive capabilities, they lack persistent memory across conversations. Amazon Bedrock AgentCore Memory addresses this limitation by providing a managed service that enables AI agents to maintain context over time, remember important facts, and deliver consistent, personalized experiences.
809
+
810
+ AgentCore Memory operates on two levels:
811
+
812
+ - **Short-Term Memory**: Immediate conversation context and session-based information that provides continuity within a single interaction or closely related sessions.
813
+ - **Long-Term Memory**: Persistent information extracted and stored across multiple conversations, including facts, preferences, and summaries that enable personalized experiences over time.
814
+
815
+ When you interact with the memory via the `CreateEvent` API, you store interactions in Short-Term Memory (STM) instantly. These interactions can include everything from user messages, assistant responses, to tool actions.
816
+
817
+ To write to long-term memory, you need to configure extraction strategies which define how and where to store information from conversations for future use. These strategies are asynchronously processed from raw events after every few turns based on the strategy that was selected. You can't create long term memory records directly, as they are extracted asynchronously by AgentCore Memory.
818
+
819
+ ### Memory Properties
820
+
821
+ | Name | Type | Required | Description |
822
+ |------|------|----------|-------------|
823
+ | `memoryName` | `string` | Yes | The name of the memory |
824
+ | `expirationDuration` | `Duration` | No | Short-term memory expiration in days (between 7 and 365). Default: 90 days |
825
+ | `description` | `string` | No | Optional description for the memory. Default: no description. |
826
+ | `kmsKey` | `IKey` | No | Custom KMS key to use for encryption. Default: Your data is encrypted with a key that AWS owns and manages for you |
827
+ | `memoryStrategies` | `MemoryStrategyBase[]` | No | Built-in extraction strategies to use for this memory. Default: No extraction strategies (short term memory only) |
828
+ | `executionRole` | `iam.IRole` | No | The IAM role that provides permissions for the memory to access AWS services. Default: A new role will be created. |
829
+ | `tags` | `{ [key: string]: string }` | No | Tags for memory. Default: no tags. |
830
+
831
+ ### Basic Memory Creation
832
+
833
+ Below you can find how to configure a simple short-term memory (STM) with no long-term memory extraction strategies.
834
+ Note how you set `expirationDuration`, which defines the time the events will be stored in the short-term memory before they expire.
835
+
836
+ ```typescript fixture=default
837
+
838
+ // Create a basic memory with default settings, no LTM strategies
839
+ const memory = new agentcore.Memory(this, "MyMemory", {
840
+ memoryName: "my_memory",
841
+ description: "A memory for storing user interactions for a period of 90 days",
842
+ expirationDuration: cdk.Duration.days(90),
843
+ });
844
+ ```
845
+
846
+ Basic Memory with Custom KMS Encryption
847
+
848
+ ```typescript fixture=default
849
+ // Create a custom KMS key for encryption
850
+ const encryptionKey = new kms.Key(this, "MemoryEncryptionKey", {
851
+ enableKeyRotation: true,
852
+ description: "KMS key for memory encryption",
853
+ });
854
+
855
+ // Create memory with custom encryption
856
+ const memory = new agentcore.Memory(this, "MyMemory", {
857
+ memoryName: "my_encrypted_memory",
858
+ description: "Memory with custom KMS encryption",
859
+ expirationDuration: cdk.Duration.days(90),
860
+ kmsKey: encryptionKey,
861
+ });
862
+ ```
863
+
864
+ ### LTM Memory Extraction Stategies
865
+
866
+ If you need long-term memory for context recall across sessions, you can setup memory extraction strategies
867
+ to extract the relevant memory from the raw events.
868
+
869
+ Amazon Bedrock AgentCore Memory has different memory strategies for extracting and organizing information:
870
+
871
+ - **Summarization**: to summarize interactions to preserve critical context and key insights.
872
+ - **Semantic Memory**: to extract general factual knowledge, concepts and meanings from raw conversations using vector embeddings.
873
+ This enables similarity-based retrieval of relevant facts and context.
874
+ - **User Preferences**: to extract user behavior patterns from raw conversations.
875
+
876
+ You can use built-in extraction strategies for quick setup, or create custom extraction strategies with specific models and prompt templates.
877
+
878
+ ### Memory with Built-in Strategies
879
+
880
+ The library provides three built-in LTM strategies. These are default strategies for organizing and extracting memory data,
881
+ each optimized for specific use cases.
882
+
883
+ For example: An agent helps multiple users with cloud storage setup. From these conversations,
884
+ see how each strategy processes users expressing confusion about account connection:
885
+
886
+ 1. **Summarization Strategy** (`MemoryStrategy.usingBuiltInSummarization()`)
887
+ This strategy compresses conversations into concise overviews, preserving essential context and key insights for quick recall.
888
+ Extracted memory example: Users confused by cloud setup during onboarding.
889
+
890
+ - Extracts concise summaries to preserve critical context and key insights
891
+ - Namespace: `/strategies/{memoryStrategyId}/actors/{actorId}/sessions/{sessionId}`
892
+
893
+ 2. **Semantic Memory Strategy** (`MemoryStrategy.usingBuiltInSemantic()`)
894
+ Distills general facts, concepts, and underlying meanings from raw conversational data, presenting the information in a context-independent format.
895
+ Extracted memory example: In-context learning = task-solving via examples, no training needed.
896
+
897
+ - Extracts general factual knowledge, concepts and meanings from raw conversations
898
+ - Namespace: `/strategies/{memoryStrategyId}/actors/{actorId}`
899
+
900
+ 3. **User Preference Strategy** (`MemoryStrategy.usingBuiltInUserPreference()`)
901
+ Captures individual preferences, interaction patterns, and personalized settings to enhance future experiences.
902
+ Extracted memory example: User needs clear guidance on cloud storage account connection during onboarding.
903
+
904
+ - Extracts user behavior patterns from raw conversations
905
+ - Namespace: `/strategies/{memoryStrategyId}/actors/{actorId}`
906
+
907
+ ```typescript fixture=default
908
+ // Create memory with built-in strategies
909
+ const memory = new agentcore.Memory(this, "MyMemory", {
910
+ memoryName: "my_memory",
911
+ description: "Memory with built-in strategies",
912
+ expirationDuration: cdk.Duration.days(90),
913
+ memoryStrategies: [
914
+ agentcore.MemoryStrategy.usingBuiltInSummarization(),
915
+ agentcore.MemoryStrategy.usingBuiltInSemantic(),
916
+ agentcore.MemoryStrategy.usingBuiltInUserPreference(),
917
+ ],
918
+ });
919
+ ```
920
+
921
+ The name generated for each built in memory strategy is as follows:
922
+
923
+ - For Summarization: `summary_builtin_cdk001`
924
+ - For Semantic:`semantic_builtin_cdk001>`
925
+ - For User Preferences: `preference_builtin_cdk001`
926
+
927
+ ### Memory with custom Strategies
928
+
929
+ With Long-Term Memory, organization is managed through Namespaces.
930
+
931
+ An `actor` refers to entity such as end users or agent/user combinations. For example, in a coding support chatbot,
932
+ the actor is usually the developer asking questions. Using the actor ID helps the system know which user the memory belongs to,
933
+ keeping each user's data separate and organized.
934
+
935
+ A `session` is usually a single conversation or interaction period between the user and the AI agent.
936
+ It groups all related messages and events that happen during that conversation.
937
+
938
+ A `namespace` is used to logically group and organize long-term memories. It ensures data stays neat, separate, and secure.
939
+
940
+ With AgentCore Memory, you need to add a namespace when you define a memory strategy. This namespace helps define where the long-term memory
941
+ will be logically grouped. Every time a new long-term memory is extracted using this memory strategy, it is saved under the namespace you set.
942
+ This means that all long-term memories are scoped to their specific namespace, keeping them organized and preventing any mix-ups with other
943
+ users or sessions. You should use a hierarchical format separated by forward slashes /. This helps keep memories organized clearly. As needed,
944
+ you can choose to use the below pre-defined variables within braces in the namespace based on your applications' organization needs:
945
+
946
+ - `actorId` – Identifies who the long-term memory belongs to, such as a user
947
+ - `memoryStrategyId` – Shows which memory strategy is being used. This strategy identifier is auto-generated when you create a memory using CreateMemory operation.
948
+ - `sessionId` – Identifies which session or conversation the memory is from.
949
+
950
+ For example, if you define the following namespace as the input to your strategy in CreateMemory operation:
951
+
952
+ ```shell
953
+ /strategy/{memoryStrategyId}/actor/{actorId}/session/{sessionId}
954
+ ```
955
+
956
+ After memory creation, this namespace might look like:
957
+
958
+ ```shell
959
+ /strategy/summarization-93483043//actor/actor-9830m2w3/session/session-9330sds8
960
+ ```
961
+
962
+ You can customise the namespace, i.e. where the memories are stored by using the following methods:
963
+
964
+ 1. **Summarization Strategy** (`MemoryStrategy.usingSummarization(props)`)
965
+ 1. **Semantic Memory Strategy** (`MemoryStrategy.usingSemantic(props)`)
966
+ 1. **User Preference Strategy** (`MemoryStrategy.usingUserPreference(props)`)
967
+
968
+ ```typescript fixture=default
969
+ // Create memory with built-in strategies
970
+ const memory = new agentcore.Memory(this, "MyMemory", {
971
+ memoryName: "my_memory",
972
+ description: "Memory with built-in strategies",
973
+ expirationDuration: cdk.Duration.days(90),
974
+ memoryStrategies: [
975
+ agentcore.MemoryStrategy.usingUserPreference({
976
+ name: "CustomerPreferences",
977
+ namespaces: ["support/customer/{actorId}/preferences"]
978
+ }),
979
+ agentcore.MemoryStrategy.usingSemantic({
980
+ name: "CustomerSupportSemantic",
981
+ namespaces: ["support/customer/{actorId}/semantic"]
982
+ }),
983
+ ],
984
+ });
985
+ ```
986
+
987
+ Custom memory strategies let you tailor memory extraction and consolidation to your specific domain or use case.
988
+ You can override the prompts for extracting and consolidating semantic, summary, or user preferences.
989
+ You can also choose the model that you want to use for extraction and consolidation.
990
+
991
+ The custom prompts you create are appended to a non-editable system prompt.
992
+
993
+ Since a custom strategy requires you to invoke certain FMs, you need a role with appropriate permissions. For that, you can:
994
+
995
+ - Let the L2 construct create a minimum permission role for you when use L2 Bedrock Foundation Models.
996
+ - Use a custom role with the overly permissive `AmazonBedrockAgentCoreMemoryBedrockModelInferenceExecutionRolePolicy` managed policy.
997
+ - Use a custom role with your own custom policies.
998
+
999
+ #### Memory with Custom Execution Role
1000
+
1001
+ Keep in mind that memories that **do not** use custom strategies do not require a service role.
1002
+ So even if you provide it, it will be ignored as it will never be used.
1003
+
1004
+ ```typescript fixture=default
1005
+ // Create a custom execution role
1006
+ const executionRole = new iam.Role(this, "MemoryExecutionRole", {
1007
+ assumedBy: new iam.ServicePrincipal("bedrock-agentcore.amazonaws.com"),
1008
+ managedPolicies: [
1009
+ iam.ManagedPolicy.fromAwsManagedPolicyName(
1010
+ "AmazonBedrockAgentCoreMemoryBedrockModelInferenceExecutionRolePolicy"
1011
+ ),
1012
+ ],
1013
+ });
1014
+
1015
+ // Create memory with custom execution role
1016
+ const memory = new agentcore.Memory(this, "MyMemory", {
1017
+ memoryName: "my_memory",
1018
+ description: "Memory with custom execution role",
1019
+ expirationDuration: cdk.Duration.days(90),
1020
+ executionRole: executionRole,
1021
+ });
1022
+ ```
1023
+
1024
+ In customConsolidation and customExtraction, the model property uses the [@aws-cdk/aws-bedrock-alph](https://www.npmjs.com/package/@aws-cdk/aws-bedrock-alpha) library which must be installed separately.
1025
+
1026
+ ```typescript fixture=default
1027
+ // Create a custom semantic memory strategy
1028
+ const customSemanticStrategy = agentcore.MemoryStrategy.usingSemantic({
1029
+ name: "customSemanticStrategy",
1030
+ description: "Custom semantic memory strategy",
1031
+ namespaces: ["/custom/strategies/{memoryStrategyId}/actors/{actorId}"],
1032
+ customConsolidation: {
1033
+ model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
1034
+ appendToPrompt: "Custom consolidation prompt for semantic memory",
1035
+ },
1036
+ customExtraction: {
1037
+ model: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
1038
+ appendToPrompt: "Custom extraction prompt for semantic memory",
1039
+ },
1040
+ });
1041
+
1042
+ // Create memory with custom strategy
1043
+ const memory = new agentcore.Memory(this, "MyMemory", {
1044
+ memoryName: "my-custom-memory",
1045
+ description: "Memory with custom strategy",
1046
+ expirationDuration: cdk.Duration.days(90),
1047
+ memoryStrategies: [customSemanticStrategy],
1048
+ });
1049
+ ```
1050
+
1051
+ ### Memory with self-managed Strategies
1052
+
1053
+ A self-managed strategy in Amazon Bedrock AgentCore Memory gives you complete control over your memory extraction and consolidation pipelines.
1054
+ With a self-managed strategy, you can build custom memory processing workflows while leveraging Amazon Bedrock AgentCore for storage and retrieval.
1055
+
1056
+ For additional information, you can refer to the [developer guide for self managed strategies](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory-self-managed-strategies.html).
1057
+
1058
+ Create the required AWS resources including:
1059
+
1060
+ - an S3 bucket in your account where Amazon Bedrock AgentCore will deliver batched event payloads.
1061
+ - an SNS topic for job notifications. Use FIFO topics if processing order within sessions is important for your use case.
1062
+
1063
+ The construct will apply the correct permissions to the memory execution role to access these resources.
1064
+
1065
+ ```typescript fixture=default
1066
+
1067
+ const bucket = new s3.Bucket(this, 'memoryBucket', {
1068
+ bucketName: 'test-memory',
1069
+ removalPolicy: cdk.RemovalPolicy.DESTROY,
1070
+ autoDeleteObjects: true,
1071
+ });
1072
+
1073
+ const topic = new sns.Topic(this, 'topic');
1074
+
1075
+ // Create a custom semantic memory strategy
1076
+ const selfManagedStrategy = agentcore.MemoryStrategy.usingSelfManaged({
1077
+ name: "selfManagedStrategy",
1078
+ description: "self managed memory strategy",
1079
+ historicalContextWindowSize: 5,
1080
+ invocationConfiguration: {
1081
+ topic: topic,
1082
+ s3Location: {
1083
+ bucketName: bucket.bucketName,
1084
+ objectKey: 'memory/',
1085
+ }
1086
+ },
1087
+ triggerConditions: {
1088
+ messageBasedTrigger: 1,
1089
+ timeBasedTrigger: cdk.Duration.seconds(10),
1090
+ tokenBasedTrigger: 100
1091
+ }
1092
+ });
1093
+
1094
+ // Create memory with custom strategy
1095
+ const memory = new agentcore.Memory(this, "MyMemory", {
1096
+ memoryName: "my-custom-memory",
1097
+ description: "Memory with custom strategy",
1098
+ expirationDuration: cdk.Duration.days(90),
1099
+ memoryStrategies: [selfManagedStrategy],
1100
+ });
1101
+ ```
1102
+
1103
+ ### Memory Strategy Methods
1104
+
1105
+ You can add new memory strategies to the memory construct using the `addMemoryStrategy()` method, for instance:
1106
+
1107
+ ```typescript fixture=default
1108
+ // Create memory without initial strategies
1109
+ const memory = new agentcore.Memory(this, "test-memory", {
1110
+ memoryName: "test_memory_add_strategy",
1111
+ description: "A test memory for testing addMemoryStrategy method",
1112
+ expirationDuration: cdk.Duration.days(90),
1113
+ });
1114
+
1115
+ // Add strategies after instantiation
1116
+ memory.addMemoryStrategy(agentcore.MemoryStrategy.usingBuiltInSummarization());
1117
+ memory.addMemoryStrategy(agentcore.MemoryStrategy.usingBuiltInSemantic());
1118
+ ```
@@ -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';
1
5
  export * from './network/network-configuration';
2
6
  export * from './runtime/perms';
3
7
  export * from './runtime/types';
@@ -14,6 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./memory/memory"), exports);
18
+ __exportStar(require("./memory/strategies/managed-strategy"), exports);
19
+ __exportStar(require("./memory/strategies/self-managed-strategy"), exports);
20
+ __exportStar(require("./memory/memory-strategy"), exports);
17
21
  // ===================================
18
22
  // Network Configuration
19
23
  // ===================================
@@ -33,4 +37,4 @@ __exportStar(require("./runtime/runtime"), exports);
33
37
  // ===================================
34
38
  __exportStar(require("./tools/code-interpreter"), exports);
35
39
  __exportStar(require("./tools/browser"), exports);
36
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsc0NBQXNDO0FBQ3RDLHdCQUF3QjtBQUN4QixzQ0FBc0M7QUFDdEMsa0VBQWdEO0FBRWhELHNDQUFzQztBQUN0QyxVQUFVO0FBQ1Ysc0NBQXNDO0FBQ3RDLGtEQUFnQztBQUNoQyxrREFBZ0M7QUFDaEMseURBQXVDO0FBQ3ZDLDZEQUEyQztBQUMzQyw2RUFBMkQ7QUFDM0Qsa0VBQWdEO0FBQ2hELDZEQUEyQztBQUMzQyxvREFBa0M7QUFDbEMsUUFBUTtBQUNSLHNDQUFzQztBQUN0QywyREFBeUM7QUFDekMsa0RBQWdDIiwic291cmNlc0NvbnRlbnQiOlsiLy8gPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT1cbi8vIE5ldHdvcmsgQ29uZmlndXJhdGlvblxuLy8gPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT1cbmV4cG9ydCAqIGZyb20gJy4vbmV0d29yay9uZXR3b3JrLWNvbmZpZ3VyYXRpb24nO1xuXG4vLyA9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PVxuLy8gUnVudGltZVxuLy8gPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT1cbmV4cG9ydCAqIGZyb20gJy4vcnVudGltZS9wZXJtcyc7XG5leHBvcnQgKiBmcm9tICcuL3J1bnRpbWUvdHlwZXMnO1xuZXhwb3J0ICogZnJvbSAnLi9ydW50aW1lL3J1bnRpbWUtYmFzZSc7XG5leHBvcnQgKiBmcm9tICcuL3J1bnRpbWUvcnVudGltZS1hcnRpZmFjdCc7XG5leHBvcnQgKiBmcm9tICcuL3J1bnRpbWUvcnVudGltZS1hdXRob3JpemVyLWNvbmZpZ3VyYXRpb24nO1xuZXhwb3J0ICogZnJvbSAnLi9ydW50aW1lL3J1bnRpbWUtZW5kcG9pbnQtYmFzZSc7XG5leHBvcnQgKiBmcm9tICcuL3J1bnRpbWUvcnVudGltZS1lbmRwb2ludCc7XG5leHBvcnQgKiBmcm9tICcuL3J1bnRpbWUvcnVudGltZSc7XG4vLyBUb29sc1xuLy8gPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT1cbmV4cG9ydCAqIGZyb20gJy4vdG9vbHMvY29kZS1pbnRlcnByZXRlcic7XG5leHBvcnQgKiBmcm9tICcuL3Rvb2xzL2Jyb3dzZXInO1xuIl19
40
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7O0FBQUEsa0RBQWdDO0FBQ2hDLHVFQUFxRDtBQUNyRCw0RUFBMEQ7QUFDMUQsMkRBQXlDO0FBQ3pDLHNDQUFzQztBQUN0Qyx3QkFBd0I7QUFDeEIsc0NBQXNDO0FBQ3RDLGtFQUFnRDtBQUVoRCxzQ0FBc0M7QUFDdEMsVUFBVTtBQUNWLHNDQUFzQztBQUN0QyxrREFBZ0M7QUFDaEMsa0RBQWdDO0FBQ2hDLHlEQUF1QztBQUN2Qyw2REFBMkM7QUFDM0MsNkVBQTJEO0FBQzNELGtFQUFnRDtBQUNoRCw2REFBMkM7QUFDM0Msb0RBQWtDO0FBQ2xDLFFBQVE7QUFDUixzQ0FBc0M7QUFDdEMsMkRBQXlDO0FBQ3pDLGtEQUFnQyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gJy4vbWVtb3J5L21lbW9yeSc7XG5leHBvcnQgKiBmcm9tICcuL21lbW9yeS9zdHJhdGVnaWVzL21hbmFnZWQtc3RyYXRlZ3knO1xuZXhwb3J0ICogZnJvbSAnLi9tZW1vcnkvc3RyYXRlZ2llcy9zZWxmLW1hbmFnZWQtc3RyYXRlZ3knO1xuZXhwb3J0ICogZnJvbSAnLi9tZW1vcnkvbWVtb3J5LXN0cmF0ZWd5Jztcbi8vID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09XG4vLyBOZXR3b3JrIENvbmZpZ3VyYXRpb25cbi8vID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09XG5leHBvcnQgKiBmcm9tICcuL25ldHdvcmsvbmV0d29yay1jb25maWd1cmF0aW9uJztcblxuLy8gPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT1cbi8vIFJ1bnRpbWVcbi8vID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09XG5leHBvcnQgKiBmcm9tICcuL3J1bnRpbWUvcGVybXMnO1xuZXhwb3J0ICogZnJvbSAnLi9ydW50aW1lL3R5cGVzJztcbmV4cG9ydCAqIGZyb20gJy4vcnVudGltZS9ydW50aW1lLWJhc2UnO1xuZXhwb3J0ICogZnJvbSAnLi9ydW50aW1lL3J1bnRpbWUtYXJ0aWZhY3QnO1xuZXhwb3J0ICogZnJvbSAnLi9ydW50aW1lL3J1bnRpbWUtYXV0aG9yaXplci1jb25maWd1cmF0aW9uJztcbmV4cG9ydCAqIGZyb20gJy4vcnVudGltZS9ydW50aW1lLWVuZHBvaW50LWJhc2UnO1xuZXhwb3J0ICogZnJvbSAnLi9ydW50aW1lL3J1bnRpbWUtZW5kcG9pbnQnO1xuZXhwb3J0ICogZnJvbSAnLi9ydW50aW1lL3J1bnRpbWUnO1xuLy8gVG9vbHNcbi8vID09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09XG5leHBvcnQgKiBmcm9tICcuL3Rvb2xzL2NvZGUtaW50ZXJwcmV0ZXInO1xuZXhwb3J0ICogZnJvbSAnLi90b29scy9icm93c2VyJztcbiJdfQ==
@@ -0,0 +1,164 @@
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
+ import * as bedrockagentcore from 'aws-cdk-lib/aws-bedrockagentcore';
14
+ import * as iam from 'aws-cdk-lib/aws-iam';
15
+ import { ManagedMemoryStrategy, ManagedStrategyProps } from './strategies/managed-strategy';
16
+ import { SelfManagedMemoryStrategy, SelfManagedStrategyProps } from './strategies/self-managed-strategy';
17
+ /******************************************************************************
18
+ * CONSTANTS
19
+ *****************************************************************************/
20
+ /**
21
+ * Minimum length for memory strategy name
22
+ * @internal
23
+ */
24
+ export declare const MEMORY_NAME_MIN_LENGTH = 1;
25
+ /**
26
+ * Maximum length for memory strategy name
27
+ * @internal
28
+ */
29
+ export declare const MEMORY_NAME_MAX_LENGTH = 48;
30
+ /**
31
+ * Long-term memory extraction strategy types.
32
+ */
33
+ export declare enum MemoryStrategyType {
34
+ /**
35
+ * Summarization strategy - extracts concise summaries to preserve critical context and key insights
36
+ */
37
+ SUMMARIZATION = "SUMMARIZATION",
38
+ /**
39
+ * Semantic memory strategy - extracts general factual knowledge, concepts and meanings from raw conversations
40
+ * using vector embeddings for similarity search.
41
+ */
42
+ SEMANTIC = "SEMANTIC",
43
+ /**
44
+ * User preferences strategy - extracts user behavior patterns from raw conversations.
45
+ */
46
+ USER_PREFERENCE = "USER_PREFERENCE",
47
+ /**
48
+ * Customize memory processing through custom foundation model and prompt templates.
49
+ */
50
+ CUSTOM = "CUSTOM"
51
+ }
52
+ /******************************************************************************
53
+ * Common
54
+ *****************************************************************************/
55
+ /**
56
+ * Configuration parameters common for any memory strategy
57
+ */
58
+ export interface MemoryStrategyCommonProps {
59
+ /**
60
+ * The name for the strategy
61
+ * @required - Yes
62
+ */
63
+ readonly name: string;
64
+ /**
65
+ * The description of the strategy
66
+ * @default No description
67
+ * @required - No
68
+ */
69
+ readonly description?: string;
70
+ }
71
+ /******************************************************************************
72
+ * Interface
73
+ *****************************************************************************/
74
+ /**
75
+ * Interface for Memory strategies
76
+ */
77
+ export interface IMemoryStrategy {
78
+ /**
79
+ * The name of the memory strategy
80
+ */
81
+ readonly name: string;
82
+ /**
83
+ * The description of the memory strategy
84
+ */
85
+ readonly description?: string;
86
+ /**
87
+ * The type of memory strategy
88
+ */
89
+ readonly strategyType: MemoryStrategyType;
90
+ /**
91
+ * Renders internal attributes to CloudFormation
92
+ */
93
+ render(): bedrockagentcore.CfnMemory.MemoryStrategyProperty;
94
+ /**
95
+ * Grants the necessary permissions to the role
96
+ * @param grantee - The grantee to grant permissions to
97
+ * @returns The Grant object for chaining
98
+ */
99
+ grant(grantee: iam.IGrantable): iam.Grant | undefined;
100
+ }
101
+ /******************************************************************************
102
+ * Factory
103
+ *****************************************************************************/
104
+ /**
105
+ * Factory class for creating memory strategies
106
+ * 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.
107
+ * Use built-in strategies for quick setup, use built-in strategies with override to specify models and prompt templates.
108
+ *
109
+ * @see https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory-strategies.html
110
+ */
111
+ export declare class MemoryStrategy {
112
+ /**
113
+ * Default strategies for organizing and extracting memory data, each optimized for specific use cases.
114
+ * This strategy compresses conversations into concise overviews, preserving essential context and key insights for quick recall.
115
+ * Extracted memory example: Users confused by cloud setup during onboarding.
116
+ * @returns A ManagedMemoryStrategy.
117
+ */
118
+ static usingBuiltInSummarization(): ManagedMemoryStrategy;
119
+ /**
120
+ * Default strategies for organizing and extracting memory data, each optimized for specific use cases.
121
+ * Distills general facts, concepts, and underlying meanings from raw conversational data, presenting the information in a context-independent format.
122
+ * Extracted memory example: In-context learning = task-solving via examples, no training needed.
123
+ * @returns A ManagedMemoryStrategy.
124
+ */
125
+ static usingBuiltInSemantic(): ManagedMemoryStrategy;
126
+ /**
127
+ * Default strategies for organizing and extracting memory data, each optimized for specific use cases.
128
+ * Captures individual preferences, interaction patterns, and personalized settings to enhance future experiences.
129
+ * Extracted memory example: User needs clear guidance on cloud storage account connection during onboarding.
130
+ * @returns A ManagedMemoryStrategy.
131
+ */
132
+ static usingBuiltInUserPreference(): ManagedMemoryStrategy;
133
+ /**
134
+ * Creates a semantic memory strategy with custom configuration.
135
+ * Distills general facts, concepts, and underlying meanings from raw conversational data, presenting the information in a context-independent format.
136
+ * Extracted memory example: In-context learning = task-solving via examples, no training needed.
137
+ * @param config - The configuration for the semantic memory strategy.
138
+ * @returns A ManagedMemoryStrategy.
139
+ */
140
+ static usingSemantic(config: ManagedStrategyProps): ManagedMemoryStrategy;
141
+ /**
142
+ * Creates a user preference memory strategy with custom configuration.
143
+ * Captures individual preferences, interaction patterns, and personalized settings to enhance future experiences.
144
+ * Extracted memory example: User needs clear guidance on cloud storage account connection during onboarding.
145
+ * @param config - The configuration for the user preference memory strategy.
146
+ * @returns A ManagedMemoryStrategy.
147
+ */
148
+ static usingUserPreference(config: ManagedStrategyProps): ManagedMemoryStrategy;
149
+ /**
150
+ * Creates a summarization memory strategy with custom configuration.
151
+ * This strategy compresses conversations into concise overviews, preserving essential context and key insights for quick recall.
152
+ * Extracted memory example: Users confused by cloud setup during onboarding.
153
+ * @param config - The configuration for the summarization memory strategy.
154
+ * @returns A ManagedMemoryStrategy.
155
+ */
156
+ static usingSummarization(config: ManagedStrategyProps): ManagedMemoryStrategy;
157
+ /**
158
+ * Creates a self-managed memory strategy.
159
+ * A self-managed strategy gives you complete control over your memory extraction and consolidation pipelines.
160
+ * @param config - The configuration for the self-managed memory strategy.
161
+ * @returns A SelfManagedMemoryStrategy.
162
+ */
163
+ static usingSelfManaged(config: SelfManagedStrategyProps): SelfManagedMemoryStrategy;
164
+ }