-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03_create_memory.py
More file actions
65 lines (56 loc) · 1.54 KB
/
Copy path03_create_memory.py
File metadata and controls
65 lines (56 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
"""
Script to create AgentCore Memory.
This script creates an AgentCore Memory resource with memory strategies.
"""
import json
from bedrock_agentcore_starter_toolkit.operations.memory.manager import MemoryManager
# Define memory strategies in boto3 tagged union format
strategies = [
{
"summaryMemoryStrategy": {
"name": "summary",
"namespaces": [
"app/{actorId}/{sessionId}/summary"
]
}
},
{
"userPreferenceMemoryStrategy": {
"name": "preferences",
"namespaces": [
"app/{actorId}/preferences"
]
}
},
{
"semanticMemoryStrategy": {
"name": "semantic",
"namespaces": [
"app/{actorId}/semantic"
]
}
}
]
# Create memory manager
memory_manager = MemoryManager(region_name='us-west-2')
# Create memory
print("Creating AgentCore Memory...")
memory = memory_manager.get_or_create_memory(
name="returns_refunds_memory",
description="Stores customer interactions, preferences, and return history",
strategies=strategies
)
# Extract memory_id
memory_id = memory["id"]
# Save memory_id to config file
config = {
"memory_id": memory_id,
"name": "returns_refunds_memory",
"region": "us-west-2"
}
with open('memory_config.json', 'w') as f:
json.dump(config, f, indent=2)
print(f"✓ Memory created successfully!")
print(f" Memory ID: {memory_id}")
print(f"✓ Configuration saved to memory_config.json")