# What an agent harness owes its model

An agent harness sits between a model and its tools: it chooses what the model sees, runs what the model calls and decides what the model reads back. The patterns below come from the Ouroboros harness. Each one says the rule, why it holds, and where Ouroboros does it, pinned to [commit 9969ef6](https://github.com/ourostack/ouroboros/commit/9969ef6168c6d36eee8473ee91a5dce76e42a568 "verify:urlOk(https://github.com/ourostack/ouroboros/commit/9969ef6168c6d36eee8473ee91a5dce76e42a568)") so a reader can check it.

## 1. A failure says what kind it is and what to do next

Give a failed or refused call a shape, not only a sentence: what kind of failure it is (bad input, something to repair locally, a bug in the harness, something outside), whether trying again can help, and the next step as a tool call or a message. A model that reads "error" guesses. A model that reads "input error, transformable, call `list_recent_attachments`" does the next thing.

When the same failure comes back, say so. The second time is no longer the model's mistake: it is a gap in the harness, and the reply should say to report it instead of trying again.

In Ouroboros, the [friction envelope](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/tool-results.ts#L23-L29 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/tool-results.ts#L23-L29)") holds kind, recoverability, a summary, a signature and suggested next actions, and the [friction ledger](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/tool-friction.ts#L36-L55 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/tool-friction.ts#L36-L55)") rewrites a repeated signature as a harness bug. Ouroboros gives this shape to its attachment tools today; its other tools end their error text with a code whose card names the fix ([`withCode`](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/tool-error-code.ts#L9-L11 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/tool-error-code.ts#L9-L11)")).

## 2. An approval is for one exact call

When a person approves an action, freeze what they approved: the arguments (as a digest of their canonical JSON), the tool's definition and policy, and the conversation as it stood. Run that call and nothing else. If anything moved before it runs (the arguments, the tool, the policy, the conversation), the approval is void and the action does not run. An approval also expires.

The person approved what they were shown. A model that edits an argument after the tap, or a stale button tapped an hour later, must not ride on that consent.

In Ouroboros, an [approval record](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/approval-store.ts#L36-L68 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/approval-store.ts#L36-L68)") keeps the arguments and their digest, the schema, tool and policy digests, the session revision, the requester and an expiry; [`executeApprovalDecision`](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/tool-approval.ts#L405-L439 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/tool-approval.ts#L405-L439)") checks them all again before it runs, and ends the record as drifted when one differs. Ouro UI core's [chat approval cards](https://github.com/ourostack/ouro-ui-core/blob/16698c8ec52c6c597d21dae566beecfb3dccfb93/src/chat-approval.mts "verify:urlOk(https://github.com/ourostack/ouro-ui-core/blob/16698c8ec52c6c597d21dae566beecfb3dccfb93/src/chat-approval.mts)") freeze a card with its exact input in the same way.

## 3. Leave a call that may have happened to a person

When a call with side effects crashes or times out after it started, nobody knows whether it happened. Record that as its own outcome, not as a failure: a failure invites a retry, and a retry of a payment that went through is a second payment. Mark the call as started before the handler runs, so a restart finds it; tell the model that it may have happened and not to retry automatically, and leave the next step to a person or to a check of the real state.

In Ouroboros, an approved call is [marked attempted before it runs](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/tool-approval.ts#L441-L445 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/tool-approval.ts#L441-L445)"), a restart turns an attempted record into `attempted_indeterminate`, and the model reads ["execution may have occurred; do not retry automatically"](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/session-events.ts#L151 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/session-events.ts#L151)"). Ouro AX's [outcome](ax-outcome.md) names the same case for a CLI or an MCP tool.

## 4. Load tools when they are needed, and say what else exists

A model pays for the tool definitions it is sent, and has to choose among them. Keep a small set always loaded, the ones nearly every turn uses, and list the rest by name only, with one tool that loads more by name or by a few words. Add what it loads to the end of the list, so a cached prompt prefix stays valid, and keep a tool loaded once the conversation has used it.

In Ouroboros, [the always-loaded set](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/deferred-tools.ts#L20-L27 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/deferred-tools.ts#L20-L27)") is the everyday tools, and `find_tools` [lists the others by name](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/deferred-tools.ts#L51-L74 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/deferred-tools.ts#L51-L74)") and loads at most [eight per call](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/deferred-tools.ts#L13 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/deferred-tools.ts#L13)").

## 5. Fit what a tool returns, and say how to see the rest

A tool that returns a megabyte fills the model's context with one answer. Cap what a single result may put in front of the model, keep the start and the end (where the headers and the errors usually are), cut at line breaks, and put a notice where the middle was: how much was left out and how to ask for it narrowly (a tighter pattern, a line range, a filter).

In Ouroboros, [the cap](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/tool-output-budget.ts#L3-L6 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/tool-output-budget.ts#L3-L6)") is 32,000 characters, three quarters from the start, and [the notice](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/tool-output-budget.ts#L39 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/heart/tool-output-budget.ts#L39)") names the tool, the sizes and the ways to narrow. Ouro AX's [output](ax-output.md) is the same rule for a CLI's output.

## 6. Who is asking decides what the model sees, and is checked again when it acts

An agent that talks to several people should not offer one of them the tools it keeps for another. Work out per turn who the sender is to the agent (their trust, whether they are admitted, what they may ask for) and advertise only the tools that relationship allows. Then check again when a tool runs, because the relationship can change during a turn, and refuse with a code when it no longer allows the call.

In Ouroboros, a turn carries a [relationship capability envelope](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/tools-base.ts#L218-L226 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/tools-base.ts#L218-L226)") whose advertised tool names narrow the list, and [every call is authorized again](https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/tools.ts#L432-L441 "verify:urlOk(https://github.com/ourostack/ouroboros/blob/9969ef6168c6d36eee8473ee91a5dce76e42a568/src/repertoire/tools.ts#L432-L441)") before its handler runs.
