-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.py
More file actions
61 lines (50 loc) · 2.04 KB
/
quickstart.py
File metadata and controls
61 lines (50 loc) · 2.04 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
"""
Quickstart: Get a dream engine running in 10 lines.
This example uses a simple callable as the LLM backend.
Replace it with OpenAIAdapter or AnthropicAdapter for real use.
"""
import json
from dream_memory import DreamEngine, MemoryStore, Memory
from dream_memory.llm import CallableLLM
# 1. Simple mock LLM (replace with real one)
def my_llm(prompt: str, max_tokens: int = 2000) -> str:
"""Fake LLM for demo purposes."""
if "analyzing" in prompt:
return json.dumps({
"stale_topics": [], "redundant_groups": [],
"new_signals": ["User prefers Python"], "contradictions": [],
"health_score": 0.8,
})
elif "extracting" in prompt:
return json.dumps({
"memories": [
{"content": "User prefers Python for data work", "topic": "preferences", "priority": 2},
]
})
elif "pruning" in prompt:
return json.dumps({"decisions": []})
return json.dumps({"merged": [], "updated": []})
# 2. Create store and engine
store = MemoryStore("./demo_memories")
engine = DreamEngine(store, llm=CallableLLM(my_llm))
# 3. Add some memories manually
engine.add_memory("User name is Alice", topic="identity", priority=4)
engine.add_memory("Timezone is PST", topic="preferences")
# 4. Log sessions (normally from your agent's conversations)
engine.log_session("User asked about pandas DataFrames and preferred Python solutions.")
engine.log_session("User set up a new ML pipeline. Discussed sklearn vs pytorch.")
engine.log_session("User mentioned they always use dark mode.")
# 5. Dream!
result = engine.dream()
# 6. Check results
print(f"Dream completed!")
print(f" Sessions processed: {result.sessions_processed}")
print(f" Memories: {result.memories_before} -> {result.memories_after}")
print(f" Added: {result.total_added}, Pruned: {result.total_pruned}")
print()
print("Current memories:")
for mem in store.list_memories():
print(f" [{mem.topic}] {mem.content}")
# Cleanup demo files
import shutil
shutil.rmtree("./demo_memories", ignore_errors=True)