empathy-framework 2.4.0__py3-none-any.whl → 3.8.2__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.
- coach_wizards/__init__.py +13 -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/code_reviewer_README.md +60 -0
- coach_wizards/code_reviewer_wizard.py +180 -0
- 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 +101 -19
- 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 +661 -0
- 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.8.2.dist-info/METADATA +1176 -0
- empathy_framework-3.8.2.dist-info/RECORD +333 -0
- empathy_framework-3.8.2.dist-info/entry_points.txt +22 -0
- {empathy_framework-2.4.0.dist-info → empathy_framework-3.8.2.dist-info}/top_level.txt +5 -1
- empathy_healthcare_plugin/__init__.py +1 -2
- empathy_healthcare_plugin/monitors/__init__.py +9 -0
- empathy_healthcare_plugin/monitors/clinical_protocol_monitor.py +315 -0
- empathy_healthcare_plugin/monitors/monitoring/__init__.py +44 -0
- empathy_healthcare_plugin/monitors/monitoring/protocol_checker.py +300 -0
- empathy_healthcare_plugin/monitors/monitoring/protocol_loader.py +214 -0
- empathy_healthcare_plugin/monitors/monitoring/sensor_parsers.py +306 -0
- empathy_healthcare_plugin/monitors/monitoring/trajectory_analyzer.py +389 -0
- empathy_llm_toolkit/__init__.py +7 -7
- empathy_llm_toolkit/agent_factory/__init__.py +53 -0
- empathy_llm_toolkit/agent_factory/adapters/__init__.py +85 -0
- empathy_llm_toolkit/agent_factory/adapters/autogen_adapter.py +312 -0
- empathy_llm_toolkit/agent_factory/adapters/crewai_adapter.py +454 -0
- empathy_llm_toolkit/agent_factory/adapters/haystack_adapter.py +298 -0
- empathy_llm_toolkit/agent_factory/adapters/langchain_adapter.py +362 -0
- empathy_llm_toolkit/agent_factory/adapters/langgraph_adapter.py +333 -0
- empathy_llm_toolkit/agent_factory/adapters/native.py +228 -0
- empathy_llm_toolkit/agent_factory/adapters/wizard_adapter.py +426 -0
- empathy_llm_toolkit/agent_factory/base.py +305 -0
- empathy_llm_toolkit/agent_factory/crews/__init__.py +67 -0
- empathy_llm_toolkit/agent_factory/crews/code_review.py +1113 -0
- empathy_llm_toolkit/agent_factory/crews/health_check.py +1246 -0
- empathy_llm_toolkit/agent_factory/crews/refactoring.py +1128 -0
- empathy_llm_toolkit/agent_factory/crews/security_audit.py +1018 -0
- empathy_llm_toolkit/agent_factory/decorators.py +286 -0
- empathy_llm_toolkit/agent_factory/factory.py +558 -0
- empathy_llm_toolkit/agent_factory/framework.py +192 -0
- empathy_llm_toolkit/agent_factory/memory_integration.py +324 -0
- empathy_llm_toolkit/agent_factory/resilient.py +320 -0
- empathy_llm_toolkit/claude_memory.py +14 -15
- empathy_llm_toolkit/cli/__init__.py +8 -0
- empathy_llm_toolkit/cli/sync_claude.py +487 -0
- empathy_llm_toolkit/code_health.py +186 -28
- empathy_llm_toolkit/config/__init__.py +29 -0
- empathy_llm_toolkit/config/unified.py +295 -0
- empathy_llm_toolkit/contextual_patterns.py +11 -12
- empathy_llm_toolkit/core.py +168 -53
- empathy_llm_toolkit/git_pattern_extractor.py +17 -13
- 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 +16 -14
- empathy_llm_toolkit/providers.py +194 -28
- empathy_llm_toolkit/routing/__init__.py +32 -0
- empathy_llm_toolkit/routing/model_router.py +362 -0
- empathy_llm_toolkit/security/IMPLEMENTATION_SUMMARY.md +413 -0
- empathy_llm_toolkit/security/PHASE2_COMPLETE.md +384 -0
- empathy_llm_toolkit/security/PHASE2_SECRETS_DETECTOR_COMPLETE.md +271 -0
- empathy_llm_toolkit/security/QUICK_REFERENCE.md +316 -0
- empathy_llm_toolkit/security/README.md +262 -0
- empathy_llm_toolkit/security/__init__.py +62 -0
- empathy_llm_toolkit/security/audit_logger.py +929 -0
- empathy_llm_toolkit/security/audit_logger_example.py +152 -0
- empathy_llm_toolkit/security/pii_scrubber.py +640 -0
- empathy_llm_toolkit/security/secrets_detector.py +678 -0
- empathy_llm_toolkit/security/secrets_detector_example.py +304 -0
- empathy_llm_toolkit/security/secure_memdocs.py +1192 -0
- empathy_llm_toolkit/security/secure_memdocs_example.py +278 -0
- empathy_llm_toolkit/session_status.py +20 -22
- empathy_llm_toolkit/state.py +28 -21
- empathy_llm_toolkit/wizards/__init__.py +38 -0
- empathy_llm_toolkit/wizards/base_wizard.py +364 -0
- empathy_llm_toolkit/wizards/customer_support_wizard.py +190 -0
- empathy_llm_toolkit/wizards/healthcare_wizard.py +362 -0
- empathy_llm_toolkit/wizards/patient_assessment_README.md +64 -0
- empathy_llm_toolkit/wizards/patient_assessment_wizard.py +193 -0
- empathy_llm_toolkit/wizards/technology_wizard.py +194 -0
- empathy_os/__init__.py +125 -84
- empathy_os/adaptive/__init__.py +13 -0
- empathy_os/adaptive/task_complexity.py +127 -0
- empathy_os/{monitoring.py → agent_monitoring.py} +28 -28
- empathy_os/cache/__init__.py +117 -0
- empathy_os/cache/base.py +166 -0
- empathy_os/cache/dependency_manager.py +253 -0
- empathy_os/cache/hash_only.py +248 -0
- empathy_os/cache/hybrid.py +390 -0
- empathy_os/cache/storage.py +282 -0
- empathy_os/cli.py +1516 -70
- empathy_os/cli_unified.py +597 -0
- empathy_os/config/__init__.py +63 -0
- empathy_os/config/xml_config.py +239 -0
- empathy_os/config.py +95 -37
- empathy_os/coordination.py +72 -68
- empathy_os/core.py +94 -107
- empathy_os/cost_tracker.py +74 -55
- empathy_os/dashboard/__init__.py +15 -0
- empathy_os/dashboard/server.py +743 -0
- empathy_os/discovery.py +17 -14
- empathy_os/emergence.py +21 -22
- empathy_os/exceptions.py +18 -30
- empathy_os/feedback_loops.py +30 -33
- empathy_os/levels.py +32 -35
- empathy_os/leverage_points.py +31 -32
- empathy_os/logging_config.py +19 -16
- empathy_os/memory/__init__.py +195 -0
- empathy_os/memory/claude_memory.py +466 -0
- empathy_os/memory/config.py +224 -0
- empathy_os/memory/control_panel.py +1298 -0
- empathy_os/memory/edges.py +179 -0
- empathy_os/memory/graph.py +567 -0
- empathy_os/memory/long_term.py +1194 -0
- empathy_os/memory/nodes.py +179 -0
- empathy_os/memory/redis_bootstrap.py +540 -0
- empathy_os/memory/security/__init__.py +31 -0
- empathy_os/memory/security/audit_logger.py +930 -0
- empathy_os/memory/security/pii_scrubber.py +640 -0
- empathy_os/memory/security/secrets_detector.py +678 -0
- empathy_os/memory/short_term.py +2119 -0
- empathy_os/memory/storage/__init__.py +15 -0
- empathy_os/memory/summary_index.py +583 -0
- empathy_os/memory/unified.py +619 -0
- empathy_os/metrics/__init__.py +12 -0
- empathy_os/metrics/prompt_metrics.py +190 -0
- empathy_os/models/__init__.py +136 -0
- empathy_os/models/__main__.py +13 -0
- empathy_os/models/cli.py +655 -0
- empathy_os/models/empathy_executor.py +354 -0
- empathy_os/models/executor.py +252 -0
- empathy_os/models/fallback.py +671 -0
- empathy_os/models/provider_config.py +563 -0
- empathy_os/models/registry.py +382 -0
- empathy_os/models/tasks.py +302 -0
- empathy_os/models/telemetry.py +548 -0
- empathy_os/models/token_estimator.py +378 -0
- empathy_os/models/validation.py +274 -0
- empathy_os/monitoring/__init__.py +52 -0
- empathy_os/monitoring/alerts.py +23 -0
- empathy_os/monitoring/alerts_cli.py +268 -0
- empathy_os/monitoring/multi_backend.py +271 -0
- empathy_os/monitoring/otel_backend.py +363 -0
- empathy_os/optimization/__init__.py +19 -0
- empathy_os/optimization/context_optimizer.py +272 -0
- empathy_os/pattern_library.py +30 -29
- empathy_os/persistence.py +35 -37
- empathy_os/platform_utils.py +261 -0
- empathy_os/plugins/__init__.py +28 -0
- empathy_os/plugins/base.py +361 -0
- empathy_os/plugins/registry.py +268 -0
- empathy_os/project_index/__init__.py +30 -0
- empathy_os/project_index/cli.py +335 -0
- empathy_os/project_index/crew_integration.py +430 -0
- empathy_os/project_index/index.py +425 -0
- empathy_os/project_index/models.py +501 -0
- empathy_os/project_index/reports.py +473 -0
- empathy_os/project_index/scanner.py +538 -0
- empathy_os/prompts/__init__.py +61 -0
- empathy_os/prompts/config.py +77 -0
- empathy_os/prompts/context.py +177 -0
- empathy_os/prompts/parser.py +285 -0
- empathy_os/prompts/registry.py +313 -0
- empathy_os/prompts/templates.py +208 -0
- empathy_os/redis_config.py +144 -58
- empathy_os/redis_memory.py +79 -77
- empathy_os/resilience/__init__.py +56 -0
- empathy_os/resilience/circuit_breaker.py +256 -0
- empathy_os/resilience/fallback.py +179 -0
- empathy_os/resilience/health.py +300 -0
- empathy_os/resilience/retry.py +209 -0
- empathy_os/resilience/timeout.py +135 -0
- empathy_os/routing/__init__.py +43 -0
- empathy_os/routing/chain_executor.py +433 -0
- empathy_os/routing/classifier.py +217 -0
- empathy_os/routing/smart_router.py +234 -0
- empathy_os/routing/wizard_registry.py +307 -0
- empathy_os/templates.py +19 -14
- empathy_os/trust/__init__.py +28 -0
- empathy_os/trust/circuit_breaker.py +579 -0
- empathy_os/trust_building.py +67 -58
- empathy_os/validation/__init__.py +19 -0
- empathy_os/validation/xml_validator.py +281 -0
- empathy_os/wizard_factory_cli.py +170 -0
- empathy_os/{workflows.py → workflow_commands.py} +131 -37
- empathy_os/workflows/__init__.py +360 -0
- empathy_os/workflows/base.py +1660 -0
- empathy_os/workflows/bug_predict.py +962 -0
- empathy_os/workflows/code_review.py +960 -0
- empathy_os/workflows/code_review_adapters.py +310 -0
- empathy_os/workflows/code_review_pipeline.py +720 -0
- empathy_os/workflows/config.py +600 -0
- empathy_os/workflows/dependency_check.py +648 -0
- empathy_os/workflows/document_gen.py +1069 -0
- empathy_os/workflows/documentation_orchestrator.py +1205 -0
- empathy_os/workflows/health_check.py +679 -0
- empathy_os/workflows/keyboard_shortcuts/__init__.py +39 -0
- empathy_os/workflows/keyboard_shortcuts/generators.py +386 -0
- empathy_os/workflows/keyboard_shortcuts/parsers.py +414 -0
- empathy_os/workflows/keyboard_shortcuts/prompts.py +295 -0
- empathy_os/workflows/keyboard_shortcuts/schema.py +193 -0
- empathy_os/workflows/keyboard_shortcuts/workflow.py +505 -0
- empathy_os/workflows/manage_documentation.py +804 -0
- empathy_os/workflows/new_sample_workflow1.py +146 -0
- empathy_os/workflows/new_sample_workflow1_README.md +150 -0
- empathy_os/workflows/perf_audit.py +687 -0
- empathy_os/workflows/pr_review.py +748 -0
- empathy_os/workflows/progress.py +445 -0
- empathy_os/workflows/progress_server.py +322 -0
- empathy_os/workflows/refactor_plan.py +693 -0
- empathy_os/workflows/release_prep.py +808 -0
- empathy_os/workflows/research_synthesis.py +404 -0
- empathy_os/workflows/secure_release.py +585 -0
- empathy_os/workflows/security_adapters.py +297 -0
- empathy_os/workflows/security_audit.py +1046 -0
- empathy_os/workflows/step_config.py +234 -0
- empathy_os/workflows/test5.py +125 -0
- empathy_os/workflows/test5_README.md +158 -0
- empathy_os/workflows/test_gen.py +1855 -0
- empathy_os/workflows/test_lifecycle.py +526 -0
- empathy_os/workflows/test_maintenance.py +626 -0
- empathy_os/workflows/test_maintenance_cli.py +590 -0
- empathy_os/workflows/test_maintenance_crew.py +821 -0
- empathy_os/workflows/xml_enhanced_crew.py +285 -0
- empathy_software_plugin/__init__.py +1 -2
- empathy_software_plugin/cli/__init__.py +120 -0
- empathy_software_plugin/cli/inspect.py +362 -0
- empathy_software_plugin/cli.py +49 -27
- empathy_software_plugin/plugin.py +4 -8
- empathy_software_plugin/wizards/__init__.py +42 -0
- empathy_software_plugin/wizards/advanced_debugging_wizard.py +392 -0
- empathy_software_plugin/wizards/agent_orchestration_wizard.py +511 -0
- empathy_software_plugin/wizards/ai_collaboration_wizard.py +503 -0
- empathy_software_plugin/wizards/ai_context_wizard.py +441 -0
- empathy_software_plugin/wizards/ai_documentation_wizard.py +503 -0
- empathy_software_plugin/wizards/base_wizard.py +288 -0
- empathy_software_plugin/wizards/book_chapter_wizard.py +519 -0
- empathy_software_plugin/wizards/code_review_wizard.py +606 -0
- empathy_software_plugin/wizards/debugging/__init__.py +50 -0
- empathy_software_plugin/wizards/debugging/bug_risk_analyzer.py +414 -0
- empathy_software_plugin/wizards/debugging/config_loaders.py +442 -0
- empathy_software_plugin/wizards/debugging/fix_applier.py +469 -0
- empathy_software_plugin/wizards/debugging/language_patterns.py +383 -0
- empathy_software_plugin/wizards/debugging/linter_parsers.py +470 -0
- empathy_software_plugin/wizards/debugging/verification.py +369 -0
- empathy_software_plugin/wizards/enhanced_testing_wizard.py +537 -0
- empathy_software_plugin/wizards/memory_enhanced_debugging_wizard.py +816 -0
- empathy_software_plugin/wizards/multi_model_wizard.py +501 -0
- empathy_software_plugin/wizards/pattern_extraction_wizard.py +422 -0
- empathy_software_plugin/wizards/pattern_retriever_wizard.py +400 -0
- empathy_software_plugin/wizards/performance/__init__.py +9 -0
- empathy_software_plugin/wizards/performance/bottleneck_detector.py +221 -0
- empathy_software_plugin/wizards/performance/profiler_parsers.py +278 -0
- empathy_software_plugin/wizards/performance/trajectory_analyzer.py +429 -0
- empathy_software_plugin/wizards/performance_profiling_wizard.py +305 -0
- empathy_software_plugin/wizards/prompt_engineering_wizard.py +425 -0
- empathy_software_plugin/wizards/rag_pattern_wizard.py +461 -0
- empathy_software_plugin/wizards/security/__init__.py +32 -0
- empathy_software_plugin/wizards/security/exploit_analyzer.py +290 -0
- empathy_software_plugin/wizards/security/owasp_patterns.py +241 -0
- empathy_software_plugin/wizards/security/vulnerability_scanner.py +604 -0
- empathy_software_plugin/wizards/security_analysis_wizard.py +322 -0
- empathy_software_plugin/wizards/security_learning_wizard.py +740 -0
- empathy_software_plugin/wizards/tech_debt_wizard.py +726 -0
- empathy_software_plugin/wizards/testing/__init__.py +27 -0
- empathy_software_plugin/wizards/testing/coverage_analyzer.py +459 -0
- empathy_software_plugin/wizards/testing/quality_analyzer.py +531 -0
- empathy_software_plugin/wizards/testing/test_suggester.py +533 -0
- empathy_software_plugin/wizards/testing_wizard.py +274 -0
- hot_reload/README.md +473 -0
- hot_reload/__init__.py +62 -0
- hot_reload/config.py +84 -0
- hot_reload/integration.py +228 -0
- hot_reload/reloader.py +298 -0
- hot_reload/watcher.py +179 -0
- hot_reload/websocket.py +176 -0
- scaffolding/README.md +589 -0
- scaffolding/__init__.py +35 -0
- scaffolding/__main__.py +14 -0
- scaffolding/cli.py +240 -0
- test_generator/__init__.py +38 -0
- test_generator/__main__.py +14 -0
- test_generator/cli.py +226 -0
- test_generator/generator.py +325 -0
- test_generator/risk_analyzer.py +216 -0
- workflow_patterns/__init__.py +33 -0
- workflow_patterns/behavior.py +249 -0
- workflow_patterns/core.py +76 -0
- workflow_patterns/output.py +99 -0
- workflow_patterns/registry.py +255 -0
- workflow_patterns/structural.py +288 -0
- workflow_scaffolding/__init__.py +11 -0
- workflow_scaffolding/__main__.py +12 -0
- workflow_scaffolding/cli.py +206 -0
- workflow_scaffolding/generator.py +265 -0
- agents/code_inspection/patterns/inspection/recurring_B112.json +0 -18
- agents/code_inspection/patterns/inspection/recurring_F541.json +0 -16
- agents/code_inspection/patterns/inspection/recurring_FORMAT.json +0 -25
- agents/code_inspection/patterns/inspection/recurring_bug_20250822_def456.json +0 -16
- agents/code_inspection/patterns/inspection/recurring_bug_20250915_abc123.json +0 -16
- agents/code_inspection/patterns/inspection/recurring_bug_20251212_3c5b9951.json +0 -16
- agents/code_inspection/patterns/inspection/recurring_bug_20251212_97c0f72f.json +0 -16
- agents/code_inspection/patterns/inspection/recurring_bug_20251212_a0871d53.json +0 -16
- agents/code_inspection/patterns/inspection/recurring_bug_20251212_a9b6ec41.json +0 -16
- agents/code_inspection/patterns/inspection/recurring_bug_null_001.json +0 -16
- agents/code_inspection/patterns/inspection/recurring_builtin.json +0 -16
- agents/compliance_anticipation_agent.py +0 -1427
- agents/epic_integration_wizard.py +0 -541
- agents/trust_building_behaviors.py +0 -891
- empathy_framework-2.4.0.dist-info/METADATA +0 -485
- empathy_framework-2.4.0.dist-info/RECORD +0 -102
- empathy_framework-2.4.0.dist-info/entry_points.txt +0 -6
- empathy_llm_toolkit/htmlcov/status.json +0 -1
- empathy_llm_toolkit/security/htmlcov/status.json +0 -1
- {empathy_framework-2.4.0.dist-info → empathy_framework-3.8.2.dist-info}/WHEEL +0 -0
- {empathy_framework-2.4.0.dist-info → empathy_framework-3.8.2.dist-info}/licenses/LICENSE +0 -0
empathy_os/pattern_library.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Pattern Library for Multi-Agent Collaboration
|
|
1
|
+
"""Pattern Library for Multi-Agent Collaboration
|
|
3
2
|
|
|
4
3
|
Enables AI agents to share discovered patterns with each other, accelerating
|
|
5
4
|
learning across the agent collective (Level 5: Systems Empathy).
|
|
@@ -17,8 +16,7 @@ from typing import Any
|
|
|
17
16
|
|
|
18
17
|
@dataclass
|
|
19
18
|
class Pattern:
|
|
20
|
-
"""
|
|
21
|
-
A discovered pattern that can be shared across AI agents
|
|
19
|
+
"""A discovered pattern that can be shared across AI agents
|
|
22
20
|
|
|
23
21
|
Patterns represent reusable solutions, common behaviors, or
|
|
24
22
|
learned heuristics that one agent discovered and others can benefit from.
|
|
@@ -27,6 +25,7 @@ class Pattern:
|
|
|
27
25
|
- Sequential patterns: "After action X, users typically need Y"
|
|
28
26
|
- Temporal patterns: "On Mondays, prioritize Z"
|
|
29
27
|
- Conditional patterns: "If context A, then approach B works best"
|
|
28
|
+
|
|
30
29
|
"""
|
|
31
30
|
|
|
32
31
|
id: str
|
|
@@ -76,8 +75,7 @@ class PatternMatch:
|
|
|
76
75
|
|
|
77
76
|
|
|
78
77
|
class PatternLibrary:
|
|
79
|
-
"""
|
|
80
|
-
Shared library for multi-agent pattern discovery and sharing
|
|
78
|
+
"""Shared library for multi-agent pattern discovery and sharing
|
|
81
79
|
|
|
82
80
|
Enables Level 5 Systems Empathy: AI-AI cooperation where one agent's
|
|
83
81
|
discovery benefits all agents in the collective.
|
|
@@ -112,6 +110,7 @@ class PatternLibrary:
|
|
|
112
110
|
>>> context = {"recent_event": "system_update", "user_confusion": True}
|
|
113
111
|
>>> matches = library.query_patterns("documentation_agent", context)
|
|
114
112
|
>>> print(f"Found {len(matches)} relevant patterns")
|
|
113
|
+
|
|
115
114
|
"""
|
|
116
115
|
|
|
117
116
|
def __init__(self):
|
|
@@ -121,8 +120,7 @@ class PatternLibrary:
|
|
|
121
120
|
self.pattern_graph: dict[str, list[str]] = {} # pattern_id -> related_pattern_ids
|
|
122
121
|
|
|
123
122
|
def contribute_pattern(self, agent_id: str, pattern: Pattern) -> None:
|
|
124
|
-
"""
|
|
125
|
-
Agent contributes a discovered pattern to the library
|
|
123
|
+
"""Agent contributes a discovered pattern to the library
|
|
126
124
|
|
|
127
125
|
Args:
|
|
128
126
|
agent_id: ID of contributing agent
|
|
@@ -134,10 +132,11 @@ class PatternLibrary:
|
|
|
134
132
|
... agent_id="agent_1",
|
|
135
133
|
... pattern_type="conditional",
|
|
136
134
|
... name="High-stakes decision pattern",
|
|
137
|
-
... description="For high-stakes decisions, provide
|
|
135
|
+
... description="For high-stakes decisions, provide options with tradeoffs",
|
|
138
136
|
... confidence=0.9
|
|
139
137
|
... )
|
|
140
138
|
>>> library.contribute_pattern("agent_1", pattern)
|
|
139
|
+
|
|
141
140
|
"""
|
|
142
141
|
# Store pattern
|
|
143
142
|
self.patterns[pattern.id] = pattern
|
|
@@ -159,8 +158,7 @@ class PatternLibrary:
|
|
|
159
158
|
min_confidence: float = 0.5,
|
|
160
159
|
limit: int = 10,
|
|
161
160
|
) -> list[PatternMatch]:
|
|
162
|
-
"""
|
|
163
|
-
Query relevant patterns for current context
|
|
161
|
+
"""Query relevant patterns for current context
|
|
164
162
|
|
|
165
163
|
Args:
|
|
166
164
|
agent_id: ID of querying agent
|
|
@@ -179,6 +177,7 @@ class PatternLibrary:
|
|
|
179
177
|
... "time_of_day": "morning"
|
|
180
178
|
... }
|
|
181
179
|
>>> matches = library.query_patterns("debug_agent", context, min_confidence=0.7)
|
|
180
|
+
|
|
182
181
|
"""
|
|
183
182
|
matches: list[PatternMatch] = []
|
|
184
183
|
|
|
@@ -199,7 +198,7 @@ class PatternLibrary:
|
|
|
199
198
|
pattern=pattern,
|
|
200
199
|
relevance_score=relevance_score,
|
|
201
200
|
matching_factors=matching_factors,
|
|
202
|
-
)
|
|
201
|
+
),
|
|
203
202
|
)
|
|
204
203
|
|
|
205
204
|
# Sort by relevance and limit
|
|
@@ -207,40 +206,40 @@ class PatternLibrary:
|
|
|
207
206
|
return matches[:limit]
|
|
208
207
|
|
|
209
208
|
def get_pattern(self, pattern_id: str) -> Pattern | None:
|
|
210
|
-
"""
|
|
211
|
-
Get a specific pattern by ID
|
|
209
|
+
"""Get a specific pattern by ID
|
|
212
210
|
|
|
213
211
|
Args:
|
|
214
212
|
pattern_id: Pattern identifier
|
|
215
213
|
|
|
216
214
|
Returns:
|
|
217
215
|
Pattern if found, None otherwise
|
|
216
|
+
|
|
218
217
|
"""
|
|
219
218
|
return self.patterns.get(pattern_id)
|
|
220
219
|
|
|
221
220
|
def record_pattern_outcome(self, pattern_id: str, success: bool):
|
|
222
|
-
"""
|
|
223
|
-
Record outcome of using a pattern
|
|
221
|
+
"""Record outcome of using a pattern
|
|
224
222
|
|
|
225
223
|
Updates pattern statistics to improve future recommendations.
|
|
226
224
|
|
|
227
225
|
Args:
|
|
228
226
|
pattern_id: ID of pattern that was used
|
|
229
227
|
success: Whether using the pattern was successful
|
|
228
|
+
|
|
230
229
|
"""
|
|
231
230
|
pattern = self.patterns.get(pattern_id)
|
|
232
231
|
if pattern:
|
|
233
232
|
pattern.record_usage(success)
|
|
234
233
|
|
|
235
234
|
def link_patterns(self, pattern_id_1: str, pattern_id_2: str):
|
|
236
|
-
"""
|
|
237
|
-
Create a link between related patterns
|
|
235
|
+
"""Create a link between related patterns
|
|
238
236
|
|
|
239
237
|
Helps agents discover complementary patterns.
|
|
240
238
|
|
|
241
239
|
Args:
|
|
242
240
|
pattern_id_1: First pattern ID
|
|
243
241
|
pattern_id_2: Second pattern ID
|
|
242
|
+
|
|
244
243
|
"""
|
|
245
244
|
if pattern_id_1 in self.pattern_graph:
|
|
246
245
|
if pattern_id_2 not in self.pattern_graph[pattern_id_1]:
|
|
@@ -251,8 +250,7 @@ class PatternLibrary:
|
|
|
251
250
|
self.pattern_graph[pattern_id_2].append(pattern_id_1)
|
|
252
251
|
|
|
253
252
|
def get_related_patterns(self, pattern_id: str, depth: int = 1) -> list[Pattern]:
|
|
254
|
-
"""
|
|
255
|
-
Get patterns related to a given pattern
|
|
253
|
+
"""Get patterns related to a given pattern
|
|
256
254
|
|
|
257
255
|
Args:
|
|
258
256
|
pattern_id: Source pattern ID
|
|
@@ -260,6 +258,7 @@ class PatternLibrary:
|
|
|
260
258
|
|
|
261
259
|
Returns:
|
|
262
260
|
List of related patterns
|
|
261
|
+
|
|
263
262
|
"""
|
|
264
263
|
if depth <= 0 or pattern_id not in self.pattern_graph:
|
|
265
264
|
return []
|
|
@@ -278,21 +277,20 @@ class PatternLibrary:
|
|
|
278
277
|
return [self.patterns[pid] for pid in related_ids if pid in self.patterns]
|
|
279
278
|
|
|
280
279
|
def get_agent_patterns(self, agent_id: str) -> list[Pattern]:
|
|
281
|
-
"""
|
|
282
|
-
Get all patterns contributed by a specific agent
|
|
280
|
+
"""Get all patterns contributed by a specific agent
|
|
283
281
|
|
|
284
282
|
Args:
|
|
285
283
|
agent_id: Agent identifier
|
|
286
284
|
|
|
287
285
|
Returns:
|
|
288
286
|
List of patterns from this agent
|
|
287
|
+
|
|
289
288
|
"""
|
|
290
289
|
pattern_ids = self.agent_contributions.get(agent_id, [])
|
|
291
290
|
return [self.patterns[pid] for pid in pattern_ids if pid in self.patterns]
|
|
292
291
|
|
|
293
292
|
def get_top_patterns(self, n: int = 10, sort_by: str = "success_rate") -> list[Pattern]:
|
|
294
|
-
"""
|
|
295
|
-
Get top N patterns by specified metric
|
|
293
|
+
"""Get top N patterns by specified metric
|
|
296
294
|
|
|
297
295
|
Args:
|
|
298
296
|
n: Number of patterns to return
|
|
@@ -300,6 +298,7 @@ class PatternLibrary:
|
|
|
300
298
|
|
|
301
299
|
Returns:
|
|
302
300
|
Top N patterns
|
|
301
|
+
|
|
303
302
|
"""
|
|
304
303
|
patterns = list(self.patterns.values())
|
|
305
304
|
|
|
@@ -313,11 +312,11 @@ class PatternLibrary:
|
|
|
313
312
|
return patterns[:n]
|
|
314
313
|
|
|
315
314
|
def get_library_stats(self) -> dict[str, Any]:
|
|
316
|
-
"""
|
|
317
|
-
Get statistics about the pattern library
|
|
315
|
+
"""Get statistics about the pattern library
|
|
318
316
|
|
|
319
317
|
Returns:
|
|
320
318
|
Dict with library statistics
|
|
319
|
+
|
|
321
320
|
"""
|
|
322
321
|
if not self.patterns:
|
|
323
322
|
return {
|
|
@@ -350,13 +349,15 @@ class PatternLibrary:
|
|
|
350
349
|
}
|
|
351
350
|
|
|
352
351
|
def _calculate_relevance(
|
|
353
|
-
self,
|
|
352
|
+
self,
|
|
353
|
+
pattern: Pattern,
|
|
354
|
+
context: dict[str, Any],
|
|
354
355
|
) -> tuple[float, list[str]]:
|
|
355
|
-
"""
|
|
356
|
-
Calculate how relevant a pattern is to current context
|
|
356
|
+
"""Calculate how relevant a pattern is to current context
|
|
357
357
|
|
|
358
358
|
Returns:
|
|
359
359
|
(relevance_score, matching_factors)
|
|
360
|
+
|
|
360
361
|
"""
|
|
361
362
|
relevance = 0.0
|
|
362
363
|
matching_factors = []
|
empathy_os/persistence.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Persistence Layer for Empathy Framework
|
|
1
|
+
"""Persistence Layer for Empathy Framework
|
|
3
2
|
|
|
4
3
|
Provides:
|
|
5
4
|
- Pattern library save/load (JSON, SQLite)
|
|
@@ -14,14 +13,14 @@ import json
|
|
|
14
13
|
import sqlite3
|
|
15
14
|
from datetime import datetime
|
|
16
15
|
from pathlib import Path
|
|
16
|
+
from typing import Any
|
|
17
17
|
|
|
18
18
|
from .core import CollaborationState
|
|
19
19
|
from .pattern_library import Pattern, PatternLibrary
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class PatternPersistence:
|
|
23
|
-
"""
|
|
24
|
-
Save and load PatternLibrary to/from files
|
|
23
|
+
"""Save and load PatternLibrary to/from files
|
|
25
24
|
|
|
26
25
|
Supports:
|
|
27
26
|
- JSON format (human-readable, good for backups)
|
|
@@ -30,8 +29,7 @@ class PatternPersistence:
|
|
|
30
29
|
|
|
31
30
|
@staticmethod
|
|
32
31
|
def save_to_json(library: PatternLibrary, filepath: str):
|
|
33
|
-
"""
|
|
34
|
-
Save pattern library to JSON file
|
|
32
|
+
"""Save pattern library to JSON file
|
|
35
33
|
|
|
36
34
|
Args:
|
|
37
35
|
library: PatternLibrary instance to save
|
|
@@ -40,9 +38,11 @@ class PatternPersistence:
|
|
|
40
38
|
Example:
|
|
41
39
|
>>> library = PatternLibrary()
|
|
42
40
|
>>> PatternPersistence.save_to_json(library, "patterns.json")
|
|
41
|
+
|
|
43
42
|
"""
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
patterns_list: list[dict[str, Any]] = []
|
|
44
|
+
data: dict[str, Any] = {
|
|
45
|
+
"patterns": patterns_list,
|
|
46
46
|
"agent_contributions": library.agent_contributions,
|
|
47
47
|
"metadata": {
|
|
48
48
|
"saved_at": datetime.now().isoformat(),
|
|
@@ -53,7 +53,7 @@ class PatternPersistence:
|
|
|
53
53
|
|
|
54
54
|
# Serialize each pattern
|
|
55
55
|
for _pattern_id, pattern in library.patterns.items():
|
|
56
|
-
|
|
56
|
+
patterns_list.append(
|
|
57
57
|
{
|
|
58
58
|
"id": pattern.id,
|
|
59
59
|
"agent_id": pattern.agent_id,
|
|
@@ -69,7 +69,7 @@ class PatternPersistence:
|
|
|
69
69
|
"tags": pattern.tags,
|
|
70
70
|
"discovered_at": pattern.discovered_at.isoformat(),
|
|
71
71
|
"last_used": pattern.last_used.isoformat() if pattern.last_used else None,
|
|
72
|
-
}
|
|
72
|
+
},
|
|
73
73
|
)
|
|
74
74
|
|
|
75
75
|
# Write to file
|
|
@@ -78,8 +78,7 @@ class PatternPersistence:
|
|
|
78
78
|
|
|
79
79
|
@staticmethod
|
|
80
80
|
def load_from_json(filepath: str) -> PatternLibrary:
|
|
81
|
-
"""
|
|
82
|
-
Load pattern library from JSON file
|
|
81
|
+
"""Load pattern library from JSON file
|
|
83
82
|
|
|
84
83
|
Args:
|
|
85
84
|
filepath: Path to JSON file
|
|
@@ -93,6 +92,7 @@ class PatternPersistence:
|
|
|
93
92
|
|
|
94
93
|
Example:
|
|
95
94
|
>>> library = PatternPersistence.load_from_json("patterns.json")
|
|
95
|
+
|
|
96
96
|
"""
|
|
97
97
|
with open(filepath) as f:
|
|
98
98
|
data = json.load(f)
|
|
@@ -130,8 +130,7 @@ class PatternPersistence:
|
|
|
130
130
|
|
|
131
131
|
@staticmethod
|
|
132
132
|
def save_to_sqlite(library: PatternLibrary, db_path: str):
|
|
133
|
-
"""
|
|
134
|
-
Save pattern library to SQLite database
|
|
133
|
+
"""Save pattern library to SQLite database
|
|
135
134
|
|
|
136
135
|
Args:
|
|
137
136
|
library: PatternLibrary instance to save
|
|
@@ -144,6 +143,7 @@ class PatternPersistence:
|
|
|
144
143
|
Example:
|
|
145
144
|
>>> library = PatternLibrary()
|
|
146
145
|
>>> PatternPersistence.save_to_sqlite(library, "patterns.db")
|
|
146
|
+
|
|
147
147
|
"""
|
|
148
148
|
conn = sqlite3.connect(db_path)
|
|
149
149
|
cursor = conn.cursor()
|
|
@@ -168,7 +168,7 @@ class PatternPersistence:
|
|
|
168
168
|
last_used TIMESTAMP,
|
|
169
169
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
170
170
|
)
|
|
171
|
-
"""
|
|
171
|
+
""",
|
|
172
172
|
)
|
|
173
173
|
|
|
174
174
|
cursor.execute(
|
|
@@ -181,7 +181,7 @@ class PatternPersistence:
|
|
|
181
181
|
used_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
182
182
|
FOREIGN KEY (pattern_id) REFERENCES patterns(id)
|
|
183
183
|
)
|
|
184
|
-
"""
|
|
184
|
+
""",
|
|
185
185
|
)
|
|
186
186
|
|
|
187
187
|
# Insert or update patterns
|
|
@@ -217,8 +217,7 @@ class PatternPersistence:
|
|
|
217
217
|
|
|
218
218
|
@staticmethod
|
|
219
219
|
def load_from_sqlite(db_path: str) -> PatternLibrary:
|
|
220
|
-
"""
|
|
221
|
-
Load pattern library from SQLite database
|
|
220
|
+
"""Load pattern library from SQLite database
|
|
222
221
|
|
|
223
222
|
Args:
|
|
224
223
|
db_path: Path to SQLite database file
|
|
@@ -228,6 +227,7 @@ class PatternPersistence:
|
|
|
228
227
|
|
|
229
228
|
Example:
|
|
230
229
|
>>> library = PatternPersistence.load_from_sqlite("patterns.db")
|
|
230
|
+
|
|
231
231
|
"""
|
|
232
232
|
conn = sqlite3.connect(db_path)
|
|
233
233
|
conn.row_factory = sqlite3.Row # Access columns by name
|
|
@@ -263,8 +263,7 @@ class PatternPersistence:
|
|
|
263
263
|
|
|
264
264
|
|
|
265
265
|
class StateManager:
|
|
266
|
-
"""
|
|
267
|
-
Persist collaboration state across sessions
|
|
266
|
+
"""Persist collaboration state across sessions
|
|
268
267
|
|
|
269
268
|
Enables:
|
|
270
269
|
- Long-term trust tracking
|
|
@@ -277,8 +276,7 @@ class StateManager:
|
|
|
277
276
|
self.storage_path.mkdir(exist_ok=True, parents=True)
|
|
278
277
|
|
|
279
278
|
def save_state(self, user_id: str, state: CollaborationState):
|
|
280
|
-
"""
|
|
281
|
-
Save user's collaboration state to JSON
|
|
279
|
+
"""Save user's collaboration state to JSON
|
|
282
280
|
|
|
283
281
|
Args:
|
|
284
282
|
user_id: User identifier
|
|
@@ -287,6 +285,7 @@ class StateManager:
|
|
|
287
285
|
Example:
|
|
288
286
|
>>> manager = StateManager()
|
|
289
287
|
>>> manager.save_state("user123", empathy.collaboration_state)
|
|
288
|
+
|
|
290
289
|
"""
|
|
291
290
|
filepath = self.storage_path / f"{user_id}.json"
|
|
292
291
|
|
|
@@ -306,8 +305,7 @@ class StateManager:
|
|
|
306
305
|
json.dump(data, f, indent=2)
|
|
307
306
|
|
|
308
307
|
def load_state(self, user_id: str) -> CollaborationState | None:
|
|
309
|
-
"""
|
|
310
|
-
Load user's previous state
|
|
308
|
+
"""Load user's previous state
|
|
311
309
|
|
|
312
310
|
Args:
|
|
313
311
|
user_id: User identifier
|
|
@@ -321,6 +319,7 @@ class StateManager:
|
|
|
321
319
|
>>> if state:
|
|
322
320
|
... empathy = EmpathyOS(user_id="user123", target_level=4)
|
|
323
321
|
... empathy.collaboration_state = state
|
|
322
|
+
|
|
324
323
|
"""
|
|
325
324
|
filepath = self.storage_path / f"{user_id}.json"
|
|
326
325
|
|
|
@@ -347,8 +346,7 @@ class StateManager:
|
|
|
347
346
|
return None
|
|
348
347
|
|
|
349
348
|
def list_users(self) -> list[str]:
|
|
350
|
-
"""
|
|
351
|
-
List all users with saved state
|
|
349
|
+
"""List all users with saved state
|
|
352
350
|
|
|
353
351
|
Returns:
|
|
354
352
|
List of user IDs
|
|
@@ -357,12 +355,12 @@ class StateManager:
|
|
|
357
355
|
>>> manager = StateManager()
|
|
358
356
|
>>> users = manager.list_users()
|
|
359
357
|
>>> print(f"Found {len(users)} users")
|
|
358
|
+
|
|
360
359
|
"""
|
|
361
360
|
return [p.stem for p in self.storage_path.glob("*.json")]
|
|
362
361
|
|
|
363
362
|
def delete_state(self, user_id: str) -> bool:
|
|
364
|
-
"""
|
|
365
|
-
Delete user's saved state
|
|
363
|
+
"""Delete user's saved state
|
|
366
364
|
|
|
367
365
|
Args:
|
|
368
366
|
user_id: User identifier
|
|
@@ -373,6 +371,7 @@ class StateManager:
|
|
|
373
371
|
Example:
|
|
374
372
|
>>> manager = StateManager()
|
|
375
373
|
>>> deleted = manager.delete_state("user123")
|
|
374
|
+
|
|
376
375
|
"""
|
|
377
376
|
filepath = self.storage_path / f"{user_id}.json"
|
|
378
377
|
|
|
@@ -383,8 +382,7 @@ class StateManager:
|
|
|
383
382
|
|
|
384
383
|
|
|
385
384
|
class MetricsCollector:
|
|
386
|
-
"""
|
|
387
|
-
Collect and persist empathy framework metrics
|
|
385
|
+
"""Collect and persist empathy framework metrics
|
|
388
386
|
|
|
389
387
|
Tracks:
|
|
390
388
|
- Empathy level usage
|
|
@@ -413,21 +411,21 @@ class MetricsCollector:
|
|
|
413
411
|
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
414
412
|
metadata TEXT
|
|
415
413
|
)
|
|
416
|
-
"""
|
|
414
|
+
""",
|
|
417
415
|
)
|
|
418
416
|
|
|
419
417
|
cursor.execute(
|
|
420
418
|
"""
|
|
421
419
|
CREATE INDEX IF NOT EXISTS idx_user_level
|
|
422
420
|
ON metrics(user_id, empathy_level)
|
|
423
|
-
"""
|
|
421
|
+
""",
|
|
424
422
|
)
|
|
425
423
|
|
|
426
424
|
cursor.execute(
|
|
427
425
|
"""
|
|
428
426
|
CREATE INDEX IF NOT EXISTS idx_timestamp
|
|
429
427
|
ON metrics(timestamp)
|
|
430
|
-
"""
|
|
428
|
+
""",
|
|
431
429
|
)
|
|
432
430
|
|
|
433
431
|
conn.commit()
|
|
@@ -441,8 +439,7 @@ class MetricsCollector:
|
|
|
441
439
|
response_time_ms: float,
|
|
442
440
|
metadata: dict | None = None,
|
|
443
441
|
):
|
|
444
|
-
"""
|
|
445
|
-
Record a single metric event
|
|
442
|
+
"""Record a single metric event
|
|
446
443
|
|
|
447
444
|
Args:
|
|
448
445
|
user_id: User identifier
|
|
@@ -460,6 +457,7 @@ class MetricsCollector:
|
|
|
460
457
|
... response_time_ms=250.5,
|
|
461
458
|
... metadata={"bottlenecks_predicted": 3}
|
|
462
459
|
... )
|
|
460
|
+
|
|
463
461
|
"""
|
|
464
462
|
conn = sqlite3.connect(self.db_path)
|
|
465
463
|
cursor = conn.cursor()
|
|
@@ -483,8 +481,7 @@ class MetricsCollector:
|
|
|
483
481
|
conn.close()
|
|
484
482
|
|
|
485
483
|
def get_user_stats(self, user_id: str) -> dict:
|
|
486
|
-
"""
|
|
487
|
-
Get aggregated statistics for a user
|
|
484
|
+
"""Get aggregated statistics for a user
|
|
488
485
|
|
|
489
486
|
Args:
|
|
490
487
|
user_id: User identifier
|
|
@@ -496,6 +493,7 @@ class MetricsCollector:
|
|
|
496
493
|
>>> collector = MetricsCollector()
|
|
497
494
|
>>> stats = collector.get_user_stats("user123")
|
|
498
495
|
>>> print(f"Success rate: {stats['success_rate']:.1%}")
|
|
496
|
+
|
|
499
497
|
"""
|
|
500
498
|
conn = sqlite3.connect(self.db_path)
|
|
501
499
|
conn.row_factory = sqlite3.Row
|