Repository navigation
Expand file tree
/
Copy pathbasic_usage.py
More file actions
49 lines (39 loc) · 1.51 KB
/
Copy pathbasic_usage.py
File metadata and controls
49 lines (39 loc) · 1.51 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
"""Basic SDK usage example."""
from agent_memory import Memory, MemoryAction, MemoryType
def main() -> None:
memory = Memory(persist_dir=".agent_memory_demo")
memory.remember(
query="How do I reset my password?",
response="Go to Settings → Security → Reset Password and follow the email link.",
type=MemoryType.CONVERSATION,
tags=["auth", "faq"],
)
memory.remember(
query="Current API rate limit",
response="1000 requests/minute per API key.",
type=MemoryType.FACT,
requires_verification=True,
)
queries = [
"How do I reset my password?",
"Give me a one-sentence explanation of password reset",
"What is the API rate limit?",
"What's the weather today?",
]
for query in queries:
decision = memory.resolve(query)
print(f"\nQuery: {query}")
print(f"Action: {decision.action.value} (confidence: {decision.confidence:.2f})")
print(f"Reason: {decision.reason}")
if decision.action == MemoryAction.REPLAY:
print(f"→ Replay: {decision.response}")
elif decision.action == MemoryAction.RESTORE:
print("→ Restore context:")
print(memory.format_restore_context(decision))
elif decision.action == MemoryAction.VERIFY:
print("→ Verify before reuse:")
print(memory.format_verify_context(decision))
else:
print("→ Answer from scratch")
if __name__ == "__main__":
main()