zelos.execution_trace
Execution Trace — Complete execution timeline for a Goal.
v0.9.0: Provides get_goal_trace() API returning a structured timeline of every Task lifecycle event with optional input/output loading. Supports pagination for large Goals.
1""" 2Execution Trace — Complete execution timeline for a Goal. 3 4v0.9.0: Provides get_goal_trace() API returning a structured timeline 5of every Task lifecycle event with optional input/output loading. 6Supports pagination for large Goals. 7""" 8 9from dataclasses import dataclass, field 10 11 12@dataclass 13class TraceEvent: 14 """A single event in a Task's execution timeline.""" 15 16 event_type: str # task.created / task.started / task.completed / task.failed / task.retry_scheduled 17 timestamp: float 18 payload: dict = field(default_factory=dict) 19 20 def to_dict(self) -> dict: 21 return { 22 "event_type": self.event_type, 23 "timestamp": self.timestamp, 24 "payload": dict(self.payload), 25 } 26 27 28@dataclass 29class TaskTrace: 30 """Complete execution trace for a single Task within a Goal.""" 31 32 task_id: str 33 description: str = "" 34 required_capability: str = "" 35 agent_id: str | None = None 36 agent_name: str | None = None 37 status: str = "created" 38 attempt: int = 0 39 timeline: list[TraceEvent] = field(default_factory=list) 40 input_context: dict | None = None # lazy-loaded 41 output_artifact: dict | None = None # lazy-loaded 42 error: dict | None = None 43 44 def to_dict(self) -> dict: 45 return { 46 "task_id": self.task_id, 47 "description": self.description, 48 "required_capability": self.required_capability, 49 "agent_id": self.agent_id, 50 "agent_name": self.agent_name, 51 "status": self.status, 52 "attempt": self.attempt, 53 "timeline": [t.to_dict() for t in self.timeline], 54 "input_context": self.input_context, 55 "output_artifact": self.output_artifact, 56 "error": self.error, 57 } 58 59 60@dataclass 61class ExecutionTrace: 62 """Complete execution trace for a Goal — all Task traces merged. 63 64 Supports pagination via limit/offset. 65 """ 66 67 goal_id: str 68 goal_description: str = "" 69 status: str = "unknown" 70 total_duration_ms: float = 0.0 71 tasks: list[TaskTrace] = field(default_factory=list) 72 total_tasks: int = 0 # Total before pagination 73 74 def to_dict(self) -> dict: 75 return { 76 "goal_id": self.goal_id, 77 "goal_description": self.goal_description, 78 "status": self.status, 79 "total_duration_ms": self.total_duration_ms, 80 "tasks": [t.to_dict() for t in self.tasks], 81 "total_tasks": self.total_tasks, 82 } 83 84 def paginate(self, limit: int = 50, offset: int = 0) -> "ExecutionTrace": 85 """Return a paginated view of this trace.""" 86 sliced = ExecutionTrace( 87 goal_id=self.goal_id, 88 goal_description=self.goal_description, 89 status=self.status, 90 total_duration_ms=self.total_duration_ms, 91 tasks=self.tasks[offset:offset + limit], 92 total_tasks=len(self.tasks), 93 ) 94 return sliced
@dataclass
class
TraceEvent:
13@dataclass 14class TraceEvent: 15 """A single event in a Task's execution timeline.""" 16 17 event_type: str # task.created / task.started / task.completed / task.failed / task.retry_scheduled 18 timestamp: float 19 payload: dict = field(default_factory=dict) 20 21 def to_dict(self) -> dict: 22 return { 23 "event_type": self.event_type, 24 "timestamp": self.timestamp, 25 "payload": dict(self.payload), 26 }
A single event in a Task's execution timeline.
@dataclass
class
TaskTrace:
29@dataclass 30class TaskTrace: 31 """Complete execution trace for a single Task within a Goal.""" 32 33 task_id: str 34 description: str = "" 35 required_capability: str = "" 36 agent_id: str | None = None 37 agent_name: str | None = None 38 status: str = "created" 39 attempt: int = 0 40 timeline: list[TraceEvent] = field(default_factory=list) 41 input_context: dict | None = None # lazy-loaded 42 output_artifact: dict | None = None # lazy-loaded 43 error: dict | None = None 44 45 def to_dict(self) -> dict: 46 return { 47 "task_id": self.task_id, 48 "description": self.description, 49 "required_capability": self.required_capability, 50 "agent_id": self.agent_id, 51 "agent_name": self.agent_name, 52 "status": self.status, 53 "attempt": self.attempt, 54 "timeline": [t.to_dict() for t in self.timeline], 55 "input_context": self.input_context, 56 "output_artifact": self.output_artifact, 57 "error": self.error, 58 }
Complete execution trace for a single Task within a Goal.
TaskTrace( task_id: str, description: str = '', required_capability: str = '', agent_id: str | None = None, agent_name: str | None = None, status: str = 'created', attempt: int = 0, timeline: list[TraceEvent] = <factory>, input_context: dict | None = None, output_artifact: dict | None = None, error: dict | None = None)
timeline: list[TraceEvent]
def
to_dict(self) -> dict:
45 def to_dict(self) -> dict: 46 return { 47 "task_id": self.task_id, 48 "description": self.description, 49 "required_capability": self.required_capability, 50 "agent_id": self.agent_id, 51 "agent_name": self.agent_name, 52 "status": self.status, 53 "attempt": self.attempt, 54 "timeline": [t.to_dict() for t in self.timeline], 55 "input_context": self.input_context, 56 "output_artifact": self.output_artifact, 57 "error": self.error, 58 }
@dataclass
class
ExecutionTrace:
61@dataclass 62class ExecutionTrace: 63 """Complete execution trace for a Goal — all Task traces merged. 64 65 Supports pagination via limit/offset. 66 """ 67 68 goal_id: str 69 goal_description: str = "" 70 status: str = "unknown" 71 total_duration_ms: float = 0.0 72 tasks: list[TaskTrace] = field(default_factory=list) 73 total_tasks: int = 0 # Total before pagination 74 75 def to_dict(self) -> dict: 76 return { 77 "goal_id": self.goal_id, 78 "goal_description": self.goal_description, 79 "status": self.status, 80 "total_duration_ms": self.total_duration_ms, 81 "tasks": [t.to_dict() for t in self.tasks], 82 "total_tasks": self.total_tasks, 83 } 84 85 def paginate(self, limit: int = 50, offset: int = 0) -> "ExecutionTrace": 86 """Return a paginated view of this trace.""" 87 sliced = ExecutionTrace( 88 goal_id=self.goal_id, 89 goal_description=self.goal_description, 90 status=self.status, 91 total_duration_ms=self.total_duration_ms, 92 tasks=self.tasks[offset:offset + limit], 93 total_tasks=len(self.tasks), 94 ) 95 return sliced
Complete execution trace for a Goal — all Task traces merged.
Supports pagination via limit/offset.
ExecutionTrace( goal_id: str, goal_description: str = '', status: str = 'unknown', total_duration_ms: float = 0.0, tasks: list[TaskTrace] = <factory>, total_tasks: int = 0)
tasks: list[TaskTrace]
85 def paginate(self, limit: int = 50, offset: int = 0) -> "ExecutionTrace": 86 """Return a paginated view of this trace.""" 87 sliced = ExecutionTrace( 88 goal_id=self.goal_id, 89 goal_description=self.goal_description, 90 status=self.status, 91 total_duration_ms=self.total_duration_ms, 92 tasks=self.tasks[offset:offset + limit], 93 total_tasks=len(self.tasks), 94 ) 95 return sliced
Return a paginated view of this trace.