aws-cdk.aws-bedrock-agentcore-alpha 2.221.1a0__tar.gz → 2.223.0a0__tar.gz
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.
Potentially problematic release.
This version of aws-cdk.aws-bedrock-agentcore-alpha might be problematic. Click here for more details.
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0/src/aws_cdk.aws_bedrock_agentcore_alpha.egg-info → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/PKG-INFO +335 -14
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/README.md +331 -11
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/setup.py +5 -4
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/src/aws_cdk/aws_bedrock_agentcore_alpha/__init__.py +6283 -1575
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/src/aws_cdk/aws_bedrock_agentcore_alpha/_jsii/__init__.py +3 -2
- aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0/src/aws_cdk/aws_bedrock_agentcore_alpha/_jsii/aws-bedrock-agentcore-alpha@2.223.0-alpha.0.jsii.tgz +0 -0
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0/src/aws_cdk.aws_bedrock_agentcore_alpha.egg-info}/PKG-INFO +335 -14
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/src/aws_cdk.aws_bedrock_agentcore_alpha.egg-info/SOURCES.txt +1 -1
- aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0/src/aws_cdk.aws_bedrock_agentcore_alpha.egg-info/requires.txt +6 -0
- aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0/src/aws_cdk/aws_bedrock_agentcore_alpha/_jsii/aws-bedrock-agentcore-alpha@2.221.1-alpha.0.jsii.tgz +0 -0
- aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0/src/aws_cdk.aws_bedrock_agentcore_alpha.egg-info/requires.txt +0 -5
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/LICENSE +0 -0
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/MANIFEST.in +0 -0
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/NOTICE +0 -0
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/pyproject.toml +0 -0
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/setup.cfg +0 -0
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/src/aws_cdk/aws_bedrock_agentcore_alpha/py.typed +0 -0
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/src/aws_cdk.aws_bedrock_agentcore_alpha.egg-info/dependency_links.txt +0 -0
- {aws_cdk_aws_bedrock_agentcore_alpha-2.221.1a0 → aws_cdk_aws_bedrock_agentcore_alpha-2.223.0a0}/src/aws_cdk.aws_bedrock_agentcore_alpha.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: aws-cdk.aws-bedrock-agentcore-alpha
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.223.0a0
|
|
4
4
|
Summary: The CDK Construct Library for Amazon Bedrock
|
|
5
5
|
Home-page: https://github.com/aws/aws-cdk
|
|
6
6
|
Author: Amazon Web Services
|
|
@@ -22,9 +22,10 @@ Requires-Python: ~=3.9
|
|
|
22
22
|
Description-Content-Type: text/markdown
|
|
23
23
|
License-File: LICENSE
|
|
24
24
|
License-File: NOTICE
|
|
25
|
-
Requires-Dist: aws-cdk-lib<3.0.0,>=2.
|
|
25
|
+
Requires-Dist: aws-cdk-lib<3.0.0,>=2.223.0
|
|
26
|
+
Requires-Dist: aws-cdk.aws-bedrock-alpha==2.223.0.a0
|
|
26
27
|
Requires-Dist: constructs<11.0.0,>=10.0.0
|
|
27
|
-
Requires-Dist: jsii<2.0.0,>=1.
|
|
28
|
+
Requires-Dist: jsii<2.0.0,>=1.118.0
|
|
28
29
|
Requires-Dist: publication>=0.0.3
|
|
29
30
|
Requires-Dist: typeguard<4.3.0,>=2.13.3
|
|
30
31
|
|
|
@@ -77,6 +78,12 @@ This construct library facilitates the deployment of Bedrock AgentCore primitive
|
|
|
77
78
|
* [Code Interpreter Network Modes](#code-interpreter-network-modes)
|
|
78
79
|
* [Basic Code Interpreter Creation](#basic-code-interpreter-creation)
|
|
79
80
|
* [Code Interpreter IAM permissions](#code-interpreter-iam-permissions)
|
|
81
|
+
* [Memory](#memory)
|
|
82
|
+
|
|
83
|
+
* [Memory properties](#memory-properties)
|
|
84
|
+
* [Basic Memory Creation](#basic-memory-creation)
|
|
85
|
+
* [LTM Memory Extraction Stategies](#ltm-memory-extraction-stategies)
|
|
86
|
+
* [Memory Strategy Methods](#memory-strategy-methods)
|
|
80
87
|
|
|
81
88
|
## AgentCore Runtime
|
|
82
89
|
|
|
@@ -146,18 +153,19 @@ runtime = agentcore.Runtime(self, "MyAgentRuntime",
|
|
|
146
153
|
|
|
147
154
|
To grant the runtime permission to invoke a Bedrock model or inference profile:
|
|
148
155
|
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
```python
|
|
157
|
+
# Note: This example uses @aws-cdk/aws-bedrock-alpha which must be installed separately
|
|
158
|
+
# runtime: agentcore.Runtime
|
|
159
|
+
|
|
152
160
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
161
|
+
# Create a cross-region inference profile for Claude 3.7 Sonnet
|
|
162
|
+
inference_profile = bedrock.CrossRegionInferenceProfile.from_config(
|
|
163
|
+
geo_region=bedrock.CrossRegionInferenceProfileRegion.US,
|
|
164
|
+
model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_7_SONNET_V1_0
|
|
165
|
+
)
|
|
158
166
|
|
|
159
|
-
|
|
160
|
-
|
|
167
|
+
# Grant the runtime permission to invoke the inference profile
|
|
168
|
+
inference_profile.grant_invoke(runtime)
|
|
161
169
|
```
|
|
162
170
|
|
|
163
171
|
#### Option 2: Use a local asset
|
|
@@ -328,6 +336,11 @@ IAM authentication is the default mode, when no authorizerConfiguration is set t
|
|
|
328
336
|
To configure AWS Cognito User Pool authentication:
|
|
329
337
|
|
|
330
338
|
```python
|
|
339
|
+
# user_pool: cognito.UserPool
|
|
340
|
+
# user_pool_client: cognito.UserPoolClient
|
|
341
|
+
# another_user_pool_client: cognito.UserPoolClient
|
|
342
|
+
|
|
343
|
+
|
|
331
344
|
repository = ecr.Repository(self, "TestRepository",
|
|
332
345
|
repository_name="test-agent-runtime"
|
|
333
346
|
)
|
|
@@ -336,7 +349,7 @@ agent_runtime_artifact = agentcore.AgentRuntimeArtifact.from_ecr_repository(repo
|
|
|
336
349
|
runtime = agentcore.Runtime(self, "MyAgentRuntime",
|
|
337
350
|
runtime_name="myAgent",
|
|
338
351
|
agent_runtime_artifact=agent_runtime_artifact,
|
|
339
|
-
authorizer_configuration=agentcore.RuntimeAuthorizerConfiguration.using_cognito(
|
|
352
|
+
authorizer_configuration=agentcore.RuntimeAuthorizerConfiguration.using_cognito(user_pool, [user_pool_client, another_user_pool_client])
|
|
340
353
|
)
|
|
341
354
|
```
|
|
342
355
|
|
|
@@ -808,3 +821,311 @@ code_interpreter = agentcore.CodeInterpreterCustom(self, "MyCodeInterpreter",
|
|
|
808
821
|
}
|
|
809
822
|
)
|
|
810
823
|
```
|
|
824
|
+
|
|
825
|
+
## Memory
|
|
826
|
+
|
|
827
|
+
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.
|
|
828
|
+
|
|
829
|
+
AgentCore Memory operates on two levels:
|
|
830
|
+
|
|
831
|
+
* **Short-Term Memory**: Immediate conversation context and session-based information that provides continuity within a single interaction or closely related sessions.
|
|
832
|
+
* **Long-Term Memory**: Persistent information extracted and stored across multiple conversations, including facts, preferences, and summaries that enable personalized experiences over time.
|
|
833
|
+
|
|
834
|
+
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.
|
|
835
|
+
|
|
836
|
+
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.
|
|
837
|
+
|
|
838
|
+
### Memory Properties
|
|
839
|
+
|
|
840
|
+
| Name | Type | Required | Description |
|
|
841
|
+
|------|------|----------|-------------|
|
|
842
|
+
| `memoryName` | `string` | Yes | The name of the memory |
|
|
843
|
+
| `expirationDuration` | `Duration` | No | Short-term memory expiration in days (between 7 and 365). Default: 90 days |
|
|
844
|
+
| `description` | `string` | No | Optional description for the memory. Default: no description. |
|
|
845
|
+
| `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 |
|
|
846
|
+
| `memoryStrategies` | `MemoryStrategyBase[]` | No | Built-in extraction strategies to use for this memory. Default: No extraction strategies (short term memory only) |
|
|
847
|
+
| `executionRole` | `iam.IRole` | No | The IAM role that provides permissions for the memory to access AWS services. Default: A new role will be created. |
|
|
848
|
+
| `tags` | `{ [key: string]: string }` | No | Tags for memory. Default: no tags. |
|
|
849
|
+
|
|
850
|
+
### Basic Memory Creation
|
|
851
|
+
|
|
852
|
+
Below you can find how to configure a simple short-term memory (STM) with no long-term memory extraction strategies.
|
|
853
|
+
Note how you set `expirationDuration`, which defines the time the events will be stored in the short-term memory before they expire.
|
|
854
|
+
|
|
855
|
+
```python
|
|
856
|
+
# Create a basic memory with default settings, no LTM strategies
|
|
857
|
+
memory = agentcore.Memory(self, "MyMemory",
|
|
858
|
+
memory_name="my_memory",
|
|
859
|
+
description="A memory for storing user interactions for a period of 90 days",
|
|
860
|
+
expiration_duration=cdk.Duration.days(90)
|
|
861
|
+
)
|
|
862
|
+
```
|
|
863
|
+
|
|
864
|
+
Basic Memory with Custom KMS Encryption
|
|
865
|
+
|
|
866
|
+
```python
|
|
867
|
+
# Create a custom KMS key for encryption
|
|
868
|
+
encryption_key = kms.Key(self, "MemoryEncryptionKey",
|
|
869
|
+
enable_key_rotation=True,
|
|
870
|
+
description="KMS key for memory encryption"
|
|
871
|
+
)
|
|
872
|
+
|
|
873
|
+
# Create memory with custom encryption
|
|
874
|
+
memory = agentcore.Memory(self, "MyMemory",
|
|
875
|
+
memory_name="my_encrypted_memory",
|
|
876
|
+
description="Memory with custom KMS encryption",
|
|
877
|
+
expiration_duration=cdk.Duration.days(90),
|
|
878
|
+
kms_key=encryption_key
|
|
879
|
+
)
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
### LTM Memory Extraction Stategies
|
|
883
|
+
|
|
884
|
+
If you need long-term memory for context recall across sessions, you can setup memory extraction strategies
|
|
885
|
+
to extract the relevant memory from the raw events.
|
|
886
|
+
|
|
887
|
+
Amazon Bedrock AgentCore Memory has different memory strategies for extracting and organizing information:
|
|
888
|
+
|
|
889
|
+
* **Summarization**: to summarize interactions to preserve critical context and key insights.
|
|
890
|
+
* **Semantic Memory**: to extract general factual knowledge, concepts and meanings from raw conversations using vector embeddings.
|
|
891
|
+
This enables similarity-based retrieval of relevant facts and context.
|
|
892
|
+
* **User Preferences**: to extract user behavior patterns from raw conversations.
|
|
893
|
+
|
|
894
|
+
You can use built-in extraction strategies for quick setup, or create custom extraction strategies with specific models and prompt templates.
|
|
895
|
+
|
|
896
|
+
### Memory with Built-in Strategies
|
|
897
|
+
|
|
898
|
+
The library provides three built-in LTM strategies. These are default strategies for organizing and extracting memory data,
|
|
899
|
+
each optimized for specific use cases.
|
|
900
|
+
|
|
901
|
+
For example: An agent helps multiple users with cloud storage setup. From these conversations,
|
|
902
|
+
see how each strategy processes users expressing confusion about account connection:
|
|
903
|
+
|
|
904
|
+
1. **Summarization Strategy** (`MemoryStrategy.usingBuiltInSummarization()`)
|
|
905
|
+
This strategy compresses conversations into concise overviews, preserving essential context and key insights for quick recall.
|
|
906
|
+
Extracted memory example: Users confused by cloud setup during onboarding.
|
|
907
|
+
|
|
908
|
+
* Extracts concise summaries to preserve critical context and key insights
|
|
909
|
+
* Namespace: `/strategies/{memoryStrategyId}/actors/{actorId}/sessions/{sessionId}`
|
|
910
|
+
2. **Semantic Memory Strategy** (`MemoryStrategy.usingBuiltInSemantic()`)
|
|
911
|
+
Distills general facts, concepts, and underlying meanings from raw conversational data, presenting the information in a context-independent format.
|
|
912
|
+
Extracted memory example: In-context learning = task-solving via examples, no training needed.
|
|
913
|
+
|
|
914
|
+
* Extracts general factual knowledge, concepts and meanings from raw conversations
|
|
915
|
+
* Namespace: `/strategies/{memoryStrategyId}/actors/{actorId}`
|
|
916
|
+
3. **User Preference Strategy** (`MemoryStrategy.usingBuiltInUserPreference()`)
|
|
917
|
+
Captures individual preferences, interaction patterns, and personalized settings to enhance future experiences.
|
|
918
|
+
Extracted memory example: User needs clear guidance on cloud storage account connection during onboarding.
|
|
919
|
+
|
|
920
|
+
* Extracts user behavior patterns from raw conversations
|
|
921
|
+
* Namespace: `/strategies/{memoryStrategyId}/actors/{actorId}`
|
|
922
|
+
|
|
923
|
+
```python
|
|
924
|
+
# Create memory with built-in strategies
|
|
925
|
+
memory = agentcore.Memory(self, "MyMemory",
|
|
926
|
+
memory_name="my_memory",
|
|
927
|
+
description="Memory with built-in strategies",
|
|
928
|
+
expiration_duration=cdk.Duration.days(90),
|
|
929
|
+
memory_strategies=[
|
|
930
|
+
agentcore.MemoryStrategy.using_built_in_summarization(),
|
|
931
|
+
agentcore.MemoryStrategy.using_built_in_semantic(),
|
|
932
|
+
agentcore.MemoryStrategy.using_built_in_user_preference()
|
|
933
|
+
]
|
|
934
|
+
)
|
|
935
|
+
```
|
|
936
|
+
|
|
937
|
+
The name generated for each built in memory strategy is as follows:
|
|
938
|
+
|
|
939
|
+
* For Summarization: `summary_builtin_cdk001`
|
|
940
|
+
* For Semantic:`semantic_builtin_cdk001>`
|
|
941
|
+
* For User Preferences: `preference_builtin_cdk001`
|
|
942
|
+
|
|
943
|
+
### Memory with custom Strategies
|
|
944
|
+
|
|
945
|
+
With Long-Term Memory, organization is managed through Namespaces.
|
|
946
|
+
|
|
947
|
+
An `actor` refers to entity such as end users or agent/user combinations. For example, in a coding support chatbot,
|
|
948
|
+
the actor is usually the developer asking questions. Using the actor ID helps the system know which user the memory belongs to,
|
|
949
|
+
keeping each user's data separate and organized.
|
|
950
|
+
|
|
951
|
+
A `session` is usually a single conversation or interaction period between the user and the AI agent.
|
|
952
|
+
It groups all related messages and events that happen during that conversation.
|
|
953
|
+
|
|
954
|
+
A `namespace` is used to logically group and organize long-term memories. It ensures data stays neat, separate, and secure.
|
|
955
|
+
|
|
956
|
+
With AgentCore Memory, you need to add a namespace when you define a memory strategy. This namespace helps define where the long-term memory
|
|
957
|
+
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.
|
|
958
|
+
This means that all long-term memories are scoped to their specific namespace, keeping them organized and preventing any mix-ups with other
|
|
959
|
+
users or sessions. You should use a hierarchical format separated by forward slashes /. This helps keep memories organized clearly. As needed,
|
|
960
|
+
you can choose to use the below pre-defined variables within braces in the namespace based on your applications' organization needs:
|
|
961
|
+
|
|
962
|
+
* `actorId` – Identifies who the long-term memory belongs to, such as a user
|
|
963
|
+
* `memoryStrategyId` – Shows which memory strategy is being used. This strategy identifier is auto-generated when you create a memory using CreateMemory operation.
|
|
964
|
+
* `sessionId` – Identifies which session or conversation the memory is from.
|
|
965
|
+
|
|
966
|
+
For example, if you define the following namespace as the input to your strategy in CreateMemory operation:
|
|
967
|
+
|
|
968
|
+
```shell
|
|
969
|
+
/strategy/{memoryStrategyId}/actor/{actorId}/session/{sessionId}
|
|
970
|
+
```
|
|
971
|
+
|
|
972
|
+
After memory creation, this namespace might look like:
|
|
973
|
+
|
|
974
|
+
```shell
|
|
975
|
+
/strategy/summarization-93483043//actor/actor-9830m2w3/session/session-9330sds8
|
|
976
|
+
```
|
|
977
|
+
|
|
978
|
+
You can customise the namespace, i.e. where the memories are stored by using the following methods:
|
|
979
|
+
|
|
980
|
+
1. **Summarization Strategy** (`MemoryStrategy.usingSummarization(props)`)
|
|
981
|
+
2. **Semantic Memory Strategy** (`MemoryStrategy.usingSemantic(props)`)
|
|
982
|
+
3. **User Preference Strategy** (`MemoryStrategy.usingUserPreference(props)`)
|
|
983
|
+
|
|
984
|
+
```python
|
|
985
|
+
# Create memory with built-in strategies
|
|
986
|
+
memory = agentcore.Memory(self, "MyMemory",
|
|
987
|
+
memory_name="my_memory",
|
|
988
|
+
description="Memory with built-in strategies",
|
|
989
|
+
expiration_duration=cdk.Duration.days(90),
|
|
990
|
+
memory_strategies=[
|
|
991
|
+
agentcore.MemoryStrategy.using_user_preference(
|
|
992
|
+
name="CustomerPreferences",
|
|
993
|
+
namespaces=["support/customer/{actorId}/preferences"]
|
|
994
|
+
),
|
|
995
|
+
agentcore.MemoryStrategy.using_semantic(
|
|
996
|
+
name="CustomerSupportSemantic",
|
|
997
|
+
namespaces=["support/customer/{actorId}/semantic"]
|
|
998
|
+
)
|
|
999
|
+
]
|
|
1000
|
+
)
|
|
1001
|
+
```
|
|
1002
|
+
|
|
1003
|
+
Custom memory strategies let you tailor memory extraction and consolidation to your specific domain or use case.
|
|
1004
|
+
You can override the prompts for extracting and consolidating semantic, summary, or user preferences.
|
|
1005
|
+
You can also choose the model that you want to use for extraction and consolidation.
|
|
1006
|
+
|
|
1007
|
+
The custom prompts you create are appended to a non-editable system prompt.
|
|
1008
|
+
|
|
1009
|
+
Since a custom strategy requires you to invoke certain FMs, you need a role with appropriate permissions. For that, you can:
|
|
1010
|
+
|
|
1011
|
+
* Let the L2 construct create a minimum permission role for you when use L2 Bedrock Foundation Models.
|
|
1012
|
+
* Use a custom role with the overly permissive `AmazonBedrockAgentCoreMemoryBedrockModelInferenceExecutionRolePolicy` managed policy.
|
|
1013
|
+
* Use a custom role with your own custom policies.
|
|
1014
|
+
|
|
1015
|
+
#### Memory with Custom Execution Role
|
|
1016
|
+
|
|
1017
|
+
Keep in mind that memories that **do not** use custom strategies do not require a service role.
|
|
1018
|
+
So even if you provide it, it will be ignored as it will never be used.
|
|
1019
|
+
|
|
1020
|
+
```python
|
|
1021
|
+
# Create a custom execution role
|
|
1022
|
+
execution_role = iam.Role(self, "MemoryExecutionRole",
|
|
1023
|
+
assumed_by=iam.ServicePrincipal("bedrock-agentcore.amazonaws.com"),
|
|
1024
|
+
managed_policies=[
|
|
1025
|
+
iam.ManagedPolicy.from_aws_managed_policy_name("AmazonBedrockAgentCoreMemoryBedrockModelInferenceExecutionRolePolicy")
|
|
1026
|
+
]
|
|
1027
|
+
)
|
|
1028
|
+
|
|
1029
|
+
# Create memory with custom execution role
|
|
1030
|
+
memory = agentcore.Memory(self, "MyMemory",
|
|
1031
|
+
memory_name="my_memory",
|
|
1032
|
+
description="Memory with custom execution role",
|
|
1033
|
+
expiration_duration=cdk.Duration.days(90),
|
|
1034
|
+
execution_role=execution_role
|
|
1035
|
+
)
|
|
1036
|
+
```
|
|
1037
|
+
|
|
1038
|
+
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.
|
|
1039
|
+
|
|
1040
|
+
```python
|
|
1041
|
+
# Create a custom semantic memory strategy
|
|
1042
|
+
custom_semantic_strategy = agentcore.MemoryStrategy.using_semantic(
|
|
1043
|
+
name="customSemanticStrategy",
|
|
1044
|
+
description="Custom semantic memory strategy",
|
|
1045
|
+
namespaces=["/custom/strategies/{memoryStrategyId}/actors/{actorId}"],
|
|
1046
|
+
custom_consolidation=agentcore.OverrideConfig(
|
|
1047
|
+
model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
|
|
1048
|
+
append_to_prompt="Custom consolidation prompt for semantic memory"
|
|
1049
|
+
),
|
|
1050
|
+
custom_extraction=agentcore.OverrideConfig(
|
|
1051
|
+
model=bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0,
|
|
1052
|
+
append_to_prompt="Custom extraction prompt for semantic memory"
|
|
1053
|
+
)
|
|
1054
|
+
)
|
|
1055
|
+
|
|
1056
|
+
# Create memory with custom strategy
|
|
1057
|
+
memory = agentcore.Memory(self, "MyMemory",
|
|
1058
|
+
memory_name="my-custom-memory",
|
|
1059
|
+
description="Memory with custom strategy",
|
|
1060
|
+
expiration_duration=cdk.Duration.days(90),
|
|
1061
|
+
memory_strategies=[custom_semantic_strategy]
|
|
1062
|
+
)
|
|
1063
|
+
```
|
|
1064
|
+
|
|
1065
|
+
### Memory with self-managed Strategies
|
|
1066
|
+
|
|
1067
|
+
A self-managed strategy in Amazon Bedrock AgentCore Memory gives you complete control over your memory extraction and consolidation pipelines.
|
|
1068
|
+
With a self-managed strategy, you can build custom memory processing workflows while leveraging Amazon Bedrock AgentCore for storage and retrieval.
|
|
1069
|
+
|
|
1070
|
+
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).
|
|
1071
|
+
|
|
1072
|
+
Create the required AWS resources including:
|
|
1073
|
+
|
|
1074
|
+
* an S3 bucket in your account where Amazon Bedrock AgentCore will deliver batched event payloads.
|
|
1075
|
+
* an SNS topic for job notifications. Use FIFO topics if processing order within sessions is important for your use case.
|
|
1076
|
+
|
|
1077
|
+
The construct will apply the correct permissions to the memory execution role to access these resources.
|
|
1078
|
+
|
|
1079
|
+
```python
|
|
1080
|
+
bucket = s3.Bucket(self, "memoryBucket",
|
|
1081
|
+
bucket_name="test-memory",
|
|
1082
|
+
removal_policy=cdk.RemovalPolicy.DESTROY,
|
|
1083
|
+
auto_delete_objects=True
|
|
1084
|
+
)
|
|
1085
|
+
|
|
1086
|
+
topic = sns.Topic(self, "topic")
|
|
1087
|
+
|
|
1088
|
+
# Create a custom semantic memory strategy
|
|
1089
|
+
self_managed_strategy = agentcore.MemoryStrategy.using_self_managed(
|
|
1090
|
+
name="selfManagedStrategy",
|
|
1091
|
+
description="self managed memory strategy",
|
|
1092
|
+
historical_context_window_size=5,
|
|
1093
|
+
invocation_configuration=agentcore.InvocationConfiguration(
|
|
1094
|
+
topic=topic,
|
|
1095
|
+
s3_location=s3.Location(
|
|
1096
|
+
bucket_name=bucket.bucket_name,
|
|
1097
|
+
object_key="memory/"
|
|
1098
|
+
)
|
|
1099
|
+
),
|
|
1100
|
+
trigger_conditions=agentcore.TriggerConditions(
|
|
1101
|
+
message_based_trigger=1,
|
|
1102
|
+
time_based_trigger=cdk.Duration.seconds(10),
|
|
1103
|
+
token_based_trigger=100
|
|
1104
|
+
)
|
|
1105
|
+
)
|
|
1106
|
+
|
|
1107
|
+
# Create memory with custom strategy
|
|
1108
|
+
memory = agentcore.Memory(self, "MyMemory",
|
|
1109
|
+
memory_name="my-custom-memory",
|
|
1110
|
+
description="Memory with custom strategy",
|
|
1111
|
+
expiration_duration=cdk.Duration.days(90),
|
|
1112
|
+
memory_strategies=[self_managed_strategy]
|
|
1113
|
+
)
|
|
1114
|
+
```
|
|
1115
|
+
|
|
1116
|
+
### Memory Strategy Methods
|
|
1117
|
+
|
|
1118
|
+
You can add new memory strategies to the memory construct using the `addMemoryStrategy()` method, for instance:
|
|
1119
|
+
|
|
1120
|
+
```python
|
|
1121
|
+
# Create memory without initial strategies
|
|
1122
|
+
memory = agentcore.Memory(self, "test-memory",
|
|
1123
|
+
memory_name="test_memory_add_strategy",
|
|
1124
|
+
description="A test memory for testing addMemoryStrategy method",
|
|
1125
|
+
expiration_duration=cdk.Duration.days(90)
|
|
1126
|
+
)
|
|
1127
|
+
|
|
1128
|
+
# Add strategies after instantiation
|
|
1129
|
+
memory.add_memory_strategy(agentcore.MemoryStrategy.using_built_in_summarization())
|
|
1130
|
+
memory.add_memory_strategy(agentcore.MemoryStrategy.using_built_in_semantic())
|
|
1131
|
+
```
|