workhorse

A fail-soft runner for agent workflows written as Python state machines — drives
an agent CLI (Claude, Codex, Copilot, OpenCode or Pi) unattended for days.
A workflow is a Python package: its states are methods that return the next state,
its nodes are plain functions. workhorse drives the machine, renders Jinja2
prompts, invokes the agent CLI, validates JSON replies into typed models,
checkpoints after every transition, and writes run artifacts.
The PyPI distribution is workhorse-agent and the import package is
workhorse. Workflow distributions provide the commands users run.
Why
workhorse exists to run long, multi-step agent workflows unattended — the
design target is a single run that survives for a week without a human babysitting
it. That goal drives the two defining properties of the tool:
- Resilience is the default, not a mode. A single flaky node (an empty agent
response, a rate limit, a spending cap, an unparseable output) must never crash
the whole run. The runner retries transient failures, reframes the prompt, and
finally defaults a turn's outputs so the machine advances to its next state
rather than aborting. See docs/GUARDRAILS.md for the full recovery
ladder and its tuning knobs.
- Reproducibility and resume. Every step is recorded as a run artifact and
the driver checkpoints after each transition, so a run resumes from exactly where
it left off after a crash or reboot.
It is repository-agnostic: repository setup belongs to the workflow or to whatever
supervises the run, while the engine only drives the state machine.
Python workflows
A workflow is an ordinary Python distribution. Constants, loops, and branches use
native Python; values crossing state boundaries are typed; and dependencies live in
the workflow's [project.dependencies]. Workhorse remains one dependency of that
distribution rather than owning its application-specific tools.
State transitions remain statically inspectable, so workhorse-<name> dot can draw
the machine. Code inside a state stays ordinary Python and is tested through the
workflow's node and agent substitution seams.
Install
pip install workhorse-agent # or: uv add workhorse-agent
This installs the library, not a command: workhorse drives no executable of its
own. What you run is the console script the workflow's distribution binds — see
Running a workflow — so in practice you
install that distribution, and workhorse comes along as one of its dependencies.
You also need the agent CLI you intend to
drive on your PATH and authenticated — by default the Claude
CLI (claude), authenticated via a
Claude subscription or claude setup-token. codex, copilot,
opencode and pi are also supported (see
Choosing the agent CLI backend).
Requires Python ≥ 3.12.
Quick start
Install a workflow distribution and run one of the commands it brings. You need the
agent CLI (claude by default) installed and authenticated:
workhorse-loop-runner run
workhorse-coder run qa --params '{"story":"CASE-1234","target_env":"dev"}'
Key flags (run workhorse-<name> --help for the full list):
| Flag |
Purpose |
--runs-dir <dir> |
Where to write run artifacts (default: <cwd>/.agents/runs) |
--run-id <id> |
Name the stable run dir (<workflow>-<id>); default: a digest of --params, else default |
--cli {claude,codex,copilot,opencode,pi} |
Which agent CLI drives the run (or AGENT_CLI, else the config's default_cli, else claude) |
--profile <name> |
Which named [profiles.<name>] set of models this run uses (see Naming a set of models) |
--config <path> |
Use this config file instead of the discovered one, for this run and everything it spawns |
--params '<json>' / --params-file <path> |
Set the workflow's declared inputs on a fresh start |
--dry-run |
Check the workflow and exit without running a node (see Checking and diagramming a workflow) |
--resume-run <path-or-id> / --resume-latest |
Manually resume a checkpointed run |
--worktree |
Cut a fresh branch and git worktree for this run and dispatch it there instead of the invoking repo (requires a configured worktree_dir; see farrier config set-worktree). A run that finishes with the worktree clean and its commits merged or pushed removes it, and deletes the branch once it is merged. Any other ending keeps both and records why (see Worktree dispatch) |
--worktree-branch <name> / --worktree-base <ref> |
Override --worktree's default branch name (run/<workflow>-<run-id>) and base ref (the invoking repo's HEAD) |
Running a workflow (workhorse-<name> run)
Every workflow brings its own command. run is the default subcommand, so it can be
left out:
workhorse-research run # the research workflow's entry flow
workhorse-coder run qa # coder's QA flow standalone
workhorse-coder run qa --params '{"story":"CASE-1234"}'
workhorse-coder qa # same as `run qa`
There is no workhorse executable and no resolution by name. The command is bound
inside the workflow's own distribution, which hands its Registry straight to the CLI:
# myworkflows/research/workflow.py
main = console_script(workflow.entry_point(Research))
[project.scripts]
workhorse-research = "myworkflows.research.workflow:main"
So the workflow that runs is the one whose command you typed — nothing is looked up, and
a name that has no script simply has no command, which you notice at install time rather
than at resolution time. The script must point at what console_script(...) returns
([project.scripts] targets are called after import, so a module-level main = … is the
shape).
The package must be installed unpacked (any pip/uv wheel is): the prompt renderer is
a filesystem template loader rooted at the workflow's own directory, so a zip-imported
package is refused at startup rather than failing later as a missing template.
The subcommands each command carries are run, dot,
control, inbox, replay,
environment and version — what the operator of a workflow needs: run it, draw it, steer
the live process, read or answer the messages a run left at its operator gates, run one
recorded turn again, prove that a turn loads the operator's whole environment, and say which
engine version did it.
workhorse-<name> environment [--profile NAME] starts claude -p and one engine turn from
the current directory, each with a trivial prompt, and prints one line per list the CLI's
init event carries (tools, skills, agents, plugins, slash commands, MCP servers) with both
counts and same, or the names the engine turn misses or adds. It writes nothing into the
directory. A tool the engine refuses on purpose and a delegate it defines are named and do
not count as missing. Exit codes: 0 the engine turn loads everything the plain session
loads, 1 it misses names, 2 the backend's CLI reports no load list (only claude does),
3 a session passed its 180 second limit or sent no init event.
A workflow's node functions run in the workflow distribution's environment, so every
imported tool must be declared in that distribution's [project.dependencies], not
merely installed somewhere else on PATH.
The skill and prompt content those prompts reference is separate, and separately
configured — see Initial setup.
A prompt names a skill by its library name, and a turn finds it among the skills its
harness loads: the repo from the turn's cwd up, the turn's added dirs, then home. A name
that is not there stops the turn with an error. The run checks every name its prompts make
before the first state and prints the ones that will not resolve, with the fix. It is a
warning on a real run, and --dry-run turns it into an exit code. The helpers
(skill_link, skill_command, and find_by_tags and has_skill for a workflow shipping
to unknown repos) are in
docs/CHECKING.md.
Checking and diagramming a workflow
--dry-run checks a workflow and exits without running a node — 0 when it is clean, 1
on the first problem, so CI can read it. The failure it exists to catch is a typo found at
hour 30 of an unattended run. dot renders the same workflow to
Graphviz DOT, read off the states rather than a separate diagram,
so it cannot go stale.
workhorse-research run --dry-run
workhorse-coder dot -o wf.dot && dot -Tsvg wf.dot -o wf.svg # render (needs graphviz)
The dry run does a static pass over the states' source — every rendered prompt path exists,
every state is reachable, something can return Done, no transition names a non-state —
and then drives the machine for real over a substituted node index, where every node body
and agent reply is a stand-in. What each half catches, what a fail terminal means with and
without declared replies, the dry-run run dir, and dot's flags and rendering rules
are in docs/CHECKING.md.
Choosing the agent CLI backend
The controller drives one agent CLI per run, behind a backend port
(workhorse/runner/backends/, one module per CLI). The CLI is chosen per-run; the
model is per-node:
workhorse-<name> run # the configured default_cli, else claude
workhorse-<name> run --cli codex # or copilot, opencode, pi
# Equivalently, set the AGENT_CLI={claude,codex,copilot,opencode,pi} env var.
The unnamed case is configurable, so a machine set up for one CLI does not have to
name it on every run — put default_cli in the shared config (see
BACKENDS.md):
default_cli = "opencode"
| Backend |
CLI |
Default model |
In-place compaction |
Compaction window |
claude |
claude -p (stream-json) |
sonnet |
yes (/compact) |
states --autocompact |
codex |
codex exec --json |
CLI default |
no — ladder reframes on overflow |
ignored |
copilot |
copilot --prompt=<prompt> --output-format json |
CLI default |
no — ladder reframes on overflow |
ignored |
opencode |
opencode run --format json |
— (node names it) |
no — ladder reframes on overflow |
ignored |
pi |
pi --mode json |
— (node names it) |
yes (rpc compact) |
ignored |
Claude, codex and opencode can spawn subagents inside a turn. Copilot and pi cannot.
A workflow reads the answer as self.subagents, and a dry run answers False unless the
test's RunEnv sets subagents. A workflow that wants one subagent per concern writes
one prompt for each case and picks by self.subagents.