Overview
Control what a turn may execute, how it recovers, and when it can finish.
prompt + state views
+ tools + historyestimate + reserve
→ chain.generateknown tool? allowed?
input schema passes?tool result
or explicit failureresult → transcript
↳ next model stepclose gate
→ typed outcomeThe harness is the runtime around the model. It assembles input, checks proposed operations, executes tools, returns feedback, and decides how the turn ends. The model chooses what to attempt; application declarations and runtime checks determine what is permitted.
Why a harness?
A model can request a nonexistent tool, supply invalid arguments, or stop without returning the result its caller needs. A prompt can describe the right behavior, but execution needs checks of its own.
Keel makes those checks part of the turn. Invalid arguments are refused before tool execution. Corrected calls pass through the same validation. A missing required deliverable prevents completion even if the model says it finished.
Declare the work and its limits
const outcome = await runtime.runTurn({
agent: assistant,
ambient,
envelope,
budget: { steps: 8, timeMs: 30_000 },
});
if (outcome.kind === "completed") {
present(outcome.payload);
} else {
handleOutcome(outcome);
}Here, runtime, assistant, and the request context come from your app;
present and handleOutcome are application handlers. Branch on the outcome,
not on whether any text arrived.
Make failure observable
Suppose an agent delegates research and the child never submits its required
findings. The child fails with deliverable-missing. The caller receives
that failure and either continues with feedback or fails according to its
onError policy. A child finishing does not complete its caller.
The harness checks declared contracts. It does not prove factual accuracy or that a schema-valid result is useful. Cover those requirements with your app's own behavior tests — see Testing.
Work with the harness
| Guide | What you'll learn |
|---|---|
| Gates and invariants | Separate configuration errors from checks during a turn. |
| Budgets and cancellation | Bound work, recovery, and nested execution. |
| Failure and recovery | Trace rejected calls, retries, correction feedback, and failures. |
| Completion and deliverables | Declare what must exist before a turn can complete. |
| Tracing and inspection | Explain a run from its events and final record. |
Model owns provider selection and fallback. Delegation owns the caller/child relationship. Harness explains how those mechanisms affect execution and the turn's outcome.
Inspect in Studio
Run a normal request and a deliberate failure. In TURN RECORDS, compare the outcomes; in MODEL, follow the operations that led to them. Use WIRE to distinguish visible output from proof of completion.
Next: Gates and invariants.
