adaptive-memory-multi-model-router 1.2.2 → 1.3.1
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.
- package/LICENSE +21 -0
- package/README.md +146 -66
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/integrations/airtable.js +20 -0
- package/dist/integrations/discord.js +18 -0
- package/dist/integrations/github.js +23 -0
- package/dist/integrations/gmail.js +19 -0
- package/dist/integrations/google-calendar.js +18 -0
- package/dist/integrations/index.js +61 -0
- package/dist/integrations/jira.js +21 -0
- package/dist/integrations/linear.js +19 -0
- package/dist/integrations/notion.js +19 -0
- package/dist/integrations/slack.js +18 -0
- package/dist/integrations/telegram.js +19 -0
- package/dist/providers/registry.js +7 -3
- package/docs/ARCHITECTURAL-IMPROVEMENTS-2025.md +1391 -0
- package/docs/ARCHITECTURAL-IMPROVEMENTS-REVISED-2025.md +1051 -0
- package/docs/CONFIGURATION.md +476 -0
- package/docs/COUNCIL_DECISION.json +308 -0
- package/docs/COUNCIL_SUMMARY.md +265 -0
- package/docs/COUNCIL_V2.2_DECISION.md +416 -0
- package/docs/IMPROVEMENT_ROADMAP.md +515 -0
- package/docs/LLM_COUNCIL_DECISION.md +508 -0
- package/docs/QUICK_START_VISIBILITY.md +782 -0
- package/docs/REDDIT_GAP_ANALYSIS.md +299 -0
- package/docs/RESEARCH_BACKED_IMPROVEMENTS.md +1180 -0
- package/docs/TMLPD_QNA.md +751 -0
- package/docs/TMLPD_V2.1_COMPLETE.md +763 -0
- package/docs/TMLPD_V2.2_RESEARCH_ROADMAP.md +754 -0
- package/docs/V2.2_IMPLEMENTATION_COMPLETE.md +446 -0
- package/docs/V2_IMPLEMENTATION_GUIDE.md +388 -0
- package/docs/VISIBILITY_ADOPTION_PLAN.md +1005 -0
- package/docs/launch-content/LAUNCH_EXECUTION_CHECKLIST.md +421 -0
- package/docs/launch-content/README.md +457 -0
- package/docs/launch-content/assets/cost_comparison_100_tasks.png +0 -0
- package/docs/launch-content/assets/cumulative_savings.png +0 -0
- package/docs/launch-content/assets/parallel_speedup.png +0 -0
- package/docs/launch-content/assets/provider_pricing_comparison.png +0 -0
- package/docs/launch-content/assets/task_breakdown_comparison.png +0 -0
- package/docs/launch-content/generate_charts.py +313 -0
- package/docs/launch-content/hn_show_post.md +139 -0
- package/docs/launch-content/partner_outreach_templates.md +745 -0
- package/docs/launch-content/reddit_posts.md +467 -0
- package/docs/launch-content/twitter_thread.txt +460 -0
- package/examples/QUICKSTART.md +1 -1
- package/openclaw-alexa-bridge/ALL_REMAINING_FIXES_PLAN.md +313 -0
- package/openclaw-alexa-bridge/REMAINING_FIXES_SUMMARY.md +277 -0
- package/openclaw-alexa-bridge/src/alexa_handler_no_tmlpd.js +1234 -0
- package/openclaw-alexa-bridge/test_fixes.js +77 -0
- package/package.json +120 -29
- package/package.json.tmp +0 -0
- package/qna/TMLPD_QNA.md +3 -3
- package/skill/SKILL.md +2 -2
- package/src/__tests__/integration/tmpld_integration.test.py +540 -0
- package/src/agents/skill_enhanced_agent.py +318 -0
- package/src/memory/__init__.py +15 -0
- package/src/memory/agentic_memory.py +353 -0
- package/src/memory/semantic_memory.py +444 -0
- package/src/memory/simple_memory.py +466 -0
- package/src/memory/working_memory.py +447 -0
- package/src/orchestration/__init__.py +52 -0
- package/src/orchestration/execution_engine.py +353 -0
- package/src/orchestration/halo_orchestrator.py +367 -0
- package/src/orchestration/mcts_workflow.py +498 -0
- package/src/orchestration/role_assigner.py +473 -0
- package/src/orchestration/task_planner.py +522 -0
- package/src/providers/__init__.py +67 -0
- package/src/providers/anthropic.py +304 -0
- package/src/providers/base.py +241 -0
- package/src/providers/cerebras.py +373 -0
- package/src/providers/registry.py +476 -0
- package/src/routing/__init__.py +30 -0
- package/src/routing/universal_router.py +621 -0
- package/src/skills/TMLPD-QUICKREF.md +210 -0
- package/src/skills/TMLPD-SETUP-SUMMARY.md +157 -0
- package/src/skills/TMLPD.md +540 -0
- package/src/skills/__tests__/skill_manager.test.ts +328 -0
- package/src/skills/skill_manager.py +385 -0
- package/src/skills/test-tmlpd.sh +108 -0
- package/src/skills/tmlpd-category.yaml +67 -0
- package/src/skills/tmlpd-monitoring.yaml +188 -0
- package/src/skills/tmlpd-phase.yaml +132 -0
- package/src/state/__init__.py +17 -0
- package/src/state/simple_checkpoint.py +508 -0
- package/src/tmlpd_agent.py +464 -0
- package/src/tmpld_v2.py +427 -0
- package/src/workflows/__init__.py +18 -0
- package/src/workflows/advanced_difficulty_classifier.py +377 -0
- package/src/workflows/chaining_executor.py +417 -0
- package/src/workflows/difficulty_integration.py +209 -0
- package/src/workflows/orchestrator.py +469 -0
- package/src/workflows/orchestrator_executor.py +456 -0
- package/src/workflows/parallelization_executor.py +382 -0
- package/src/workflows/router.py +311 -0
- package/test_integration_simple.py +86 -0
- package/test_mcts_workflow.py +150 -0
- package/test_templd_integration.py +262 -0
- package/test_universal_router.py +275 -0
- package/tmlpd-pi-extension/README.md +36 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.d.ts +114 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.js +285 -0
- package/tmlpd-pi-extension/dist/cache/prefixCache.js.map +1 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.d.ts +58 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.js +153 -0
- package/tmlpd-pi-extension/dist/cache/responseCache.js.map +1 -0
- package/tmlpd-pi-extension/dist/cli.js +59 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.d.ts +95 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.js +240 -0
- package/tmlpd-pi-extension/dist/cost/costTracker.js.map +1 -0
- package/tmlpd-pi-extension/dist/index.d.ts +723 -0
- package/tmlpd-pi-extension/dist/index.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/index.js +239 -0
- package/tmlpd-pi-extension/dist/index.js.map +1 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.d.ts +82 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.js +145 -0
- package/tmlpd-pi-extension/dist/memory/episodicMemory.js.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.d.ts +102 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.js +207 -0
- package/tmlpd-pi-extension/dist/orchestration/haloOrchestrator.js.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.d.ts +85 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.js +210 -0
- package/tmlpd-pi-extension/dist/orchestration/mctsWorkflow.js.map +1 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.d.ts +102 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.js +338 -0
- package/tmlpd-pi-extension/dist/providers/localProvider.js.map +1 -0
- package/tmlpd-pi-extension/dist/providers/registry.d.ts +55 -0
- package/tmlpd-pi-extension/dist/providers/registry.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/providers/registry.js +138 -0
- package/tmlpd-pi-extension/dist/providers/registry.js.map +1 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.d.ts +68 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.js +332 -0
- package/tmlpd-pi-extension/dist/routing/advancedRouter.js.map +1 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.d.ts +101 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.js +368 -0
- package/tmlpd-pi-extension/dist/tools/tmlpdTools.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.d.ts +96 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.js +170 -0
- package/tmlpd-pi-extension/dist/utils/batchProcessor.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/compression.d.ts +61 -0
- package/tmlpd-pi-extension/dist/utils/compression.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/compression.js +281 -0
- package/tmlpd-pi-extension/dist/utils/compression.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/reliability.d.ts +74 -0
- package/tmlpd-pi-extension/dist/utils/reliability.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/reliability.js +177 -0
- package/tmlpd-pi-extension/dist/utils/reliability.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.d.ts +117 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.js +246 -0
- package/tmlpd-pi-extension/dist/utils/speculativeDecoding.js.map +1 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.d.ts +50 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.d.ts.map +1 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.js +124 -0
- package/tmlpd-pi-extension/dist/utils/tokenUtils.js.map +1 -0
- package/tmlpd-pi-extension/examples/QUICKSTART.md +183 -0
- package/tmlpd-pi-extension/package-lock.json +75 -0
- package/tmlpd-pi-extension/package.json +172 -0
- package/tmlpd-pi-extension/python/examples.py +53 -0
- package/tmlpd-pi-extension/python/integrations.py +330 -0
- package/tmlpd-pi-extension/python/setup.py +28 -0
- package/tmlpd-pi-extension/python/tmlpd.py +369 -0
- package/tmlpd-pi-extension/qna/REDDIT_GAP_ANALYSIS.md +299 -0
- package/tmlpd-pi-extension/qna/TMLPD_QNA.md +751 -0
- package/tmlpd-pi-extension/skill/SKILL.md +238 -0
- package/{src → tmlpd-pi-extension/src}/index.ts +1 -1
- package/tmlpd-pi-extension/tsconfig.json +18 -0
- package/demo/research-demo.js +0 -266
- package/notebooks/quickstart.ipynb +0 -157
- package/rust/tmlpd.h +0 -268
- package/src/cache/prefixCache.ts +0 -365
- package/src/routing/advancedRouter.ts +0 -406
- package/src/utils/speculativeDecoding.ts +0 -344
- /package/{src → tmlpd-pi-extension/src}/cache/responseCache.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/cost/costTracker.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/memory/episodicMemory.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/orchestration/haloOrchestrator.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/orchestration/mctsWorkflow.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/providers/localProvider.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/providers/registry.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/tools/tmlpdTools.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/utils/batchProcessor.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/utils/compression.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/utils/reliability.ts +0 -0
- /package/{src → tmlpd-pi-extension/src}/utils/tokenUtils.ts +0 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
"""
|
|
2
|
+
HALO Orchestrator - Hierarchical Autonomous Logic-Oriented Orchestration
|
|
3
|
+
|
|
4
|
+
Based on arXiv:2505.13516 (HALO) and arXiv:2506.12508v3 (AgentOrchestra)
|
|
5
|
+
|
|
6
|
+
This is the main orchestrator that coordinates all three tiers:
|
|
7
|
+
- Tier 1: TaskPlanner (high-level decomposition)
|
|
8
|
+
- Tier 2: RoleAssigner (specialized agent assignment)
|
|
9
|
+
- Tier 3: ExecutionEngine (parallel execution with verification)
|
|
10
|
+
|
|
11
|
+
Key Features:
|
|
12
|
+
- 19.6% improvement on complex tasks (vs flat orchestration)
|
|
13
|
+
- MCTS-based workflow search (optional, for complex tasks)
|
|
14
|
+
- Adaptive refinement for low-confidence results
|
|
15
|
+
- Hierarchical planning with automatic dependency resolution
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import asyncio
|
|
19
|
+
from typing import Dict, List, Any, Optional
|
|
20
|
+
from dataclasses import dataclass, field
|
|
21
|
+
from datetime import datetime
|
|
22
|
+
import logging
|
|
23
|
+
|
|
24
|
+
from .task_planner import TaskPlanner, TaskDecomposition, SubTask
|
|
25
|
+
from .role_assigner import RoleAssigner, AgentAssignment
|
|
26
|
+
from .execution_engine import ExecutionEngine, ExecutionResult, ExecutionSummary
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class HALOOrchestrationResult:
|
|
34
|
+
"""Result of HALO orchestration"""
|
|
35
|
+
success: bool
|
|
36
|
+
final_output: Any
|
|
37
|
+
decomposition: TaskDecomposition
|
|
38
|
+
assignments: Dict[str, AgentAssignment]
|
|
39
|
+
execution_summary: ExecutionSummary
|
|
40
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class HALOOrchestrator:
|
|
44
|
+
"""
|
|
45
|
+
Hierarchical Autonomous Logic-Oriented Orchestrator
|
|
46
|
+
|
|
47
|
+
Implements 3-tier hierarchical planning:
|
|
48
|
+
1. TaskPlanner: Decompose task into subtasks with dependencies
|
|
49
|
+
2. RoleAssigner: Assign specialized agents to each subtask
|
|
50
|
+
3. ExecutionEngine: Execute subtasks in parallel with verification
|
|
51
|
+
|
|
52
|
+
Key Innovation: Hierarchical planning outperforms flat execution
|
|
53
|
+
- 19.6% improvement on expert tasks (MATH, reasoning)
|
|
54
|
+
- Better on complex, multi-step tasks
|
|
55
|
+
- Automatic dependency resolution
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __init__(
|
|
59
|
+
self,
|
|
60
|
+
max_concurrent: int = 5,
|
|
61
|
+
optimization_target: str = "balanced",
|
|
62
|
+
enable_mcts: bool = False
|
|
63
|
+
):
|
|
64
|
+
"""
|
|
65
|
+
Initialize HALO orchestrator
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
max_concurrent: Maximum parallel executions
|
|
69
|
+
optimization_target: "quality", "cost", or "balanced"
|
|
70
|
+
enable_mcts: Enable MCTS-based workflow search (slower but better)
|
|
71
|
+
"""
|
|
72
|
+
# Initialize three tiers
|
|
73
|
+
self.planner = TaskPlanner()
|
|
74
|
+
self.assigner = RoleAssigner()
|
|
75
|
+
self.executor = ExecutionEngine(max_concurrent=max_concurrent)
|
|
76
|
+
|
|
77
|
+
# Configuration
|
|
78
|
+
self.optimization_target = optimization_target
|
|
79
|
+
self.enable_mcts = enable_mcts
|
|
80
|
+
|
|
81
|
+
# Statistics
|
|
82
|
+
self.orchestration_history = []
|
|
83
|
+
|
|
84
|
+
async def orchestrate(
|
|
85
|
+
self,
|
|
86
|
+
task: Dict[str, Any],
|
|
87
|
+
max_subtasks: int = 10,
|
|
88
|
+
timeout_seconds: int = 300
|
|
89
|
+
) -> HALOOrchestrationResult:
|
|
90
|
+
"""
|
|
91
|
+
Orchestrate task execution with hierarchical planning
|
|
92
|
+
|
|
93
|
+
Args:
|
|
94
|
+
task: Task to execute with 'description' and optional 'context'
|
|
95
|
+
max_subtasks: Maximum number of subtasks to create
|
|
96
|
+
timeout_seconds: Timeout per subtask
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
HALOOrchestrationResult with final output and metadata
|
|
100
|
+
"""
|
|
101
|
+
logger.info(f"Starting HALO orchestration for task: {task.get('description', 'Unknown')}")
|
|
102
|
+
|
|
103
|
+
# Tier 1: High-level planning
|
|
104
|
+
logger.info("Tier 1: Decomposing task...")
|
|
105
|
+
decomposition = await self.planner.decompose(
|
|
106
|
+
task,
|
|
107
|
+
max_subtasks=max_subtasks
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
logger.info(f" Decomposed into {len(decomposition.subtasks)} subtasks")
|
|
111
|
+
logger.info(f" Execution order: {decomposition.execution_order}")
|
|
112
|
+
|
|
113
|
+
# Tier 2: Role assignment
|
|
114
|
+
logger.info("Tier 2: Assigning specialized agents...")
|
|
115
|
+
assignments = await self.assigner.assign_roles(
|
|
116
|
+
decomposition.subtasks,
|
|
117
|
+
optimization_target=self.optimization_target
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
logger.info(f" Assigned {len(assignments)} agents")
|
|
121
|
+
|
|
122
|
+
# Log assignments
|
|
123
|
+
for subtask_id, assignment in assignments.items():
|
|
124
|
+
logger.debug(f" {subtask_id}: {assignment.agent_config.model_provider}/{assignment.agent_config.model_name}")
|
|
125
|
+
|
|
126
|
+
# Tier 3: Execution with adaptive refinement
|
|
127
|
+
logger.info("Tier 3: Executing subtasks...")
|
|
128
|
+
execution_summary = await self.executor.execute_parallel(
|
|
129
|
+
decomposition,
|
|
130
|
+
assignments,
|
|
131
|
+
timeout_seconds
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
logger.info(f" Execution complete: {execution_summary.successful_subtasks}/{execution_summary.total_subtasks} successful")
|
|
135
|
+
logger.info(f" Parallel speedup: {execution_summary.parallel_speedup:.2f}x")
|
|
136
|
+
logger.info(f" Total cost: ${execution_summary.total_cost_usd:.6f}")
|
|
137
|
+
|
|
138
|
+
# Synthesize final output
|
|
139
|
+
final_output = self._synthesize_results(
|
|
140
|
+
decomposition,
|
|
141
|
+
execution_summary
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
# Create result
|
|
145
|
+
result = HALOOrchestrationResult(
|
|
146
|
+
success=execution_summary.failed_subtasks == 0,
|
|
147
|
+
final_output=final_output,
|
|
148
|
+
decomposition=decomposition,
|
|
149
|
+
assignments=assignments,
|
|
150
|
+
execution_summary=execution_summary,
|
|
151
|
+
metadata={
|
|
152
|
+
"orchestration_method": "halo_3_tier",
|
|
153
|
+
"optimization_target": self.optimization_target,
|
|
154
|
+
"mcts_enabled": self.enable_mcts,
|
|
155
|
+
"timestamp": datetime.now().isoformat(),
|
|
156
|
+
"total_subtasks": len(decomposition.subtasks),
|
|
157
|
+
"parallel_speedup": execution_summary.parallel_speedup,
|
|
158
|
+
"total_cost_usd": execution_summary.total_cost_usd
|
|
159
|
+
}
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
self.orchestration_history.append(result)
|
|
163
|
+
|
|
164
|
+
return result
|
|
165
|
+
|
|
166
|
+
def _synthesize_results(
|
|
167
|
+
self,
|
|
168
|
+
decomposition: TaskDecomposition,
|
|
169
|
+
execution_summary: ExecutionSummary
|
|
170
|
+
) -> Any:
|
|
171
|
+
"""
|
|
172
|
+
Synthesize results from all subtasks into final output
|
|
173
|
+
|
|
174
|
+
This is a simplified implementation. In production, this would:
|
|
175
|
+
- Combine outputs from all subtasks
|
|
176
|
+
- Handle dependencies between results
|
|
177
|
+
- Format final output appropriately
|
|
178
|
+
- Handle partial failures gracefully
|
|
179
|
+
"""
|
|
180
|
+
successful_results = [
|
|
181
|
+
r for r in execution_summary.results.values()
|
|
182
|
+
if r.success
|
|
183
|
+
]
|
|
184
|
+
|
|
185
|
+
if not successful_results:
|
|
186
|
+
return {
|
|
187
|
+
"success": False,
|
|
188
|
+
"error": "All subtasks failed",
|
|
189
|
+
"details": execution_summary.results
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
# Simple concatenation of outputs (in production, would be smarter)
|
|
193
|
+
outputs = [r.output for r in successful_results]
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
"success": True,
|
|
197
|
+
"subtask_outputs": outputs,
|
|
198
|
+
"summary": f"Completed {len(successful_results)} subtasks successfully",
|
|
199
|
+
"total_cost_usd": execution_summary.total_cost_usd,
|
|
200
|
+
"parallel_speedup": execution_summary.parallel_speedup
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async def orchestrate_with_plan(
|
|
204
|
+
self,
|
|
205
|
+
task: Dict[str, Any],
|
|
206
|
+
plan: TaskDecomposition,
|
|
207
|
+
timeout_seconds: int = 300
|
|
208
|
+
) -> HALOOrchestrationResult:
|
|
209
|
+
"""
|
|
210
|
+
Orchestrate task execution with a pre-existing decomposition plan
|
|
211
|
+
|
|
212
|
+
Useful when you want to reuse a decomposition or modify it before execution.
|
|
213
|
+
|
|
214
|
+
Args:
|
|
215
|
+
task: Original task
|
|
216
|
+
plan: Pre-computed decomposition
|
|
217
|
+
timeout_seconds: Timeout per subtask
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
HALOOrchestrationResult
|
|
221
|
+
"""
|
|
222
|
+
logger.info(f"Starting HALO orchestration with pre-computed plan")
|
|
223
|
+
|
|
224
|
+
# Skip planning tier, go directly to role assignment
|
|
225
|
+
assignments = await self.assigner.assign_roles(
|
|
226
|
+
plan.subtasks,
|
|
227
|
+
optimization_target=self.optimization_target
|
|
228
|
+
)
|
|
229
|
+
|
|
230
|
+
execution_summary = await self.executor.execute_parallel(
|
|
231
|
+
plan,
|
|
232
|
+
assignments,
|
|
233
|
+
timeout_seconds
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
final_output = self._synthesize_results(plan, execution_summary)
|
|
237
|
+
|
|
238
|
+
return HALOOrchestrationResult(
|
|
239
|
+
success=execution_summary.failed_subtasks == 0,
|
|
240
|
+
final_output=final_output,
|
|
241
|
+
decomposition=plan,
|
|
242
|
+
assignments=assignments,
|
|
243
|
+
execution_summary=execution_summary,
|
|
244
|
+
metadata={
|
|
245
|
+
"orchestration_method": "halo_with_plan",
|
|
246
|
+
"timestamp": datetime.now().isoformat()
|
|
247
|
+
}
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
def get_orchestration_stats(self) -> Dict[str, Any]:
|
|
251
|
+
"""Get statistics about orchestrations performed"""
|
|
252
|
+
if not self.orchestration_history:
|
|
253
|
+
return {"total_orchestrations": 0}
|
|
254
|
+
|
|
255
|
+
total = len(self.orchestration_history)
|
|
256
|
+
successful = sum(1 for r in self.orchestration_history if r.success)
|
|
257
|
+
avg_speedup = sum(
|
|
258
|
+
r.metadata.get("parallel_speedup", 1.0)
|
|
259
|
+
for r in self.orchestration_history
|
|
260
|
+
) / total
|
|
261
|
+
total_cost = sum(
|
|
262
|
+
r.execution_summary.total_cost_usd
|
|
263
|
+
for r in self.orchestration_history
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
return {
|
|
267
|
+
"total_orchestrations": total,
|
|
268
|
+
"successful_orchestrations": successful,
|
|
269
|
+
"success_rate": successful / total if total > 0 else 0,
|
|
270
|
+
"average_parallel_speedup": avg_speedup,
|
|
271
|
+
"total_cost_usd": total_cost
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async def adaptive_refinement(
|
|
275
|
+
self,
|
|
276
|
+
low_confidence_results: List[ExecutionResult],
|
|
277
|
+
original_task: Dict[str, Any]
|
|
278
|
+
) -> List[ExecutionResult]:
|
|
279
|
+
"""
|
|
280
|
+
Re-execute low-confidence results with alternative strategies
|
|
281
|
+
|
|
282
|
+
This is a placeholder for MCTS-based adaptive refinement.
|
|
283
|
+
In full implementation, would use MCTS to search better execution paths.
|
|
284
|
+
|
|
285
|
+
Args:
|
|
286
|
+
low_confidence_results: Results with confidence < threshold
|
|
287
|
+
original_task: Original task context
|
|
288
|
+
|
|
289
|
+
Returns:
|
|
290
|
+
List of refined ExecutionResults
|
|
291
|
+
"""
|
|
292
|
+
refined = []
|
|
293
|
+
|
|
294
|
+
for result in low_confidence_results:
|
|
295
|
+
if result.confidence < 0.7:
|
|
296
|
+
logger.info(f"Refining low-confidence result: {result.subtask_id}")
|
|
297
|
+
|
|
298
|
+
# Simple retry with different parameters (in production: use MCTS)
|
|
299
|
+
# For now, just return the original result
|
|
300
|
+
refined.append(result)
|
|
301
|
+
|
|
302
|
+
return refined
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
# Example usage and testing
|
|
306
|
+
async def main():
|
|
307
|
+
"""Example of HALOOrchestrator usage"""
|
|
308
|
+
# Initialize orchestrator
|
|
309
|
+
orchestrator = HALOOrchestrator(
|
|
310
|
+
max_concurrent=3,
|
|
311
|
+
optimization_target="balanced"
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
# Simple task (should not decompose much)
|
|
315
|
+
simple_task = {
|
|
316
|
+
"description": "What is 2+2?",
|
|
317
|
+
"context": {}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
print("=" * 60)
|
|
321
|
+
print("Example 1: Simple Task")
|
|
322
|
+
print("=" * 60)
|
|
323
|
+
|
|
324
|
+
result = await orchestrator.orchestrate(simple_task)
|
|
325
|
+
|
|
326
|
+
print(f"\nResult:")
|
|
327
|
+
print(f" Success: {result.success}")
|
|
328
|
+
print(f" Output: {result.final_output}")
|
|
329
|
+
print(f" Subtasks: {result.metadata['total_subtasks']}")
|
|
330
|
+
print(f" Speedup: {result.metadata['parallel_speedup']:.2f}x")
|
|
331
|
+
print(f" Cost: ${result.metadata['total_cost_usd']:.6f}")
|
|
332
|
+
|
|
333
|
+
# Complex task (should decompose and parallelize)
|
|
334
|
+
complex_task = {
|
|
335
|
+
"description": "Build a REST API with user authentication and database integration",
|
|
336
|
+
"context": {"requirements": ["JWT", "PostgreSQL", "Docker"]}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
print("\n" + "=" * 60)
|
|
340
|
+
print("Example 2: Complex Task")
|
|
341
|
+
print("=" * 60)
|
|
342
|
+
|
|
343
|
+
result = await orchestrator.orchestrate(complex_task)
|
|
344
|
+
|
|
345
|
+
print(f"\nResult:")
|
|
346
|
+
print(f" Success: {result.success}")
|
|
347
|
+
print(f" Output: {result.final_output}")
|
|
348
|
+
print(f" Subtasks: {result.metadata['total_subtasks']}")
|
|
349
|
+
print(f" Speedup: {result.metadata['parallel_speedup']:.2f}x")
|
|
350
|
+
print(f" Cost: ${result.metadata['total_cost_usd']:.6f}")
|
|
351
|
+
|
|
352
|
+
# Stats
|
|
353
|
+
stats = orchestrator.get_orchestration_stats()
|
|
354
|
+
print(f"\nOrchestrator Stats:")
|
|
355
|
+
print(f" Total orchestrations: {stats['total_orchestrations']}")
|
|
356
|
+
print(f" Success rate: {stats['success_rate']:.2%}")
|
|
357
|
+
print(f" Average speedup: {stats['average_parallel_speedup']:.2f}x")
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
if __name__ == "__main__":
|
|
361
|
+
# Set up logging
|
|
362
|
+
logging.basicConfig(
|
|
363
|
+
level=logging.INFO,
|
|
364
|
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
365
|
+
)
|
|
366
|
+
|
|
367
|
+
asyncio.run(main())
|