-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_session.py
More file actions
93 lines (79 loc) · 3.31 KB
/
multi_session.py
File metadata and controls
93 lines (79 loc) · 3.31 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
93
"""
Multi-session example: Simulate an agent running over multiple days.
Shows how dream-memory consolidates knowledge across sessions,
getting sharper over time.
"""
import json
import time
from dream_memory import DreamEngine, DreamConfig
from dream_memory.store.sqlite_store import SQLiteStore
from dream_memory.llm import CallableLLM
# Simulate a smarter LLM that actually reads the context
call_count = 0
def simulated_llm(prompt: str, max_tokens: int = 2000) -> str:
global call_count
call_count += 1
if "analyzing" in prompt:
# Orient: detect redundancy if we have duplicate-ish memories
redundant = []
if "Python" in prompt and "python" in prompt.lower():
redundant = [["m1", "m2"]] # Hypothetical overlap
return json.dumps({
"stale_topics": [],
"redundant_groups": [],
"new_signals": ["New deployment workflow learned"],
"contradictions": [],
"health_score": 0.85,
})
elif "extracting" in prompt:
return json.dumps({
"memories": [
{"content": "Agent learned Docker deployment workflow", "topic": "devops", "priority": 3},
{"content": "Production uses PostgreSQL 16", "topic": "infrastructure", "priority": 2},
]
})
elif "pruning" in prompt:
return json.dumps({"decisions": []})
return json.dumps({"merged": [], "updated": []})
# Configure for frequent dreaming (demo purposes)
config = DreamConfig(
min_sessions_between_dreams=2,
min_hours_between_dreams=0, # No cooldown for demo
max_total_memories=50,
)
store = SQLiteStore("./multi_demo.db", config=config)
engine = DreamEngine(store, llm=CallableLLM(simulated_llm), config=config)
# Day 1: Initial sessions
print("=== Day 1 ===")
engine.add_memory("Project uses Python 3.12", topic="stack", priority=3)
engine.add_memory("Team lead is Sarah", topic="team", priority=4)
engine.log_session("Set up development environment. Installed Python 3.12, Docker, and PostgreSQL.")
engine.log_session("First code review. Team uses black formatter and pytest.")
result = engine.dream()
print(f" Dream 1: {result.memories_before} -> {result.memories_after} memories")
# Day 2: More sessions
print("\n=== Day 2 ===")
engine.log_session("Deployed to staging. Used Docker Compose for orchestration.")
engine.log_session("Production incident: DB connection pool exhausted. Fixed by increasing max_connections.")
result = engine.dream()
print(f" Dream 2: {result.memories_before} -> {result.memories_after} memories")
# Day 3: Even more
print("\n=== Day 3 ===")
engine.log_session("Implemented caching layer with Redis.")
engine.log_session("Code review feedback: prefer composition over inheritance.")
result = engine.dream()
print(f" Dream 3: {result.memories_before} -> {result.memories_after} memories")
# Check final state
print("\n=== Final State ===")
status = engine.status()
print(f" Total memories: {status['total_memories']}")
print(f" Topics: {', '.join(status['topics'])}")
print(f" Dreams completed: {status['dream_count']}")
print(f" LLM calls made: {call_count}")
print("\nAll memories:")
for mem in store.list_memories():
print(f" [{mem.priority.name:<9}] ({mem.topic}) {mem.content}")
# Cleanup
import os, glob
for f in glob.glob("./multi_demo.db*"):
os.remove(f)