Harness and CLI¶
For: people embedding tether in Python or reading the control loop. After this page you know which class starts a session, which parameters it takes and where the CLI maps onto them.
Harness is the control plane: it owns the loop that assembles the prompt, asks the model, runs one command, records it and decides whether to stop. Everything the CLI does (tether run, send, wait, pipeline) is a thin wrapper over a method here, so a Python program can do the same with await Harness(...).run(goal). For a walk-through with examples see Python SDK and custom tools; for what each stop condition means see the deterministic envelope.
tether.harness¶
Control Plane: Tether Harness, bounded agent loop, live SQLite inbox, and headless spawner.
StallGuard
dataclass
¶
Stalls (AD-21): an identical repeat, a 2- to 4-command cycle, range_reads reads of one
file in a row, a bare echo (AD-50). check classifies a command; message is the note a
stall gets instead of running it; ran records a command that ran.
forget_actions()
¶
New input (an inbox message, a restart): earlier commands are not repeats.
check(cmd, stdin)
¶
(kind, cycle, read target): kind is loop, cycle, range, echo or None.
parts(kind, cmd, cycle, target, wrote)
¶
(fact, advice) of the one-line note a skipped stall gets (loop, cycle, range): the note
is fact advice, and the monitor (#412) may replace the advice only. A command is quoted
by its first line, at most STALL_QUOTE chars (a repeated heredoc is the whole file).
PipelineResumeError
¶
Bases: ValueError
A pipeline session cannot be resumed; the CLI reports it as a usage error.
Harness
¶
General-purpose LLM-Native Micro-Harness.
output_schema (JSON Schema subset) is a deterministic pre-done gate: the deliverable
must be JSON matching it. tether.api.failure_info classifies FAILED results by the
prefixes "Verification gate", "Stopped" and "Worker error".
register(fn_or_spec)
¶
Register a custom Python function or ToolSpec with this Harness.
build_multiplexer(session_id, enabled_tools, sandbox, model, on_approval=None)
¶
Construct the session Multiplexer with done + strictly opted-in tools.
create_pipeline_session(pipeline, goal, *, parent_id=None)
¶
Create a persisted root pipeline session row in SQLite without executing it yet.
spawn_pipeline(pipeline, goal, *, parent_id=None)
¶
Create a pipeline session and launch it as a detached headless worker.
run_pipeline(pipeline, goal, *, parent_id=None)
async
¶
Execute a deterministic multi-stage pipeline with isolated stage sessions.
resume_pipeline(session_id)
async
¶
Re-run a failed or waiting pipeline from its first stage that is not COMPLETED.
create_session(goal, *, parent_id=None)
¶
Create a persisted session row in SQLite without executing it yet.
from_session(rec, *, db_path=None, model=None, max_steps=None, worktree=False, worktree_from=None, setup=None)
classmethod
¶
Rebuild a harness from a stored session (used by tether replay).
Runs in the current directory (the stored workspace_root is not reused). Verify gates are not stored, so they are not restored. With worktree=True the replay runs in its own git worktree (worktree_from sets the base ref). setup is a shell command run in that worktree before the model starts.
spawn(goal, *, parent_id=None)
¶
Create a session and launch it as a detached headless worker, returning session_id.
run(goal, *, parent_id=None)
async
¶
Create and run a session inline until completion (done) or max_steps.
send(session_id, message, *, headless=False)
async
¶
Send a message to SQLite inbox; auto-resumes if WAITING_INPUT/COMPLETED/FAILED.
execute_session(session_id)
async
¶
Run a session. Worktree sessions are committed whenever they stop.
detect_cycle(history, window=8)
¶
Repeated n-gram at the tail of the last window actions, else None.
A 2-gram must repeat 3 times, a 3-gram or 4-gram 2 times, so a legitimate
test / view / test / view pair is not flagged. Identical-command runs are
loop_stall's job, so they are not a cycle here.
read_target(cmd)
¶
File a read-only command inspects (edit view p, sed -n 1,9p p, cat p), else None.
is_quiet(cmd)
¶
True if every statement of cmd is read-only or a verification (for f in x; do cat).
spawn_detached_worker(db_path, session_id)
¶
Spawn a detached OS background worker (python -P -m tether.cli _worker <session_id>).
-P: cwd must never shadow the installed tether (#273)¶
quiet_nudge(changed, quiet_run, can_edit)
¶
(notice id, text) after quiet steps before any change: make the edit or answer (#127), repeated every few more quiet steps; else (None, ""). After a change there is none: the "call done" one was followed 2 of 23 times (AD-20).
undo_damage(cmd, delta, tracker, root, originals, created_here, goal)
¶
Put back what a command broke or lost; returns (notes, whether a file was reverted).
F5: a .py file it left unparsable gets its old bytes, first, so the auto-test and the
notes see the file as it was. AD-51 (#350): files that were here before the session and
that it deleted come back, unless the goal asks to delete, move or clean things up. The
write-backs are the harness's, not the model's: the tracker does not count them.
tether.cli¶
tether.pipeline¶
Declarative multi-stage deterministic pipelines and heterogeneous model routing.
PipelineStage
dataclass
¶
A single deterministic stage inside a multi-stage Tether pipeline.
Pipeline
dataclass
¶
Declarative multi-stage workflow with isolated sessions and bounded FTS5 handoffs.
parse_pipeline_yaml(raw_yaml, default_name='pipeline')
¶
Parse a YAML string into a validated Pipeline specification.
load_pipeline(path)
¶
Load a declarative YAML pipeline manifest from disk.
render_stage_goal(stage, root_goal, upstream_stages, store)
¶
Render stage goal with {{goal}} interpolation and compact ~50-token upstream digests.