orchestrator
Orchestrator package — async graph scheduling over task and workstream runtimes.
Re-exports all public names so that from agentrelay.orchestrator import X
continues to work after promotion from a single module to a package.
TaskRuntimeBuilder
Builder for initializing per-task runtime envelopes from a task graph.
Source code in src/agentrelay/orchestrator/builders.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
from_graph(graph)
classmethod
Build initial runtimes for all tasks in a graph.
Runtimes are returned in the graph's stable topological task order. Each runtime starts with default mutable state/artifacts and no agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
TaskGraph
|
Validated immutable task graph. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, TaskRuntime]
|
dict[str, TaskRuntime]: Task runtimes keyed by task ID. |
Source code in src/agentrelay/orchestrator/builders.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
from_probe(graph, probe)
classmethod
Build runtimes pre-populated from a disk probe.
Each runtime's :class:TaskState and :class:TaskArtifacts are
populated from the corresponding :class:TaskProbe when the task's
signal directory exists on disk. Tasks that never started (no
signal dir) get fresh default state equivalent to
:meth:from_graph.
integration_branch and workstream_worktree_path on
TaskState are not set here — the orchestrator sets those
at dispatch time from the corresponding workstream runtime.
Transient per-attempt fields (agent_address, sandbox,
sandbox_context) are also intentionally left at their
defaults; they belong to a live agent session and are discarded
across orchestrator restarts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
TaskGraph
|
Validated immutable task graph. |
required |
probe
|
GraphProbe
|
Result of :func: |
required |
Returns:
| Type | Description |
|---|---|
dict[str, TaskRuntime]
|
dict[str, TaskRuntime]: Task runtimes keyed by task ID. |
Source code in src/agentrelay/orchestrator/builders.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
WorkstreamRuntimeBuilder
Builder for initializing per-workstream runtime envelopes from a graph.
Source code in src/agentrelay/orchestrator/builders.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
from_graph(graph)
classmethod
Build initial runtimes for all workstreams in a graph.
Runtimes are returned in the graph's stable sorted workstream order. Each runtime starts with default mutable state/artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
TaskGraph
|
Validated immutable task graph. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, WorkstreamRuntime]
|
dict[str, WorkstreamRuntime]: Workstream runtimes keyed by ID. |
Source code in src/agentrelay/orchestrator/builders.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
from_probe(graph, probe)
classmethod
Build runtimes pre-populated from a disk probe.
Each runtime's :class:WorkstreamState and
:class:WorkstreamArtifacts are populated from the corresponding
:class:WorkstreamProbe when the workstream's signal directory
exists on disk. Workstreams that never prepared (no signal dir)
get fresh default state equivalent to :meth:from_graph.
If the probe carries a frozen :class:ResolvedWorkstream record,
its target_branch_before_any_merge value is copied into
runtime.artifacts so downstream rollback logic can reach it
without re-reading resolved.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
TaskGraph
|
Validated immutable task graph. |
required |
probe
|
GraphProbe
|
Result of :func: |
required |
Returns:
| Type | Description |
|---|---|
dict[str, WorkstreamRuntime]
|
dict[str, WorkstreamRuntime]: Workstream runtimes keyed by ID. |
Source code in src/agentrelay/orchestrator/builders.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
Orchestrator
dataclass
Async graph scheduler using dependency + workstream constraints.
Immutable configuration holder. The :meth:run method creates an
:class:_OrchestratorRun that owns all mutable execution state.
Source code in src/agentrelay/orchestrator/orchestrator.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
run(task_runtimes=None, workstream_runtimes=None)
async
Run graph orchestration until terminal success/failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_runtimes
|
Optional[Mapping[str, TaskRuntime]]
|
Optional prebuilt task runtime map for resume-like runs. If omitted, built fresh from graph. |
None
|
workstream_runtimes
|
Optional[Mapping[str, WorkstreamRuntime]]
|
Optional prebuilt workstream runtime map for resume-like runs. If omitted, built fresh from graph. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
OrchestratorResult |
OrchestratorResult
|
Terminal orchestration result with mutated runtimes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If configuration values are invalid or runtime maps do not align with graph IDs. |
Source code in src/agentrelay/orchestrator/orchestrator.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
OrchestratorConfig
dataclass
Configuration for one orchestrator scheduling run.
Attributes:
| Name | Type | Description |
|---|---|---|
max_concurrency |
int
|
Maximum number of task attempts to run concurrently. |
max_task_attempts |
int
|
Maximum attempts per task (including first attempt). |
task_teardown_mode |
TearDownMode
|
Teardown policy forwarded to |
fail_fast_on_internal_error |
bool
|
Stop scheduling immediately when a task run raises (internal/system failure). |
fail_fast_on_workstream_error |
bool
|
When |
merge_poll_interval |
float
|
Seconds between polls for integration PR merge
status. Only used when an :class: |
Source code in src/agentrelay/orchestrator/orchestrator.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
OrchestratorEvent
dataclass
Structured event emitted by the orchestration loop.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
Event type identifier. |
task_id |
Optional[str]
|
Optional task ID associated with the event. |
workstream_id |
Optional[str]
|
Optional workstream ID associated with the event. |
attempt_num |
Optional[int]
|
Optional 0-indexed attempt number for task-run events. |
outcome_class |
Optional[TaskOutcomeClass]
|
Optional classified task outcome. |
message |
Optional[str]
|
Optional event detail. |
Source code in src/agentrelay/orchestrator/orchestrator.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
OrchestratorListener
Bases: Protocol
Callback protocol for real-time orchestration event observation.
Source code in src/agentrelay/orchestrator/orchestrator.py
117 118 119 120 121 122 123 124 125 126 127 | |
on_event(event)
Called each time the orchestrator produces an event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
OrchestratorEvent
|
The event that was just produced. |
required |
Source code in src/agentrelay/orchestrator/orchestrator.py
121 122 123 124 125 126 127 | |
OrchestratorOutcome
Bases: str, Enum
Terminal outcome for one orchestrator run.
Attributes:
| Name | Type | Description |
|---|---|---|
SUCCEEDED |
All tasks reached a terminal success status. |
|
COMPLETED_WITH_FAILURES |
No fatal internal error, but one or more tasks
ended |
|
FATAL_INTERNAL_ERROR |
A task run raised and orchestration failed fast. |
Source code in src/agentrelay/orchestrator/orchestrator.py
53 54 55 56 57 58 59 60 61 62 63 64 65 | |
OrchestratorResult
dataclass
Terminal result for one orchestrator run.
Attributes:
| Name | Type | Description |
|---|---|---|
outcome |
OrchestratorOutcome
|
Overall run outcome classification. |
task_runtimes |
Mapping[str, TaskRuntime]
|
Final task runtimes keyed by task ID. |
workstream_runtimes |
Mapping[str, WorkstreamRuntime]
|
Final workstream runtimes keyed by workstream ID. |
events |
tuple[OrchestratorEvent, ...]
|
Ordered structured events produced during scheduling/execution. |
fatal_error |
Optional[str]
|
Traceback text for fatal internal errors, if any. |
Source code in src/agentrelay/orchestrator/orchestrator.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
TaskOutcomeClass
Bases: str, Enum
Classification of one task attempt outcome from the orchestrator boundary.
Attributes:
| Name | Type | Description |
|---|---|---|
SUCCESS |
Task reached a terminal success status ( |
|
EXPECTED_FAILURE |
Task run returned |
|
INTERNAL_ERROR |
Task run raised an exception. |
Source code in src/agentrelay/orchestrator/orchestrator.py
39 40 41 42 43 44 45 46 47 48 49 50 | |
GraphProbe
dataclass
Aggregate probe result covering all tasks and workstreams in a graph.
Attributes:
| Name | Type | Description |
|---|---|---|
task_probes |
dict[str, TaskProbe]
|
Reconstructed task state keyed by task ID. Every task in the current graph has an entry, even tasks that never ran (signal dir absent). |
workstream_probes |
dict[str, WorkstreamProbe]
|
Reconstructed workstream state keyed by workstream ID. Every workstream in the current graph has an entry. |
Source code in src/agentrelay/orchestrator/probe.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
TaskProbe
dataclass
Reconstructed on-disk state for a single task.
Attributes:
| Name | Type | Description |
|---|---|---|
task_id |
str
|
Task identifier. |
status |
TaskStatus
|
Resolved task status after stale-state normalization.
Guaranteed never to be |
signal_dir |
Path
|
Path to the task signal directory
( |
attempt_num |
int
|
Highest attempt number found on disk (0 if no attempt directories exist). |
branch_name |
str
|
Task feature branch name, derived from convention
as |
pr_url |
Optional[str]
|
PR URL recovered from the latest attempt's |
resolved |
Optional[ResolvedTask]
|
Frozen execution record loaded from
|
Source code in src/agentrelay/orchestrator/probe.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
WorkstreamProbe
dataclass
Reconstructed on-disk state for a single workstream.
Attributes:
| Name | Type | Description |
|---|---|---|
workstream_id |
str
|
Workstream identifier. |
status |
WorkstreamStatus
|
Current workstream status (no normalization needed —
workstream transient states are handled by the orchestrator's
main loop via |
signal_dir |
Path
|
Path to the workstream signal directory
( |
worktree_path |
Path
|
Path to the workstream worktree
( |
branch_name |
str
|
Workstream integration branch name, derived as
|
merge_pr_url |
Optional[str]
|
Integration PR URL recovered from the
|
resolved |
Optional[ResolvedWorkstream]
|
Frozen execution record loaded from
|
Source code in src/agentrelay/orchestrator/probe.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
build_integration_auto_merger(repo_path)
Build the standard integration auto-merger for GitHub CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
Path
|
Path to the repository (for pre-merge SHA capture). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
GhIntegrationAutoMerger
|
class: |
Source code in src/agentrelay/orchestrator/builders.py
367 368 369 370 371 372 373 374 375 376 | |
build_integration_merge_checker(repo_path)
Build the standard integration merge checker for GitHub CLI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
Path
|
Path to the repository (for git ref resolution). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
GhIntegrationMergeChecker
|
class: |
Source code in src/agentrelay/orchestrator/builders.py
355 356 357 358 359 360 361 362 363 364 | |
build_run_repo_manager(repo_path, graph_name)
Build the standard run repo manager for git repositories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
Path
|
Path to the repository root. |
required |
graph_name
|
str
|
Name of the graph being executed. |
required |
Returns:
| Type | Description |
|---|---|
GitRunRepoManager
|
A |
Source code in src/agentrelay/orchestrator/builders.py
428 429 430 431 432 433 434 435 436 437 438 | |
build_sandbox_infrastructure_manager(graph)
Build the appropriate sandbox infrastructure manager for a graph.
Inspects the graph's tasks for OCI sandbox usage. Returns an
OciSandboxInfrastructureManager when any task uses OCI
isolation, otherwise returns a
NullSandboxInfrastructureManager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
TaskGraph
|
Validated immutable task graph. |
required |
Returns:
| Type | Description |
|---|---|
OciSandboxInfrastructureManager | NullSandboxInfrastructureManager
|
Appropriate infrastructure manager implementation. |
Source code in src/agentrelay/orchestrator/builders.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
build_session_resolver()
Build the standard session resolver for tmux environments.
Returns:
| Type | Description |
|---|---|
TmuxSessionResolver
|
A |
Source code in src/agentrelay/orchestrator/builders.py
419 420 421 422 423 424 425 | |
build_standard_runner(repo_path, graph_name, run_dir, graph, keep_panes=False, poll_interval=2.0, context_content=None, tools=(), credential_provider=None, anthropic_credential=None)
Build the standard runner for worktree + tmux + Claude Code.
All steps use StepDispatch default since only one
framework/environment combo currently exists.
When adding a new AgentFramework or AgentEnvironment, add keyed
entries to the StepDispatch tables for steps that have distinct
implementations. Refer to the sensitivity table in
:class:StandardTaskRunner's docstring.
Dispatch table (current):
+-----------------------+----------------------------+-----------------------+ | Step | Implementation | Notes | +=======================+============================+=======================+ | preparer | WorktreeTaskPreparer | env/fw agnostic | +-----------------------+----------------------------+-----------------------+ | launcher | TmuxTaskLauncher | will need entries | +-----------------------+----------------------------+-----------------------+ | kickoff | TmuxTaskKickoff | will need entries | +-----------------------+----------------------------+-----------------------+ | completion_checker | SignalCompletionChecker | may need entries | +-----------------------+----------------------------+-----------------------+ | gate_checker | ShellGateChecker | env/fw agnostic | +-----------------------+----------------------------+-----------------------+ | merger | GhTaskMerger | env/fw agnostic | +-----------------------+----------------------------+-----------------------+ | log_capture | WorktreeTaskLogCapture | will need entries | +-----------------------+----------------------------+-----------------------+ | teardown | WorktreeTaskTeardown | will need entries | +-----------------------+----------------------------+-----------------------+
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
Path
|
Path to the bare/main repository. |
required |
graph_name
|
str
|
Name of the task graph being executed. |
required |
graph
|
TaskGraph
|
The task graph (used to compute dependency descriptions). |
required |
keep_panes
|
bool
|
Whether to keep tmux panes after teardown. |
False
|
poll_interval
|
float
|
Seconds between completion signal polls. |
2.0
|
context_content
|
Optional[str]
|
Optional context content to write to the signal dir. |
None
|
tools
|
tuple[str, ...]
|
Declared tool names from the graph YAML. |
()
|
Returns:
| Type | Description |
|---|---|
StandardTaskRunner
|
A fully wired :class: |
Source code in src/agentrelay/orchestrator/builders.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
build_standard_workstream_runner(repo_path, graph_name, run_dir)
Build the standard workstream runner for git worktree + GitHub CLI.
Wires the three workstream lifecycle steps with concrete implementations:
+----------+-------------------------+ | Step | Implementation | +==========+=========================+ | preparer | GitWorkstreamPreparer | +----------+-------------------------+ | integrator | GhWorkstreamIntegrator | +----------+-------------------------+ | teardown | GitWorkstreamTeardown | +----------+-------------------------+
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
Path
|
Path to the bare/main repository. |
required |
graph_name
|
str
|
Name of the task graph being executed. |
required |
Returns:
| Type | Description |
|---|---|
StandardWorkstreamRunner
|
A fully wired :class: |
Source code in src/agentrelay/orchestrator/builders.py
320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
build_task_pr_prober()
Build the standard task PR prober for GitHub CLI.
Used during graph resumption to normalize stale PR_CREATED tasks
by checking whether the PR was merged and optionally merging it.
Returns:
| Name | Type | Description |
|---|---|---|
A |
GhTaskPrProber
|
class: |
Source code in src/agentrelay/orchestrator/builders.py
379 380 381 382 383 384 385 386 387 388 | |
probe_graph_state(repo_path, graph_name, graph, run_dir, pr_prober)
Reconstruct runtime state from on-disk signal files.
Normalizes stale transient states in place before returning. A
task that was RUNNING at orchestrator-crash time is resolved by
inspecting the attempt directory for terminal signals (.done or
.failed); a task that was PR_CREATED is resolved by probing
the hosting platform via pr_prober.
Chained normalization path when a RUNNING task has a .done
file containing a PR URL::
RUNNING
└─ .done + PR URL ──► PR_CREATED
├─ is_merged=True ─────────────► PR_MERGED
├─ is_merged=F, try_merge=T ──► PR_MERGED
├─ is_merged=F, try_merge=F ──► FAILED
└─ pr_url=None (malformed) ───► FAILED
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_path
|
Path
|
Path to the target repository (used to compute worktree paths). |
required |
graph_name
|
str
|
Name of the graph being resumed. |
required |
graph
|
TaskGraph
|
Current graph definition, used to enumerate task and workstream IDs. |
required |
run_dir
|
Path
|
Path to the run directory being probed
(typically |
required |
pr_prober
|
TaskPrProber
|
Protocol implementation for checking and merging stale task PRs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GraphProbe |
GraphProbe
|
Reconstructed task and workstream state. |
Source code in src/agentrelay/orchestrator/probe.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |