empathy-framework 3.5.6__py3-none-any.whl → 3.7.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agents/compliance_anticipation_agent.py +113 -118
- agents/compliance_db.py +339 -0
- agents/epic_integration_wizard.py +37 -48
- agents/notifications.py +291 -0
- agents/trust_building_behaviors.py +66 -85
- coach_wizards/__init__.py +11 -12
- coach_wizards/accessibility_wizard.py +12 -12
- coach_wizards/api_wizard.py +12 -12
- coach_wizards/base_wizard.py +26 -20
- coach_wizards/cicd_wizard.py +15 -13
- coach_wizards/compliance_wizard.py +12 -12
- coach_wizards/database_wizard.py +12 -12
- coach_wizards/debugging_wizard.py +12 -12
- coach_wizards/documentation_wizard.py +12 -12
- coach_wizards/generate_wizards.py +1 -2
- coach_wizards/localization_wizard.py +21 -14
- coach_wizards/migration_wizard.py +12 -12
- coach_wizards/monitoring_wizard.py +12 -12
- coach_wizards/observability_wizard.py +12 -12
- coach_wizards/performance_wizard.py +12 -12
- coach_wizards/prompt_engineering_wizard.py +22 -25
- coach_wizards/refactoring_wizard.py +12 -12
- coach_wizards/scaling_wizard.py +12 -12
- coach_wizards/security_wizard.py +12 -12
- coach_wizards/testing_wizard.py +12 -12
- {empathy_framework-3.5.6.dist-info → empathy_framework-3.7.0.dist-info}/METADATA +234 -30
- empathy_framework-3.7.0.dist-info/RECORD +105 -0
- empathy_healthcare_plugin/__init__.py +1 -2
- empathy_llm_toolkit/__init__.py +5 -6
- empathy_llm_toolkit/claude_memory.py +14 -15
- empathy_llm_toolkit/code_health.py +27 -19
- empathy_llm_toolkit/contextual_patterns.py +11 -12
- empathy_llm_toolkit/core.py +43 -49
- empathy_llm_toolkit/git_pattern_extractor.py +16 -12
- empathy_llm_toolkit/levels.py +6 -13
- empathy_llm_toolkit/pattern_confidence.py +14 -18
- empathy_llm_toolkit/pattern_resolver.py +10 -12
- empathy_llm_toolkit/pattern_summary.py +13 -11
- empathy_llm_toolkit/providers.py +27 -38
- empathy_llm_toolkit/session_status.py +18 -20
- empathy_llm_toolkit/state.py +20 -21
- empathy_os/__init__.py +72 -73
- empathy_os/cli.py +193 -98
- empathy_os/cli_unified.py +68 -41
- empathy_os/config.py +31 -31
- empathy_os/coordination.py +48 -54
- empathy_os/core.py +90 -99
- empathy_os/cost_tracker.py +20 -23
- empathy_os/discovery.py +9 -11
- empathy_os/emergence.py +20 -21
- empathy_os/exceptions.py +18 -30
- empathy_os/feedback_loops.py +27 -30
- empathy_os/levels.py +31 -34
- empathy_os/leverage_points.py +27 -28
- empathy_os/logging_config.py +11 -12
- empathy_os/monitoring.py +27 -27
- empathy_os/pattern_library.py +29 -28
- empathy_os/persistence.py +30 -34
- empathy_os/platform_utils.py +46 -47
- empathy_os/redis_config.py +14 -15
- empathy_os/redis_memory.py +53 -56
- empathy_os/templates.py +12 -11
- empathy_os/trust_building.py +44 -36
- empathy_os/workflow_commands.py +123 -31
- empathy_software_plugin/__init__.py +1 -2
- empathy_software_plugin/cli.py +32 -25
- empathy_software_plugin/plugin.py +4 -8
- empathy_framework-3.5.6.dist-info/RECORD +0 -103
- {empathy_framework-3.5.6.dist-info → empathy_framework-3.7.0.dist-info}/WHEEL +0 -0
- {empathy_framework-3.5.6.dist-info → empathy_framework-3.7.0.dist-info}/entry_points.txt +0 -0
- {empathy_framework-3.5.6.dist-info → empathy_framework-3.7.0.dist-info}/licenses/LICENSE +0 -0
- {empathy_framework-3.5.6.dist-info → empathy_framework-3.7.0.dist-info}/top_level.txt +0 -0
empathy_os/core.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
"""
|
|
2
|
-
EmpathyOS - Core Implementation
|
|
1
|
+
"""EmpathyOS - Core Implementation
|
|
3
2
|
|
|
4
3
|
The main entry point for the Empathy Framework, providing access to all
|
|
5
4
|
5 empathy levels and system thinking integrations.
|
|
@@ -28,8 +27,7 @@ if TYPE_CHECKING:
|
|
|
28
27
|
|
|
29
28
|
@dataclass
|
|
30
29
|
class CollaborationState:
|
|
31
|
-
"""
|
|
32
|
-
Stock & Flow model of AI-human collaboration
|
|
30
|
+
"""Stock & Flow model of AI-human collaboration
|
|
33
31
|
|
|
34
32
|
Tracks:
|
|
35
33
|
- Trust level (stock that accumulates/erodes)
|
|
@@ -72,8 +70,7 @@ class CollaborationState:
|
|
|
72
70
|
|
|
73
71
|
|
|
74
72
|
class EmpathyOS:
|
|
75
|
-
"""
|
|
76
|
-
Empathy Operating System for AI-Human Collaboration
|
|
73
|
+
"""Empathy Operating System for AI-Human Collaboration
|
|
77
74
|
|
|
78
75
|
Integrates:
|
|
79
76
|
- 5-level Empathy Maturity Model
|
|
@@ -88,6 +85,7 @@ class EmpathyOS:
|
|
|
88
85
|
>>> empathy = EmpathyOS(user_id="developer_123", target_level=4)
|
|
89
86
|
>>> result = await empathy.level_4_anticipatory(system_trajectory)
|
|
90
87
|
>>> print(result["bottlenecks_predicted"])
|
|
88
|
+
|
|
91
89
|
"""
|
|
92
90
|
|
|
93
91
|
def __init__(
|
|
@@ -100,8 +98,7 @@ class EmpathyOS:
|
|
|
100
98
|
short_term_memory: RedisShortTermMemory | None = None,
|
|
101
99
|
access_tier: AccessTier = AccessTier.CONTRIBUTOR,
|
|
102
100
|
):
|
|
103
|
-
"""
|
|
104
|
-
Initialize EmpathyOS
|
|
101
|
+
"""Initialize EmpathyOS
|
|
105
102
|
|
|
106
103
|
Args:
|
|
107
104
|
user_id: Unique identifier for user/team
|
|
@@ -116,6 +113,7 @@ class EmpathyOS:
|
|
|
116
113
|
staging, and conflict resolution.
|
|
117
114
|
access_tier: Access tier for this agent (Observer, Contributor, Validator, Steward).
|
|
118
115
|
Determines what operations the agent can perform on shared memory.
|
|
116
|
+
|
|
119
117
|
"""
|
|
120
118
|
self.user_id = user_id
|
|
121
119
|
self.target_level = target_level
|
|
@@ -150,8 +148,7 @@ class EmpathyOS:
|
|
|
150
148
|
|
|
151
149
|
@property
|
|
152
150
|
def memory(self) -> UnifiedMemory:
|
|
153
|
-
"""
|
|
154
|
-
Unified memory interface for both short-term and long-term storage.
|
|
151
|
+
"""Unified memory interface for both short-term and long-term storage.
|
|
155
152
|
|
|
156
153
|
Lazily initializes on first access with environment auto-detection.
|
|
157
154
|
|
|
@@ -188,8 +185,7 @@ class EmpathyOS:
|
|
|
188
185
|
classification: Classification | str | None = None,
|
|
189
186
|
auto_classify: bool = True,
|
|
190
187
|
) -> dict | None:
|
|
191
|
-
"""
|
|
192
|
-
Store a pattern in long-term memory with security controls.
|
|
188
|
+
"""Store a pattern in long-term memory with security controls.
|
|
193
189
|
|
|
194
190
|
This is a convenience method that delegates to memory.persist_pattern().
|
|
195
191
|
|
|
@@ -209,6 +205,7 @@ class EmpathyOS:
|
|
|
209
205
|
... pattern_type="algorithm",
|
|
210
206
|
... )
|
|
211
207
|
>>> print(result["classification"]) # "INTERNAL"
|
|
208
|
+
|
|
212
209
|
"""
|
|
213
210
|
return self.memory.persist_pattern(
|
|
214
211
|
content=content,
|
|
@@ -218,8 +215,7 @@ class EmpathyOS:
|
|
|
218
215
|
)
|
|
219
216
|
|
|
220
217
|
def recall_pattern(self, pattern_id: str) -> dict | None:
|
|
221
|
-
"""
|
|
222
|
-
Retrieve a pattern from long-term memory.
|
|
218
|
+
"""Retrieve a pattern from long-term memory.
|
|
223
219
|
|
|
224
220
|
This is a convenience method that delegates to memory.recall_pattern().
|
|
225
221
|
|
|
@@ -232,12 +228,12 @@ class EmpathyOS:
|
|
|
232
228
|
Example:
|
|
233
229
|
>>> pattern = empathy.recall_pattern("pat_123")
|
|
234
230
|
>>> print(pattern["content"])
|
|
231
|
+
|
|
235
232
|
"""
|
|
236
233
|
return self.memory.recall_pattern(pattern_id)
|
|
237
234
|
|
|
238
235
|
def stash(self, key: str, value: Any, ttl_seconds: int = 3600) -> bool:
|
|
239
|
-
"""
|
|
240
|
-
Store data in short-term memory with TTL.
|
|
236
|
+
"""Store data in short-term memory with TTL.
|
|
241
237
|
|
|
242
238
|
This is a convenience method that delegates to memory.stash().
|
|
243
239
|
|
|
@@ -248,12 +244,12 @@ class EmpathyOS:
|
|
|
248
244
|
|
|
249
245
|
Returns:
|
|
250
246
|
True if stored successfully
|
|
247
|
+
|
|
251
248
|
"""
|
|
252
249
|
return self.memory.stash(key, value, ttl_seconds)
|
|
253
250
|
|
|
254
251
|
def retrieve(self, key: str) -> Any:
|
|
255
|
-
"""
|
|
256
|
-
Retrieve data from short-term memory.
|
|
252
|
+
"""Retrieve data from short-term memory.
|
|
257
253
|
|
|
258
254
|
This is a convenience method that delegates to memory.retrieve().
|
|
259
255
|
|
|
@@ -262,24 +258,24 @@ class EmpathyOS:
|
|
|
262
258
|
|
|
263
259
|
Returns:
|
|
264
260
|
Stored data or None
|
|
261
|
+
|
|
265
262
|
"""
|
|
266
263
|
return self.memory.retrieve(key)
|
|
267
264
|
|
|
268
265
|
async def __aenter__(self):
|
|
269
|
-
"""
|
|
270
|
-
Enter async context manager
|
|
266
|
+
"""Enter async context manager
|
|
271
267
|
|
|
272
268
|
Enables usage: async with EmpathyOS(...) as empathy:
|
|
273
269
|
|
|
274
270
|
Returns:
|
|
275
271
|
self: The EmpathyOS instance
|
|
272
|
+
|
|
276
273
|
"""
|
|
277
274
|
# Initialize any async resources here if needed
|
|
278
275
|
return self
|
|
279
276
|
|
|
280
277
|
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
281
|
-
"""
|
|
282
|
-
Exit async context manager
|
|
278
|
+
"""Exit async context manager
|
|
283
279
|
|
|
284
280
|
Performs cleanup when exiting the context:
|
|
285
281
|
- Saves patterns if persistence is enabled
|
|
@@ -293,13 +289,13 @@ class EmpathyOS:
|
|
|
293
289
|
|
|
294
290
|
Returns:
|
|
295
291
|
False to propagate exceptions (standard behavior)
|
|
292
|
+
|
|
296
293
|
"""
|
|
297
294
|
await self._cleanup()
|
|
298
295
|
return False # Don't suppress exceptions
|
|
299
296
|
|
|
300
297
|
async def _cleanup(self):
|
|
301
|
-
"""
|
|
302
|
-
Cleanup resources on context exit
|
|
298
|
+
"""Cleanup resources on context exit
|
|
303
299
|
|
|
304
300
|
**Extension Point**: Override to add custom cleanup logic
|
|
305
301
|
(e.g., save state to database, close connections, send metrics)
|
|
@@ -307,15 +303,13 @@ class EmpathyOS:
|
|
|
307
303
|
# Future: Save patterns to disk
|
|
308
304
|
# Future: Send final metrics
|
|
309
305
|
# Future: Close async connections
|
|
310
|
-
pass
|
|
311
306
|
|
|
312
307
|
# =========================================================================
|
|
313
308
|
# SHARED PATTERN LIBRARY (Multi-Agent Collaboration)
|
|
314
309
|
# =========================================================================
|
|
315
310
|
|
|
316
311
|
def contribute_pattern(self, pattern) -> None:
|
|
317
|
-
"""
|
|
318
|
-
Contribute a discovered pattern to the shared library.
|
|
312
|
+
"""Contribute a discovered pattern to the shared library.
|
|
319
313
|
|
|
320
314
|
Enables Level 5 Systems Empathy: patterns discovered by this agent
|
|
321
315
|
become available to all other agents sharing the same library.
|
|
@@ -338,17 +332,17 @@ class EmpathyOS:
|
|
|
338
332
|
... description="A discovered pattern",
|
|
339
333
|
... )
|
|
340
334
|
>>> agent.contribute_pattern(pattern)
|
|
335
|
+
|
|
341
336
|
"""
|
|
342
337
|
if self.shared_library is None:
|
|
343
338
|
raise RuntimeError(
|
|
344
339
|
"No shared library configured. Pass shared_library to __init__ "
|
|
345
|
-
"to enable multi-agent pattern sharing."
|
|
340
|
+
"to enable multi-agent pattern sharing.",
|
|
346
341
|
)
|
|
347
342
|
self.shared_library.contribute_pattern(self.user_id, pattern)
|
|
348
343
|
|
|
349
344
|
def query_patterns(self, context: dict, **kwargs):
|
|
350
|
-
"""
|
|
351
|
-
Query the shared library for patterns relevant to the current context.
|
|
345
|
+
"""Query the shared library for patterns relevant to the current context.
|
|
352
346
|
|
|
353
347
|
Enables agents to benefit from patterns discovered by other agents
|
|
354
348
|
in the distributed memory network.
|
|
@@ -371,11 +365,12 @@ class EmpathyOS:
|
|
|
371
365
|
... )
|
|
372
366
|
>>> for match in matches:
|
|
373
367
|
... print(f"{match.pattern.name}: {match.relevance_score:.0%}")
|
|
368
|
+
|
|
374
369
|
"""
|
|
375
370
|
if self.shared_library is None:
|
|
376
371
|
raise RuntimeError(
|
|
377
372
|
"No shared library configured. Pass shared_library to __init__ "
|
|
378
|
-
"to enable multi-agent pattern sharing."
|
|
373
|
+
"to enable multi-agent pattern sharing.",
|
|
379
374
|
)
|
|
380
375
|
return self.shared_library.query_patterns(self.user_id, context, **kwargs)
|
|
381
376
|
|
|
@@ -388,8 +383,7 @@ class EmpathyOS:
|
|
|
388
383
|
# =========================================================================
|
|
389
384
|
|
|
390
385
|
async def level_1_reactive(self, user_request: str) -> dict:
|
|
391
|
-
"""
|
|
392
|
-
Level 1: Reactive Empathy
|
|
386
|
+
"""Level 1: Reactive Empathy
|
|
393
387
|
|
|
394
388
|
Respond to explicit request accurately and helpfully.
|
|
395
389
|
No anticipation, no proactive action.
|
|
@@ -402,11 +396,12 @@ class EmpathyOS:
|
|
|
402
396
|
|
|
403
397
|
Raises:
|
|
404
398
|
ValueError: If user_request is empty or not a string
|
|
399
|
+
|
|
405
400
|
"""
|
|
406
401
|
# Input validation
|
|
407
402
|
if not isinstance(user_request, str):
|
|
408
403
|
raise ValidationError(
|
|
409
|
-
f"user_request must be a string, got {type(user_request).__name__}"
|
|
404
|
+
f"user_request must be a string, got {type(user_request).__name__}",
|
|
410
405
|
)
|
|
411
406
|
if not user_request.strip():
|
|
412
407
|
raise ValidationError("user_request cannot be empty")
|
|
@@ -446,8 +441,7 @@ class EmpathyOS:
|
|
|
446
441
|
# =========================================================================
|
|
447
442
|
|
|
448
443
|
async def level_2_guided(self, user_request: str) -> dict:
|
|
449
|
-
"""
|
|
450
|
-
Level 2: Guided Empathy
|
|
444
|
+
"""Level 2: Guided Empathy
|
|
451
445
|
|
|
452
446
|
Use calibrated questions (Voss) to clarify intent before acting.
|
|
453
447
|
Collaborative exploration to uncover hidden needs.
|
|
@@ -460,11 +454,12 @@ class EmpathyOS:
|
|
|
460
454
|
|
|
461
455
|
Raises:
|
|
462
456
|
ValueError: If user_request is empty or not a string
|
|
457
|
+
|
|
463
458
|
"""
|
|
464
459
|
# Input validation
|
|
465
460
|
if not isinstance(user_request, str):
|
|
466
461
|
raise ValidationError(
|
|
467
|
-
f"user_request must be a string, got {type(user_request).__name__}"
|
|
462
|
+
f"user_request must be a string, got {type(user_request).__name__}",
|
|
468
463
|
)
|
|
469
464
|
if not user_request.strip():
|
|
470
465
|
raise ValidationError("user_request cannot be empty")
|
|
@@ -528,8 +523,7 @@ class EmpathyOS:
|
|
|
528
523
|
# =========================================================================
|
|
529
524
|
|
|
530
525
|
async def level_3_proactive(self, context: dict) -> dict:
|
|
531
|
-
"""
|
|
532
|
-
Level 3: Proactive Empathy
|
|
526
|
+
"""Level 3: Proactive Empathy
|
|
533
527
|
|
|
534
528
|
Detect patterns, act on leading indicators.
|
|
535
529
|
Take initiative without being asked.
|
|
@@ -542,6 +536,7 @@ class EmpathyOS:
|
|
|
542
536
|
|
|
543
537
|
Raises:
|
|
544
538
|
ValueError: If context is not a dict or is empty
|
|
539
|
+
|
|
545
540
|
"""
|
|
546
541
|
# Input validation
|
|
547
542
|
if not isinstance(context, dict):
|
|
@@ -610,8 +605,7 @@ class EmpathyOS:
|
|
|
610
605
|
# =========================================================================
|
|
611
606
|
|
|
612
607
|
async def level_4_anticipatory(self, system_trajectory: dict) -> dict:
|
|
613
|
-
"""
|
|
614
|
-
Level 4: Anticipatory Empathy (THE INNOVATION)
|
|
608
|
+
"""Level 4: Anticipatory Empathy (THE INNOVATION)
|
|
615
609
|
|
|
616
610
|
Predict future bottlenecks, design relief in advance.
|
|
617
611
|
|
|
@@ -628,11 +622,12 @@ class EmpathyOS:
|
|
|
628
622
|
|
|
629
623
|
Raises:
|
|
630
624
|
ValueError: If system_trajectory is not a dict or is empty
|
|
625
|
+
|
|
631
626
|
"""
|
|
632
627
|
# Input validation
|
|
633
628
|
if not isinstance(system_trajectory, dict):
|
|
634
629
|
raise ValidationError(
|
|
635
|
-
f"system_trajectory must be a dict, got {type(system_trajectory).__name__}"
|
|
630
|
+
f"system_trajectory must be a dict, got {type(system_trajectory).__name__}",
|
|
636
631
|
)
|
|
637
632
|
if not system_trajectory:
|
|
638
633
|
raise ValidationError("system_trajectory cannot be empty")
|
|
@@ -700,8 +695,7 @@ class EmpathyOS:
|
|
|
700
695
|
# =========================================================================
|
|
701
696
|
|
|
702
697
|
async def level_5_systems(self, domain_context: dict) -> dict:
|
|
703
|
-
"""
|
|
704
|
-
Level 5: Systems Empathy
|
|
698
|
+
"""Level 5: Systems Empathy
|
|
705
699
|
|
|
706
700
|
Build structures that help at scale.
|
|
707
701
|
Design leverage points, frameworks, self-sustaining systems.
|
|
@@ -719,11 +713,12 @@ class EmpathyOS:
|
|
|
719
713
|
|
|
720
714
|
Raises:
|
|
721
715
|
ValueError: If domain_context is not a dict or is empty
|
|
716
|
+
|
|
722
717
|
"""
|
|
723
718
|
# Input validation
|
|
724
719
|
if not isinstance(domain_context, dict):
|
|
725
720
|
raise ValidationError(
|
|
726
|
-
f"domain_context must be a dict, got {type(domain_context).__name__}"
|
|
721
|
+
f"domain_context must be a dict, got {type(domain_context).__name__}",
|
|
727
722
|
)
|
|
728
723
|
if not domain_context:
|
|
729
724
|
raise ValidationError("domain_context cannot be empty")
|
|
@@ -785,8 +780,7 @@ class EmpathyOS:
|
|
|
785
780
|
# =========================================================================
|
|
786
781
|
|
|
787
782
|
async def _process_request(self, request: str) -> dict:
|
|
788
|
-
"""
|
|
789
|
-
Process user request (implement domain logic)
|
|
783
|
+
"""Process user request (implement domain logic)
|
|
790
784
|
|
|
791
785
|
**Extension Point**: Override this method in subclasses to implement
|
|
792
786
|
your specific domain logic for processing user requests.
|
|
@@ -796,13 +790,13 @@ class EmpathyOS:
|
|
|
796
790
|
|
|
797
791
|
Returns:
|
|
798
792
|
Dict with processed result and status
|
|
793
|
+
|
|
799
794
|
"""
|
|
800
795
|
# Placeholder - implement your actual request processing
|
|
801
796
|
return {"processed": request, "status": "success"}
|
|
802
797
|
|
|
803
798
|
async def _ask_calibrated_questions(self, request: str) -> dict:
|
|
804
|
-
"""
|
|
805
|
-
Voss's tactical empathy: Ask calibrated questions
|
|
799
|
+
"""Voss's tactical empathy: Ask calibrated questions
|
|
806
800
|
|
|
807
801
|
**Extension Point**: Override to implement sophisticated clarification
|
|
808
802
|
logic using NLP, LLMs, or domain-specific heuristics.
|
|
@@ -812,6 +806,7 @@ class EmpathyOS:
|
|
|
812
806
|
|
|
813
807
|
Returns:
|
|
814
808
|
Dict with needs_clarification flag and optional questions list
|
|
809
|
+
|
|
815
810
|
"""
|
|
816
811
|
# Simple heuristic - in production, use NLP/LLM
|
|
817
812
|
needs_clarification = any(
|
|
@@ -830,8 +825,7 @@ class EmpathyOS:
|
|
|
830
825
|
return {"needs_clarification": False}
|
|
831
826
|
|
|
832
827
|
def _refine_request(self, original: str, clarification: dict) -> str:
|
|
833
|
-
"""
|
|
834
|
-
Refine request based on clarification responses
|
|
828
|
+
"""Refine request based on clarification responses
|
|
835
829
|
|
|
836
830
|
**Extension Point**: Override to implement domain-specific request refinement
|
|
837
831
|
based on clarification questions and user responses.
|
|
@@ -842,6 +836,7 @@ class EmpathyOS:
|
|
|
842
836
|
|
|
843
837
|
Returns:
|
|
844
838
|
Refined request string with added context
|
|
839
|
+
|
|
845
840
|
"""
|
|
846
841
|
# If no clarification was needed, return original
|
|
847
842
|
if not clarification.get("needs_clarification", False):
|
|
@@ -870,7 +865,7 @@ class EmpathyOS:
|
|
|
870
865
|
"type": "sequential",
|
|
871
866
|
"pattern": "user_always_does_X_before_Y",
|
|
872
867
|
"confidence": 0.85,
|
|
873
|
-
}
|
|
868
|
+
},
|
|
874
869
|
)
|
|
875
870
|
|
|
876
871
|
return patterns
|
|
@@ -889,8 +884,7 @@ class EmpathyOS:
|
|
|
889
884
|
return confidence > 0.8
|
|
890
885
|
|
|
891
886
|
async def _execute_proactive_actions(self, actions: list[dict]) -> list[dict]:
|
|
892
|
-
"""
|
|
893
|
-
Execute proactive actions
|
|
887
|
+
"""Execute proactive actions
|
|
894
888
|
|
|
895
889
|
**Extension Point**: Override to implement actual execution of proactive
|
|
896
890
|
actions in your domain (e.g., file operations, API calls, UI updates).
|
|
@@ -903,13 +897,14 @@ class EmpathyOS:
|
|
|
903
897
|
|
|
904
898
|
Returns:
|
|
905
899
|
List of result dicts with action and success status
|
|
900
|
+
|
|
906
901
|
"""
|
|
907
902
|
results = []
|
|
908
903
|
for action in actions:
|
|
909
904
|
# Validate action has required fields
|
|
910
905
|
if not action.get("action"):
|
|
911
906
|
results.append(
|
|
912
|
-
{"action": action, "success": False, "error": "Missing 'action' field"}
|
|
907
|
+
{"action": action, "success": False, "error": "Missing 'action' field"},
|
|
913
908
|
)
|
|
914
909
|
continue
|
|
915
910
|
|
|
@@ -925,14 +920,13 @@ class EmpathyOS:
|
|
|
925
920
|
|
|
926
921
|
# Simulate successful execution
|
|
927
922
|
results.append(
|
|
928
|
-
{"action": action, "success": True, "executed_at": datetime.now().isoformat()}
|
|
923
|
+
{"action": action, "success": True, "executed_at": datetime.now().isoformat()},
|
|
929
924
|
)
|
|
930
925
|
|
|
931
926
|
return results
|
|
932
927
|
|
|
933
928
|
def _predict_future_bottlenecks(self, trajectory: dict) -> list[dict]:
|
|
934
|
-
"""
|
|
935
|
-
Predict where system will hit friction/overload
|
|
929
|
+
"""Predict where system will hit friction/overload
|
|
936
930
|
|
|
937
931
|
Uses trajectory analysis, domain knowledge, historical patterns
|
|
938
932
|
"""
|
|
@@ -955,14 +949,13 @@ class EmpathyOS:
|
|
|
955
949
|
"current_state": f"{current} features",
|
|
956
950
|
"predicted_state": f"{projected_3mo} features",
|
|
957
951
|
"impact": trajectory.get("impact", "low"),
|
|
958
|
-
}
|
|
952
|
+
},
|
|
959
953
|
)
|
|
960
954
|
|
|
961
955
|
return bottlenecks
|
|
962
956
|
|
|
963
957
|
def _should_anticipate(self, bottleneck: dict) -> bool:
|
|
964
|
-
"""
|
|
965
|
-
Safety checks for Level 4 anticipatory actions
|
|
958
|
+
"""Safety checks for Level 4 anticipatory actions
|
|
966
959
|
|
|
967
960
|
Validates:
|
|
968
961
|
1. Confidence is above threshold
|
|
@@ -989,8 +982,7 @@ class EmpathyOS:
|
|
|
989
982
|
return True
|
|
990
983
|
|
|
991
984
|
def _parse_timeframe_to_days(self, timeframe: str) -> int | None:
|
|
992
|
-
"""
|
|
993
|
-
Parse timeframe string to days
|
|
985
|
+
"""Parse timeframe string to days
|
|
994
986
|
|
|
995
987
|
Examples:
|
|
996
988
|
"2-3 months" -> 75 (midpoint)
|
|
@@ -999,6 +991,7 @@ class EmpathyOS:
|
|
|
999
991
|
|
|
1000
992
|
Returns:
|
|
1001
993
|
Number of days, or None if unparseable
|
|
994
|
+
|
|
1002
995
|
"""
|
|
1003
996
|
import re
|
|
1004
997
|
|
|
@@ -1038,8 +1031,7 @@ class EmpathyOS:
|
|
|
1038
1031
|
}
|
|
1039
1032
|
|
|
1040
1033
|
async def _execute_anticipatory_interventions(self, interventions: list[dict]) -> list[dict]:
|
|
1041
|
-
"""
|
|
1042
|
-
Execute anticipatory interventions
|
|
1034
|
+
"""Execute anticipatory interventions
|
|
1043
1035
|
|
|
1044
1036
|
**Extension Point**: Override to implement actual execution of
|
|
1045
1037
|
anticipatory interventions (e.g., scaling resources, provisioning
|
|
@@ -1053,6 +1045,7 @@ class EmpathyOS:
|
|
|
1053
1045
|
|
|
1054
1046
|
Returns:
|
|
1055
1047
|
List of result dicts with intervention and success status
|
|
1048
|
+
|
|
1056
1049
|
"""
|
|
1057
1050
|
results = []
|
|
1058
1051
|
for intervention in interventions:
|
|
@@ -1063,7 +1056,7 @@ class EmpathyOS:
|
|
|
1063
1056
|
"intervention": intervention,
|
|
1064
1057
|
"success": False,
|
|
1065
1058
|
"error": "Missing 'type' field",
|
|
1066
|
-
}
|
|
1059
|
+
},
|
|
1067
1060
|
)
|
|
1068
1061
|
continue
|
|
1069
1062
|
|
|
@@ -1085,14 +1078,13 @@ class EmpathyOS:
|
|
|
1085
1078
|
"success": True,
|
|
1086
1079
|
"executed_at": datetime.now().isoformat(),
|
|
1087
1080
|
"status": "intervention_deployed",
|
|
1088
|
-
}
|
|
1081
|
+
},
|
|
1089
1082
|
)
|
|
1090
1083
|
|
|
1091
1084
|
return results
|
|
1092
1085
|
|
|
1093
1086
|
def _identify_problem_classes(self, domain_context: dict) -> list[dict]:
|
|
1094
|
-
"""
|
|
1095
|
-
Identify recurring problem classes (not individual instances)
|
|
1087
|
+
"""Identify recurring problem classes (not individual instances)
|
|
1096
1088
|
|
|
1097
1089
|
Use "Rule of Three":
|
|
1098
1090
|
- Occurred at least 3 times
|
|
@@ -1108,7 +1100,7 @@ class EmpathyOS:
|
|
|
1108
1100
|
"class": "documentation_burden",
|
|
1109
1101
|
"instances": domain_context["instances"],
|
|
1110
1102
|
"frequency": "every_new_feature",
|
|
1111
|
-
}
|
|
1103
|
+
},
|
|
1112
1104
|
)
|
|
1113
1105
|
|
|
1114
1106
|
return problem_classes
|
|
@@ -1124,8 +1116,7 @@ class EmpathyOS:
|
|
|
1124
1116
|
}
|
|
1125
1117
|
|
|
1126
1118
|
async def _implement_frameworks(self, frameworks: list[dict]) -> list[dict]:
|
|
1127
|
-
"""
|
|
1128
|
-
Implement designed frameworks
|
|
1119
|
+
"""Implement designed frameworks
|
|
1129
1120
|
|
|
1130
1121
|
**Extension Point**: Override to implement actual framework deployment
|
|
1131
1122
|
(e.g., generating code templates, creating CI/CD pipelines, deploying
|
|
@@ -1139,13 +1130,14 @@ class EmpathyOS:
|
|
|
1139
1130
|
|
|
1140
1131
|
Returns:
|
|
1141
1132
|
List of result dicts with framework and deployed status
|
|
1133
|
+
|
|
1142
1134
|
"""
|
|
1143
1135
|
results = []
|
|
1144
1136
|
for framework in frameworks:
|
|
1145
1137
|
# Validate framework has required fields
|
|
1146
1138
|
if not framework.get("name"):
|
|
1147
1139
|
results.append(
|
|
1148
|
-
{"framework": framework, "deployed": False, "error": "Missing 'name' field"}
|
|
1140
|
+
{"framework": framework, "deployed": False, "error": "Missing 'name' field"},
|
|
1149
1141
|
)
|
|
1150
1142
|
continue
|
|
1151
1143
|
|
|
@@ -1168,7 +1160,7 @@ class EmpathyOS:
|
|
|
1168
1160
|
"deployed_at": datetime.now().isoformat(),
|
|
1169
1161
|
"status": "framework_active",
|
|
1170
1162
|
"impact_scope": "system_wide",
|
|
1171
|
-
}
|
|
1163
|
+
},
|
|
1172
1164
|
)
|
|
1173
1165
|
|
|
1174
1166
|
return results
|
|
@@ -1178,9 +1170,7 @@ class EmpathyOS:
|
|
|
1178
1170
|
# =========================================================================
|
|
1179
1171
|
|
|
1180
1172
|
def monitor_feedback_loops(self, session_history: list) -> dict:
|
|
1181
|
-
"""
|
|
1182
|
-
Detect and manage feedback loops in collaboration
|
|
1183
|
-
"""
|
|
1173
|
+
"""Detect and manage feedback loops in collaboration"""
|
|
1184
1174
|
active_loops = self.feedback_detector.detect_active_loop(session_history)
|
|
1185
1175
|
|
|
1186
1176
|
# Take action based on loop type
|
|
@@ -1188,7 +1178,7 @@ class EmpathyOS:
|
|
|
1188
1178
|
# URGENT: Break vicious cycle
|
|
1189
1179
|
return self._break_trust_erosion_loop()
|
|
1190
1180
|
|
|
1191
|
-
|
|
1181
|
+
if active_loops.get("dominant_loop") == "R1_trust_building":
|
|
1192
1182
|
# MAINTAIN: Keep virtuous cycle going
|
|
1193
1183
|
return self._maintain_trust_building_loop()
|
|
1194
1184
|
|
|
@@ -1258,8 +1248,7 @@ class EmpathyOS:
|
|
|
1258
1248
|
return self._session_id
|
|
1259
1249
|
|
|
1260
1250
|
def stage_pattern(self, pattern: StagedPattern) -> bool:
|
|
1261
|
-
"""
|
|
1262
|
-
Stage a discovered pattern for validation.
|
|
1251
|
+
"""Stage a discovered pattern for validation.
|
|
1263
1252
|
|
|
1264
1253
|
Patterns are held in a staging area until a Validator promotes them
|
|
1265
1254
|
to the active pattern library. This implements the trust-but-verify
|
|
@@ -1286,17 +1275,17 @@ class EmpathyOS:
|
|
|
1286
1275
|
... confidence=0.85,
|
|
1287
1276
|
... )
|
|
1288
1277
|
>>> empathy.stage_pattern(pattern)
|
|
1278
|
+
|
|
1289
1279
|
"""
|
|
1290
1280
|
if self.short_term_memory is None:
|
|
1291
1281
|
raise RuntimeError(
|
|
1292
1282
|
"No short-term memory configured. Pass short_term_memory to __init__ "
|
|
1293
|
-
"to enable pattern staging."
|
|
1283
|
+
"to enable pattern staging.",
|
|
1294
1284
|
)
|
|
1295
1285
|
return self.short_term_memory.stage_pattern(pattern, self.credentials)
|
|
1296
1286
|
|
|
1297
1287
|
def get_staged_patterns(self) -> list[StagedPattern]:
|
|
1298
|
-
"""
|
|
1299
|
-
Get all patterns currently in staging.
|
|
1288
|
+
"""Get all patterns currently in staging.
|
|
1300
1289
|
|
|
1301
1290
|
Returns patterns staged by any agent that are awaiting validation.
|
|
1302
1291
|
Validators use this to review and promote/reject patterns.
|
|
@@ -1306,11 +1295,12 @@ class EmpathyOS:
|
|
|
1306
1295
|
|
|
1307
1296
|
Raises:
|
|
1308
1297
|
RuntimeError: If no short-term memory configured
|
|
1298
|
+
|
|
1309
1299
|
"""
|
|
1310
1300
|
if self.short_term_memory is None:
|
|
1311
1301
|
raise RuntimeError(
|
|
1312
1302
|
"No short-term memory configured. Pass short_term_memory to __init__ "
|
|
1313
|
-
"to enable pattern staging."
|
|
1303
|
+
"to enable pattern staging.",
|
|
1314
1304
|
)
|
|
1315
1305
|
return self.short_term_memory.list_staged_patterns(self.credentials)
|
|
1316
1306
|
|
|
@@ -1320,8 +1310,7 @@ class EmpathyOS:
|
|
|
1320
1310
|
data: dict,
|
|
1321
1311
|
target_agent: str | None = None,
|
|
1322
1312
|
) -> bool:
|
|
1323
|
-
"""
|
|
1324
|
-
Send a coordination signal to other agents.
|
|
1313
|
+
"""Send a coordination signal to other agents.
|
|
1325
1314
|
|
|
1326
1315
|
Use signals for real-time coordination:
|
|
1327
1316
|
- Notify completion of tasks
|
|
@@ -1348,11 +1337,12 @@ class EmpathyOS:
|
|
|
1348
1337
|
... )
|
|
1349
1338
|
>>> # Broadcast to all
|
|
1350
1339
|
>>> empathy.send_signal("status_update", {"phase": "testing"})
|
|
1340
|
+
|
|
1351
1341
|
"""
|
|
1352
1342
|
if self.short_term_memory is None:
|
|
1353
1343
|
raise RuntimeError(
|
|
1354
1344
|
"No short-term memory configured. Pass short_term_memory to __init__ "
|
|
1355
|
-
"to enable coordination signals."
|
|
1345
|
+
"to enable coordination signals.",
|
|
1356
1346
|
)
|
|
1357
1347
|
return self.short_term_memory.send_signal(
|
|
1358
1348
|
signal_type=signal_type,
|
|
@@ -1362,8 +1352,7 @@ class EmpathyOS:
|
|
|
1362
1352
|
)
|
|
1363
1353
|
|
|
1364
1354
|
def receive_signals(self, signal_type: str | None = None) -> list[dict]:
|
|
1365
|
-
"""
|
|
1366
|
-
Receive coordination signals from other agents.
|
|
1355
|
+
"""Receive coordination signals from other agents.
|
|
1367
1356
|
|
|
1368
1357
|
Returns signals targeted at this agent or broadcast signals.
|
|
1369
1358
|
Signals expire after 5 minutes (TTL).
|
|
@@ -1381,17 +1370,17 @@ class EmpathyOS:
|
|
|
1381
1370
|
>>> signals = empathy.receive_signals("analysis_complete")
|
|
1382
1371
|
>>> for sig in signals:
|
|
1383
1372
|
... print(f"From {sig['sender']}: {sig['data']}")
|
|
1373
|
+
|
|
1384
1374
|
"""
|
|
1385
1375
|
if self.short_term_memory is None:
|
|
1386
1376
|
raise RuntimeError(
|
|
1387
1377
|
"No short-term memory configured. Pass short_term_memory to __init__ "
|
|
1388
|
-
"to enable coordination signals."
|
|
1378
|
+
"to enable coordination signals.",
|
|
1389
1379
|
)
|
|
1390
1380
|
return self.short_term_memory.receive_signals(self.credentials, signal_type=signal_type)
|
|
1391
1381
|
|
|
1392
1382
|
def persist_collaboration_state(self) -> bool:
|
|
1393
|
-
"""
|
|
1394
|
-
Persist current collaboration state to short-term memory.
|
|
1383
|
+
"""Persist current collaboration state to short-term memory.
|
|
1395
1384
|
|
|
1396
1385
|
Call periodically to save state that can be recovered if the agent
|
|
1397
1386
|
restarts. State expires after 30 minutes by default.
|
|
@@ -1401,11 +1390,12 @@ class EmpathyOS:
|
|
|
1401
1390
|
|
|
1402
1391
|
Raises:
|
|
1403
1392
|
RuntimeError: If no short-term memory configured
|
|
1393
|
+
|
|
1404
1394
|
"""
|
|
1405
1395
|
if self.short_term_memory is None:
|
|
1406
1396
|
raise RuntimeError(
|
|
1407
1397
|
"No short-term memory configured. Pass short_term_memory to __init__ "
|
|
1408
|
-
"to enable state persistence."
|
|
1398
|
+
"to enable state persistence.",
|
|
1409
1399
|
)
|
|
1410
1400
|
|
|
1411
1401
|
state_data = {
|
|
@@ -1424,8 +1414,7 @@ class EmpathyOS:
|
|
|
1424
1414
|
)
|
|
1425
1415
|
|
|
1426
1416
|
def restore_collaboration_state(self, session_id: str | None = None) -> bool:
|
|
1427
|
-
"""
|
|
1428
|
-
Restore collaboration state from short-term memory.
|
|
1417
|
+
"""Restore collaboration state from short-term memory.
|
|
1429
1418
|
|
|
1430
1419
|
Use to recover state after agent restart or to continue a previous
|
|
1431
1420
|
session.
|
|
@@ -1438,11 +1427,12 @@ class EmpathyOS:
|
|
|
1438
1427
|
|
|
1439
1428
|
Raises:
|
|
1440
1429
|
RuntimeError: If no short-term memory configured
|
|
1430
|
+
|
|
1441
1431
|
"""
|
|
1442
1432
|
if self.short_term_memory is None:
|
|
1443
1433
|
raise RuntimeError(
|
|
1444
1434
|
"No short-term memory configured. Pass short_term_memory to __init__ "
|
|
1445
|
-
"to enable state persistence."
|
|
1435
|
+
"to enable state persistence.",
|
|
1446
1436
|
)
|
|
1447
1437
|
|
|
1448
1438
|
sid = session_id or self.session_id
|
|
@@ -1457,7 +1447,8 @@ class EmpathyOS:
|
|
|
1457
1447
|
# Restore state
|
|
1458
1448
|
self.collaboration_state.trust_level = state_data.get("trust_level", 0.5)
|
|
1459
1449
|
self.collaboration_state.successful_interventions = state_data.get(
|
|
1460
|
-
"successful_interventions",
|
|
1450
|
+
"successful_interventions",
|
|
1451
|
+
0,
|
|
1461
1452
|
)
|
|
1462
1453
|
self.collaboration_state.failed_interventions = state_data.get("failed_interventions", 0)
|
|
1463
1454
|
self.collaboration_state.total_interactions = state_data.get("total_interactions", 0)
|
|
@@ -1476,11 +1467,11 @@ class EmpathyOS:
|
|
|
1476
1467
|
return True
|
|
1477
1468
|
|
|
1478
1469
|
def get_memory_stats(self) -> dict | None:
|
|
1479
|
-
"""
|
|
1480
|
-
Get statistics about the short-term memory system.
|
|
1470
|
+
"""Get statistics about the short-term memory system.
|
|
1481
1471
|
|
|
1482
1472
|
Returns:
|
|
1483
1473
|
Dict with memory usage, key counts, mode, or None if not configured
|
|
1474
|
+
|
|
1484
1475
|
"""
|
|
1485
1476
|
if self.short_term_memory is None:
|
|
1486
1477
|
return None
|