# Acting under someone else's rules

An agent that pays, signs or moves anything usually answers to rules the app does not
write: a mandate, a policy service, a signed delegation. Five seams carry that, all off
until passed to `App.load`:

```ts
const app = await App.load({
  root,
  authority, // check(attempt) -> { allow } | { refuse } | { stepUp, digest }
  journal: { sink, signer }, // every acting step sealed, chained, signed, delivered
  payer, // a 402 paid once per step, status before pay
  botAuth, // every outbound request signed (Web Bot Auth), key directory served
  sandbox, // snapshot per step, restore before recovery
  runCipher, // runs sealed at rest
});
```

A function says what it does as an `action`, computed from the arguments it was actually
given, and whether its output can be trusted:

```ts
export default fn({
  input: { to: "who", amount: "how much" },
  effect: "write",
  action: ({ to, amount }) => ({ operation: "pay", counterparty: String(to), amount: String(amount) }),
  run: async ({ to, amount }, { fetch = globalThis.fetch }) => (await fetch(`https://pay.example/${to}?amount=${amount}`)).json(),
});
```

The authority is asked after `guard.ts` on every path: the model's tool loop, workflow
steps, HTTP, MCP and the CLI. A refusal goes back to the model as the tool's result. A
`stepUp` on a workflow step pauses the run at `<step>:approve`; the approval must be
signed over a claim that includes the action's `digest`, and the step is asked again
with the verified approver attached. Once untrusted output (a fetched page, an inbox)
has been read, every later action in that conversation or run is marked `tainted`, so
the authority can insist on a person for anything the text might have put there.

An authority can be a policy in prose, read against each call by a model:

```ts
import { permissionClassifier } from "@praecise/harness";

const authority = permissionClassifier({
  policy: "Refunds up to 100 are fine. Anything that sends email needs a person.",
  models: config.models,
  rung: "fast",
});
```

It answers allow, deny or ask, and ask becomes a `stepUp`. It is shown what the
person said and the calls the agent has made (`attempt.recent`), never what a
tool returned or what the model wrote, so text the agent merely read cannot
argue its own case. Identical calls are answered from memory (the last 500
decisions, or `remember`). A classifier that cannot be reached, whose answer
cannot be read, or that has not decided within `timeoutMs` (20 seconds by
default) does not allow the call. `allowReads: true` lets calls that declare
`effect: "read"` through without asking, `endpoint` names which of `models`
decides, and `onDecision` is told every decision.

In a conversation, a `stepUp` can be answered mid-turn: `approve` on an ask is
handed the call and its digest, puts the question to a person, and returns the
approval once `app.approvalOf(asking, decision)` has verified it. The authority
is then asked again with the approval attached.
