-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorchestrator.py
More file actions
60 lines (50 loc) Β· 2.14 KB
/
Copy pathorchestrator.py
File metadata and controls
60 lines (50 loc) Β· 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Orchestrates the DevMind plan, code, execute, and retry pipeline."""
from __future__ import annotations
from agents.coder_agent import CoderAgent
from agents.executor_agent import ExecutorAgent
from agents.planner_agent import PlannerAgent
from config import MAX_RETRIES
from schemas import OrchestratorResult
from tools.memory import save_session
from utils.event_bus import EventType, bus
async def run(task: str) -> OrchestratorResult:
"""Run the full autonomous DevMind pipeline for a coding task."""
bus.emit(EventType.PIPELINE_START, "Orchestrator", {"task": task})
planner = PlannerAgent()
coder = CoderAgent()
executor = ExecutorAgent()
try:
plan = await planner.run(task)
error: str | None = None
code = ""
for attempt in range(MAX_RETRIES):
code = await coder.run(plan, error=error, attempt=attempt + 1)
result = await executor.run(code)
if result.status == "success":
response = OrchestratorResult(
plan=plan,
code=code,
output=result.output,
attempts=attempt + 1,
success=True,
)
save_session(task, plan, code, result.output, True, attempt + 1)
bus.emit(EventType.PIPELINE_COMPLETE, "Orchestrator", {"success": True, "attempts": attempt + 1})
return response
error = result.error
if error:
bus.emit(EventType.AGENT_RETRY, "Orchestrator", {"attempt": attempt + 1, "error": error})
response = OrchestratorResult(
plan=plan,
code=code,
output=None,
error=error,
attempts=MAX_RETRIES,
success=False,
)
save_session(task, plan, code, None, False, MAX_RETRIES)
bus.emit(EventType.PIPELINE_COMPLETE, "Orchestrator", {"success": False, "attempts": MAX_RETRIES})
return response
except (RuntimeError, ValueError, TypeError) as exc:
bus.emit(EventType.PIPELINE_COMPLETE, "Orchestrator", {"success": False, "error": str(exc)})
raise