| 43 | |
| 44 | |
| 45 | async def run_workflow_task( |
| 46 | *, |
| 47 | source: str, |
| 48 | runner: AgentRunner, |
| 49 | registry: Any, # RuntimeTaskRegistry |
| 50 | task_id: str, |
| 51 | run_id: str, |
| 52 | output_file: str, |
| 53 | args: Any = None, |
| 54 | controller: Optional[AbortController] = None, |
| 55 | resume: Optional[Mapping] = None, |
| 56 | resolve_workflow: Optional[Any] = None, |
| 57 | tool_use_id: Optional[str] = None, |
| 58 | budget_total: Optional[int] = None, |
| 59 | max_concurrent: Optional[int] = None, |
| 60 | ): |
| 61 | from src.tasks.local_workflow import ( |
| 62 | complete_workflow_task, |
| 63 | fail_workflow_task, |
| 64 | register_workflow_task, |
| 65 | update_workflow_summary, |
| 66 | ) |
| 67 | |
| 68 | from .runtime import run_workflow |
| 69 | |
| 70 | controller = controller if controller is not None else create_abort_controller() |
| 71 | |
| 72 | def _on_start(run) -> None: |
| 73 | register_workflow_task( |
| 74 | task_id=task_id, |
| 75 | run_id=run_id, |
| 76 | workflow_name=run.meta.name, |
| 77 | description=run.meta.description, |
| 78 | output_file=output_file, |
| 79 | progress=run.progress, |
| 80 | run=run, |
| 81 | registry=registry, |
| 82 | tool_use_id=tool_use_id, |
| 83 | ) |
| 84 | |
| 85 | def _on_progress(_progress: WorkflowProgress) -> None: |
| 86 | update_workflow_summary(task_id, registry) |
| 87 | |
| 88 | try: |
| 89 | result = await run_workflow( |
| 90 | source, |
| 91 | runner=runner, |
| 92 | args=args, |
| 93 | run_id=run_id, |
| 94 | controller=controller, |
| 95 | on_start=_on_start, |
| 96 | on_progress=_on_progress, |
| 97 | resume=resume, |
| 98 | resolve_workflow=resolve_workflow, |
| 99 | budget_total=budget_total, |
| 100 | max_concurrent=max_concurrent, |
| 101 | ) |
| 102 | except WorkflowMetaError as exc: |