Convert workflow to dictionary for JSON serialization.
(self)
| 341 | self._current_step.events.append(event) |
| 342 | |
| 343 | def to_dict(self) -> Dict[str, Any]: |
| 344 | """Convert workflow to dictionary for JSON serialization.""" |
| 345 | return { |
| 346 | "task_name": self.workflow.task_name, |
| 347 | "goal": self.workflow.goal, |
| 348 | "model": self.workflow.model, |
| 349 | "status": self.workflow.status, |
| 350 | "total_tokens": self.workflow.total_tokens, |
| 351 | "prompt_tokens": self.workflow.prompt_tokens, |
| 352 | "completion_tokens": self.workflow.completion_tokens, |
| 353 | "reasoning_tokens": self.workflow.reasoning_tokens, |
| 354 | "cost": self.workflow.cost, |
| 355 | "start_time": self.workflow.start_time, |
| 356 | "end_time": self.workflow.end_time, |
| 357 | "steps": [ |
| 358 | { |
| 359 | "step_id": step.step_id, |
| 360 | "number": step.number, |
| 361 | "name": step.name, |
| 362 | "type": step.step_type, |
| 363 | "instruction": step.instruction, |
| 364 | "depth": step.depth, |
| 365 | "parent_step_id": step.parent_step_id, |
| 366 | "parent_iteration": step.parent_iteration, |
| 367 | "tokens": step.tokens, |
| 368 | "variables": step.variables, |
| 369 | "status": step.status, |
| 370 | "start_time": step.start_time, |
| 371 | "end_time": step.end_time, |
| 372 | "iterations": [ |
| 373 | { |
| 374 | "number": it.number, |
| 375 | "max": it.max, |
| 376 | "tokens": it.tokens, |
| 377 | "limit": it.limit, |
| 378 | "utilization": it.utilization, |
| 379 | "timeline": getattr(it, "timeline", []), |
| 380 | "messages": it.messages, |
| 381 | "usage": it.usage, |
| 382 | "reasoning_tokens": it.reasoning_tokens, |
| 383 | "context_tokens": it.context_tokens, |
| 384 | "context_limit": it.context_limit, |
| 385 | "content": it.content, # full content for transparency |
| 386 | } |
| 387 | for it in step.iterations |
| 388 | ], |
| 389 | "events": [ |
| 390 | {"type": ev.type, "message": ev.data.get("message", "")} |
| 391 | for ev in step.events |
| 392 | ], |
| 393 | } |
| 394 | for step in self.workflow.steps |
| 395 | ], |
| 396 | "raw_line_count": len(self.workflow.raw_lines), |
| 397 | } |
| 398 | |
| 399 | |
| 400 | # ============================================================================= |