Owns the state for one running script and implements the primitives.
| 52 | |
| 53 | |
| 54 | class WorkflowRun: |
| 55 | """Owns the state for one running script and implements the primitives.""" |
| 56 | |
| 57 | def __init__( |
| 58 | self, |
| 59 | *, |
| 60 | meta: WorkflowMeta, |
| 61 | runner: AgentRunner, |
| 62 | args: Any, |
| 63 | run_id: str, |
| 64 | scheduler: Scheduler, |
| 65 | budget: Budget, |
| 66 | journal: Journal, |
| 67 | progress: WorkflowProgress, |
| 68 | controller: AbortController, |
| 69 | base_path: CallKey = (), |
| 70 | resolve_workflow: Optional[Callable[[str], str]] = None, |
| 71 | depth: int = 0, |
| 72 | ) -> None: |
| 73 | self._meta = meta |
| 74 | self._runner = runner |
| 75 | self._args = args |
| 76 | self._run_id = run_id |
| 77 | self._scheduler = scheduler |
| 78 | self._budget = budget |
| 79 | self._journal = journal |
| 80 | self._progress = progress |
| 81 | self._controller = controller |
| 82 | self._base_path = base_path |
| 83 | self._resolve_workflow = resolve_workflow |
| 84 | self._depth = depth |
| 85 | self._display = 0 |
| 86 | # S2: per-agent child controllers, keyed by the call-path *string* (the |
| 87 | # form the UI/task layer carries on each AgentRecord), reachable so the |
| 88 | # task layer can stop one agent without aborting the whole run. |
| 89 | self._agent_controllers: dict[str, AbortController] = {} |
| 90 | # Keys whose agent has been asked to retry (the `r` action). |
| 91 | self._retry_requested: set[str] = set() |
| 92 | |
| 93 | @property |
| 94 | def controller(self) -> AbortController: |
| 95 | return self._controller |
| 96 | |
| 97 | def retry_agent(self, key: str) -> bool: |
| 98 | """Re-spawn one in-flight agent: flag it for retry and abort the current |
| 99 | attempt so ``agent()`` runs it again. Returns whether it was live.""" |
| 100 | controller = self._agent_controllers.get(key) |
| 101 | if controller is None: |
| 102 | return False |
| 103 | self._retry_requested.add(key) |
| 104 | controller.abort("agent_retry") |
| 105 | return True |
| 106 | |
| 107 | @property |
| 108 | def meta(self) -> WorkflowMeta: |
| 109 | return self._meta |
| 110 | |
| 111 | @property |