-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
244 lines (174 loc) · 6.95 KB
/
Copy pathexample.py
File metadata and controls
244 lines (174 loc) · 6.95 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
"""Usage examples for VIGIL Stones — THE ARC, TideStone, CompassStone, EmberStone, MirrorStone.
These examples show how to integrate each stone into an AI assistant.
All stones are standalone and zero-dependency — use any combination.
"""
from __future__ import annotations
import time
# ── THE ARC ──────────────────────────────────────────────────────────────
print("=" * 60)
print("THE ARC — Long-Term Narrative Tracker")
print("=" * 60)
from the_arc import TheArc, TurnRecord
arc = TheArc(path=".the_arc.json")
# After every conversation turn:
arc.absorb(TurnRecord(
turn_id=1,
role="user",
content="I'll use React Native for the mobile app",
timestamp=time.time(),
))
arc.absorb(TurnRecord(
turn_id=2,
role="assistant",
content="Great choice! React Native lets you...",
timestamp=time.time(),
))
arc.absorb(TurnRecord(
turn_id=3,
role="user",
content="Actually, I changed my mind — I'll use Flutter instead",
timestamp=time.time(),
))
# Before every LLM call:
context = arc.consult("Flutter")
if context:
print(f"THE ARC context: {context}")
# Get decision context
decisions = arc.get_decision_context("React Native")
print(f"Decisions: {decisions}")
# Statistics
stats = arc.get_stats()
print(f"Stats: {stats}")
# Run decay periodically (e.g., daily)
arc.run_decay()
print()
# ── TideStone ────────────────────────────────────────────────────────────
print("=" * 60)
print("TideStone — Real-Time User State")
print("=" * 60)
from tide_stone import TideStone
tide = TideStone()
# On every user message:
tide.observe_user("I need to learn async Python for my project")
tide.observe_user("Can you explain coroutines?")
tide.observe_user("Thanks")
# Get current state
state = tide.get_state()
if state:
print(f"Energy: {state.energy}, Pace: {state.pace}, Focus: {state.focus}, Turns: {state.turns}")
# Before responding:
directive = tide.get_state_directive()
if directive:
print(f"Tide directive: {directive}")
print()
# ── CompassStone ────────────────────────────────────────────────────────
print("=" * 60)
print("CompassStone — Goal Tracker")
print("=" * 60)
from compass_stone import CompassStone
compass = CompassStone(path=".compass_stone.json")
# After each turn:
compass.observe("I want to learn Python this month", "Great goal! Let's start with syntax")
compass.observe("I've been practicing for a week now", "Excellent progress!")
compass.observe("I finished the basics, moving to advanced topics", "")
# Before responding:
goal_directive = compass.get_goal_directive()
if goal_directive:
print(f"Goal directive: {goal_directive}")
# Active goals
active = compass.get_active_goals()
print(f"Active goals: {len(active)}")
print()
# ── EmberStone ───────────────────────────────────────────────────────────
print("=" * 60)
print("EmberStone — Recurring Topic Heat")
print("=" * 60)
from ember_stone import EmberStone
ember = EmberStone(path=".ember_stone.json")
# After each turn:
ember.observe("I'm working on Python async programming", "Async is powerful...")
ember.observe("Tell me more about async", "Here's how asyncio works...")
ember.observe("What about await?", "await suspends the coroutine...")
# Before responding:
ember_context = ember.get_active_context()
if ember_context:
print(f"Ember context: {ember_context}")
print()
# ── MirrorStone ─────────────────────────────────────────────────────────
print("=" * 60)
print("MirrorStone — Self-Confidence Tracker")
print("=" * 60)
from mirror_stone import MirrorStone
mirror = MirrorStone(path=".mirror_stone.json")
# After each assistant response:
mirror.observe(
"How does Python async work?",
"I think it uses an event loop... it might be based on coroutines... you probably should check the docs"
)
# Before responding:
conf = mirror.estimate_confidence("python async")
print(f"Python confidence: {conf.score} ({conf.flag})")
# Get directive if uncertain
if conf.flag in ("uncertain", "low_confidence"):
directive = mirror.get_mirror_directive("python async")
print(f"Mirror directive: {directive}")
print()
# ── Combined Usage ──────────────────────────────────────────────────────
print("=" * 60)
print("Combined — All VIGIL Stones Together")
print("=" * 60)
from the_arc import TheArc, TurnRecord
from tide_stone import TideStone
from compass_stone import CompassStone
from ember_stone import EmberStone
from mirror_stone import MirrorStone
arc = TheArc()
tide = TideStone()
compass = CompassStone()
ember = EmberStone()
mirror = MirrorStone()
def after_each_turn(user_msg: str, assistant_msg: str, turn_id: int):
"""Call after every conversation turn."""
timestamp = time.time()
# Track narrative
arc.absorb(TurnRecord(turn_id=turn_id, role="user", content=user_msg, timestamp=timestamp))
arc.absorb(TurnRecord(turn_id=turn_id + 1, role="assistant", content=assistant_msg, timestamp=timestamp))
# Track user state
tide.observe_user(user_msg)
# Track goals
compass.observe(user_msg, assistant_msg)
# Track hot topics
ember.observe(user_msg, assistant_msg)
# Track assistant confidence
mirror.observe(user_msg, assistant_msg)
def build_system_prompt(base_prompt: str, user_msg: str) -> str:
"""Build enhanced system prompt with all VIGIL context."""
additions = []
# THE ARC — narrative context
arc_ctx = arc.consult(user_msg)
if arc_ctx:
additions.append(arc_ctx)
# TideStone — user state
tide_directive = tide.get_state_directive()
if tide_directive:
additions.append(tide_directive)
# CompassStone — goals
goal_directive = compass.get_goal_directive()
if goal_directive:
additions.append(goal_directive)
# EmberStone — hot topics
ember_ctx = ember.get_active_context()
if ember_ctx:
additions.append(ember_ctx)
# MirrorStone — confidence
mirror_directive = mirror.get_mirror_directive(user_msg)
if mirror_directive:
additions.append(mirror_directive)
if additions:
return base_prompt + "\n\n" + "\n\n".join(additions)
return base_prompt
# Example usage
example_prompt = "You are a helpful AI assistant."
example_user = "I want to build a web app with Python"
enhanced = build_system_prompt(example_prompt, example_user)
print(f"Enhanced prompt:\n{enhanced}")