forked from IBM/AssetOpsBench
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
78 lines (59 loc) · 1.78 KB
/
Copy pathmodels.py
File metadata and controls
78 lines (59 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Data models for the plan-execute orchestration client."""
from __future__ import annotations
from dataclasses import dataclass, field
from typing import Optional
@dataclass
class PlanStep:
"""A single step in an execution plan."""
step_number: int
task: str
server: str
tool: str
tool_args: dict
dependencies: list[int]
expected_output: str
@dataclass
class Plan:
"""An execution plan composed of ordered steps."""
steps: list[PlanStep]
raw: str # Raw LLM output, preserved for debugging
def get_step(self, number: int) -> Optional[PlanStep]:
return next((s for s in self.steps if s.step_number == number), None)
def resolved_order(self) -> list[PlanStep]:
"""Return steps in topological order (dependencies before dependents)."""
seen: set[int] = set()
ordered: list[PlanStep] = []
def visit(n: int) -> None:
if n in seen:
return
step = self.get_step(n)
if step is None:
return
for dep in step.dependencies:
visit(dep)
seen.add(n)
ordered.append(step)
for step in self.steps:
visit(step.step_number)
return ordered
@dataclass
class StepResult:
"""Result of executing a single plan step."""
step_number: int
task: str
server: str
response: str
error: Optional[str] = None
tool: str = ""
tool_args: dict = field(default_factory=dict)
duration_ms: float | None = None
@property
def success(self) -> bool:
return self.error is None
@dataclass
class OrchestratorResult:
"""Final result from the plan-execute orchestrator."""
question: str
answer: str
plan: Plan
trajectory: list[StepResult]