-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_seed_memory.py
More file actions
92 lines (75 loc) · 3.44 KB
/
Copy path04_seed_memory.py
File metadata and controls
92 lines (75 loc) · 3.44 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
"""
Script to seed AgentCore Memory with sample customer conversations.
This script adds sample conversations to demonstrate memory capabilities:
- Conversation 1: Customer mentions email preference and defective laptop return
- Conversation 2: Customer asks about return windows for electronics
"""
import json
import time
try:
from bedrock_agentcore.memory import MemoryClient
except ImportError:
print("✗ Error: bedrock_agentcore package not found")
print(" Install with: pip install bedrock-agentcore")
exit(1)
# Load memory_id from config
with open('memory_config.json') as f:
config = json.load(f)
memory_id = config['memory_id']
print(f"Using Memory ID: {memory_id}")
print(f"Customer ID: user_001")
print(f"Region: us-west-2\n")
# Create memory client
memory_client = MemoryClient(region_name='us-west-2')
# Conversation 1: Email preference and defective laptop return
print("=" * 60)
print("Storing Conversation 1: Email preference + laptop return")
print("=" * 60)
messages_1 = [
("Hi, I wanted to let you know that I prefer to receive notifications via email rather than SMS.", "USER"),
("Thank you for letting me know! I've noted your preference for email notifications. Is there anything else I can help you with today?", "ASSISTANT"),
("Yes, I recently returned a laptop that was defective. Just wanted to make sure that's being processed.", "USER"),
("I can help you with that. Let me check on your return status. The defective laptop return is being processed and you should receive your refund within 5-7 business days.", "ASSISTANT")
]
memory_client.create_event(
memory_id=memory_id,
actor_id="user_001",
session_id="session_001",
messages=messages_1
)
print(f"✓ Stored {len(messages_1)} messages from conversation 1")
# Conversation 2: Return windows for electronics
print("\n" + "=" * 60)
print("Storing Conversation 2: Return window inquiry")
print("=" * 60)
messages_2 = [
("Hi, I have a question about your return policy. What's the return window for electronics?", "USER"),
("Great question! For electronics, we offer a 30-day return window from the date of purchase. The item must be in its original packaging with all accessories included.", "ASSISTANT"),
("That's helpful, thank you! And does that apply to all electronics or are there exceptions?", "USER"),
("The 30-day window applies to most electronics. However, opened software and digital downloads are non-returnable. Also, custom-built computers have a 14-day window instead of 30 days.", "ASSISTANT")
]
memory_client.create_event(
memory_id=memory_id,
actor_id="user_001",
session_id="session_002",
messages=messages_2
)
print(f"✓ Stored {len(messages_2)} messages from conversation 2")
# Wait for memory processing
print("\n" + "=" * 60)
print("Waiting for memory processing...")
print("=" * 60)
print("Note: Memory processing takes 20-30 seconds to:")
print(" - Extract user preferences (email notifications)")
print(" - Store semantic facts (defective laptop return)")
print(" - Generate conversation summaries")
print("\nWaiting 30 seconds...")
time.sleep(30)
print("\n✓ Memory seeding complete!")
print(f"\nSummary:")
print(f" - Customer: user_001")
print(f" - Conversations stored: 2")
print(f" - Total messages: {len(messages_1) + len(messages_2)}")
print(f" - Expected preferences: Email notifications")
print(f" - Expected facts: Defective laptop return, return policy questions")