Architecture
Overview
agentrelay currently has a clean architecture layer plus a legacy prototype layer:
- Current architecture:
src/agentrelay/ - Prototype reference/runner:
src/agentrelay/prototypes/v01/
This page documents the current architecture layer only.
This page intentionally tracks architecture at the abstraction level rather than by module/file listing. The API reference and design diagram are the source of truth for concrete implementation details.
Core Abstractions
TaskGraph: immutable DAG ofTaskspecifications plus workstream metadataTaskGraphBuilder: YAML/dict schema parser that builds validatedTaskGraphTaskRuntimeBuilder: graph-to-runtime initializer for task execution stateWorkstreamRuntimeBuilder: graph-to-runtime initializer for workstream lane stateTaskRunner: one-task lifecycle state machine overTaskRuntimeStepDispatch: per-step dispatch table for framework/environment-specific implementationsWorkstreamRunner: workstream-level lifecycle runner (holds per-step protocol fields directly)build_standard_runner: factory wiringStandardTaskRunnerfor worktree + tmux + Claude Codebuild_standard_workstream_runner: factory wiringStandardWorkstreamRunnerfor git + GitHub CLIOrchestrator: async dependency/workstream scheduler over graph runtimesOrchestratorConfig: run-level scheduling, retry, and teardown policyerrors: typed integration failure model + expected/internal classification helperWorkstreamSpec: immutable definition of a task workstream laneTask: immutable specification of a unit of workTaskRuntime: mutable execution envelope attached to aTaskTaskState: operational task state (status, worktree/branch, attempts, errors)TaskArtifacts: outputs produced during execution (for example PR URL and concerns)TaskStatus: lifecycle state enum used by the runtimeWorkstreamRuntime: mutable execution envelope attached to aWorkstreamSpecWorkstreamState: operational lane state (status, worktree/branch, active task, errors)WorkstreamArtifacts: outputs produced during lane execution (for example merge PR URL and concerns)WorkstreamStatus: lifecycle state enum used by workstream runtimeAgent: abstract interface for a live running coding agentAgentAddress: abstract location/identity for a running agentAgentEnvironment: execution-environment abstraction (currently tmux)
Detailed References
- API details: API Reference
- Structural view: DIAGRAM.md
Design Principles
- Immutable spec vs mutable runtime: execution never mutates the task definition.
- Pluggable configuration: framework and environment are explicit config fields.
- Narrow interfaces:
Agent,AgentAddress, and environment typing keep launcher logic decoupled. - Contract-first integrations: external side effects are modeled as typed protocols/errors before concrete implementations.
Execution Boundary
The current architecture layer includes a real orchestrator, task lifecycle runner,
workstream lifecycle runner, and a CLI entry point (run_graph.py). All production
side-effect integrations (worktree setup, tmux launch, signal polling, PR merge,
workstream prepare/merge/teardown) are wired through the composition layer.
Orchestrator Behavior Contract
The orchestrator currently enforces:
- Dependency-aware scheduling (
TaskGraph.ready_ids(...)). - Workstream constraints:
- one active task per workstream,
- child workstreams wait for parent workstream
MERGED, - ancestor workstream failure blocks descendants.
- Retry policy for expected task failures (
TaskRunner.run(...)returnsFAILED). - Internal/system failure boundary for raised task-run exceptions:
- traceback recorded in orchestrator result,
- fail-fast path may cancel in-flight work (configurable).
- Task teardown policy forwarding through
OrchestratorConfig.task_teardown_mode.
Relationship To Prototype v01
Prototype docs and historical decisions are under docs/prototypes/v01/.
Use those docs for runnable workflow behavior today; use this page for the target architecture model.