-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathquickstart.py
More file actions
235 lines (200 loc) · 9.43 KB
/
quickstart.py
File metadata and controls
235 lines (200 loc) · 9.43 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
"""Empathy Framework - Quickstart Example
A simple demonstration of the Empathy Framework showing:
- Initializing EmpathyOS
- Progressing through empathy levels 1-5
- Using systems thinking components
- Pattern detection and sharing
Copyright 2025 Deep Study AI, LLC
Licensed under Fair Source 0.9
"""
from empathy_os import (EmpathyFrameworkError, EmpathyOS, FeedbackLoopDetector,
Level1Reactive, Level2Guided, Level3Proactive,
Level4Anticipatory, Level5Systems, Pattern,
PatternLibrary, ValidationError)
def main():
"""Run quickstart demonstration"""
try:
print("=" * 60)
print("Empathy Framework - Quickstart Example")
print("=" * 60)
# ========================================
# Part 1: Initialize EmpathyOS
# ========================================
print("\n[Part 1] Initializing EmpathyOS")
print("-" * 60)
empathy = EmpathyOS(user_id="quickstart_user", target_level=4, confidence_threshold=0.75)
print("✓ Created EmpathyOS instance")
print(f" - User ID: {empathy.user_id}")
print(f" - Target Level: {empathy.target_level}")
print(f" - Initial Trust: {empathy.collaboration_state.trust_level:.2f}")
# ========================================
# Part 2: Demonstrate Five Empathy Levels
# ========================================
print("\n[Part 2] Demonstrating Five Empathy Levels")
print("-" * 60)
# Level 1: Reactive
print("\nLevel 1: Reactive Empathy (Help after being asked)")
level1 = Level1Reactive()
response1 = level1.respond({"request": "status", "subject": "project"})
print(f" Action: {response1['action']}")
print(f" Initiative: {response1['initiative']}")
print(f" Description: {response1['description']}")
# Level 2: Guided
print("\nLevel 2: Guided Empathy (Collaborative exploration)")
level2 = Level2Guided()
response2 = level2.respond({"request": "improve system", "ambiguity": "high"})
print(f" Action: {response2['action']}")
print(f" Initiative: {response2['initiative']}")
print(f" Questions: {len(response2['clarifying_questions'])} clarifying questions")
# Level 3: Proactive
print("\nLevel 3: Proactive Empathy (Act before being asked)")
level3 = Level3Proactive()
response3 = level3.respond({"observed_need": "failing_tests", "confidence": 0.9})
print(f" Action: {response3['action']}")
print(f" Initiative: {response3['initiative']}")
print(f" Confidence: {response3['confidence']:.2f}")
# Level 4: Anticipatory
print("\nLevel 4: Anticipatory Empathy (Predict future needs)")
level4 = Level4Anticipatory()
response4 = level4.respond(
{
"current_state": {"compliance": 0.7},
"trajectory": "declining",
"prediction_horizon": "30_days",
},
)
print(f" Action: {response4['action']}")
print(f" Initiative: {response4['initiative']}")
print(f" Predicted Needs: {len(response4['predicted_needs'])}")
for i, need in enumerate(response4["predicted_needs"], 1):
print(f" {i}. {need}")
# Level 5: Systems
print("\nLevel 5: Systems Empathy (Build structures at scale)")
level5 = Level5Systems()
response5 = level5.respond(
{
"problem_class": "documentation_burden",
"instances": 18,
"pattern": "repetitive_structure",
},
)
print(f" Action: {response5['action']}")
print(f" Initiative: {response5['initiative']}")
print(f" System Created: {response5['system_created']['name']}")
print(f" Leverage Point: {response5['leverage_point']}")
# ========================================
# Part 3: Pattern Library (Level 5)
# ========================================
print("\n[Part 3] Pattern Library - AI-AI Cooperation")
print("-" * 60)
library = PatternLibrary()
# Agent 1 contributes a pattern
print("\nAgent 1: Contributing pattern to library")
pattern1 = Pattern(
id="pat_001",
agent_id="agent_1",
pattern_type="sequential",
name="Post-deployment documentation",
description="After deployments, users need help finding changed features",
confidence=0.85,
tags=["deployment", "documentation"],
)
library.contribute_pattern("agent_1", pattern1)
print(f" ✓ Pattern '{pattern1.name}' contributed")
print(f" Confidence: {pattern1.confidence:.2f}")
# Agent 2 queries for relevant patterns
print("\nAgent 2: Querying library for deployment-related patterns")
context = {"recent_event": "deployment", "user_confusion": True, "tags": ["deployment"]}
matches = library.query_patterns("agent_2", context, min_confidence=0.7)
print(f" ✓ Found {len(matches)} relevant patterns")
if matches:
match = matches[0]
print(f" Pattern: {match.pattern.name}")
print(f" Relevance: {match.relevance_score:.2f}")
print(f" Matching Factors: {', '.join(match.matching_factors)}")
# Record pattern usage
print("\nAgent 2: Using pattern and recording outcome")
library.record_pattern_outcome("pat_001", success=True)
pattern1_updated = library.get_pattern("pat_001")
print(" ✓ Pattern usage recorded")
print(f" Usage count: {pattern1_updated.usage_count}")
print(f" Success rate: {pattern1_updated.success_rate:.2f}")
# Library stats
stats = library.get_library_stats()
print("\nLibrary Statistics:")
print(f" Total patterns: {stats['total_patterns']}")
print(f" Total agents: {stats['total_agents']}")
print(f" Average confidence: {stats['average_confidence']:.2f}")
# ========================================
# Part 4: Feedback Loops
# ========================================
print("\n[Part 4] Feedback Loop Detection")
print("-" * 60)
detector = FeedbackLoopDetector()
# Simulate a virtuous cycle (trust building)
print("\nDetecting feedback loops in collaboration history:")
history = [
{"trust": 0.5, "success": True},
{"trust": 0.6, "success": True},
{"trust": 0.7, "success": True},
{"trust": 0.8, "success": True},
]
result = detector.detect_active_loop(history)
print(f" Dominant Loop: {result['dominant_loop']}")
print(f" Loop Type: {result['loop_type']}")
print(f" Trend: {result['trend']}")
print(f" Recommendation: {result['recommendation']}")
is_virtuous = detector.detect_virtuous_cycle(history)
print(f"\n Virtuous Cycle Detected: {is_virtuous}")
# ========================================
# Part 5: Trust Tracking
# ========================================
print("\n[Part 5] Trust Tracking Over Time")
print("-" * 60)
print("\nSimulating collaboration sessions:")
print(f" Initial trust: {empathy.collaboration_state.trust_level:.2f}")
# Successful interactions
for i in range(3):
empathy.collaboration_state.update_trust("success")
print(f" After success {i + 1}: {empathy.collaboration_state.trust_level:.2f}")
print(f"\n Final trust level: {empathy.collaboration_state.trust_level:.2f}")
print(f" Successful interventions: {empathy.collaboration_state.successful_interventions}")
print(f" Total interactions: {empathy.collaboration_state.total_interactions}")
# ========================================
# Summary
# ========================================
print("\n" + "=" * 60)
print("Quickstart Complete!")
print("=" * 60)
print("\nYou've learned:")
print(" ✓ How to initialize EmpathyOS")
print(" ✓ The five empathy levels (1-5)")
print(" ✓ Pattern library for AI-AI cooperation")
print(" ✓ Feedback loop detection")
print(" ✓ Trust tracking")
print("\nNext Steps:")
print(" - Explore individual modules in more detail")
print(" - Build custom agents using the framework")
print(" - Integrate with your AI applications")
print(" - Contribute patterns to the library")
print("\nDocumentation: https://github.com/Deep-Study-AI/Empathy")
print("=" * 60)
except ValidationError as e:
print(f"\n❌ Validation Error: {e}")
print("Please check your input parameters and try again.")
return 1
except EmpathyFrameworkError as e:
print(f"\n❌ Empathy Framework Error: {type(e).__name__}: {e}")
print("Check the error message above for details.")
return 1
except KeyError as e:
print(f"\n❌ Missing Required Field: {e}")
print("Check that all required fields are present in the data.")
return 1
except Exception as e:
print(f"\n❌ Unexpected Error: {type(e).__name__}: {e}")
print("Please check the documentation or file an issue.")
return 1
return 0
if __name__ == "__main__":
exit(main())