# 15. Decide before you generate

> **Status: partly implemented.** The typed `openagents.router.v2alpha1` router
> (`RoutePlan`, [`coax/lib/agent/router/router.coax`](../../coax/lib/agent/router/router.coax),
> [`decide.coax`](../../coax/lib/agent/router/decide.coax),
> [`policy.coax`](../../coax/lib/agent/router/policy.coax),
> [`native-choice.coax`](../../coax/lib/agent/router/native-choice.coax),
> [`replay-check.coax`](../../coax/lib/agent/router/replay-check.coax), `#14056`,
> `#14071`) passes on `cpu` (`66/66` dev, `30/31` held-out) and routes native
> OpenAgents Core vs opt-in external delegation in
> [`coder/tui/oa-worker.coax`](../../openagents/runtime/oa-worker.coax). Remaining:
> mobile/web front integration and live multi-door latency benchmarking in
> `openagents/agent/front/`.

## Premise

Chapter 14 defines the plan. This chapter fills it in: the front asks a
decision model a few typed questions about each message and builds the plan
from the probabilities it gets back.

## Draft

A front has to be right, fast and cheap on every turn, and it has to answer in
a form code can act on. A chat model is a poor fit for that job. It is trained
to write text that reads well to a person, and nobody reads a router's output.

A decision model takes one state and a set of typed questions, such as yes or
no, a choice among named options, or a score. It answers with probabilities.
For each message the front asks: which route is this, does a prepared answer
fit, does it need more specifics, what is the risk, does the work need a
computer, and did the person name an engine? One request answers all of them.

[Episode 289](../../docs/transcripts/289.md) gives the reason this works now
when our earlier attempts did not: the models are good enough, and a type-safe
decision model makes routing feasible. In the old tree, one request answered
every router question in about 170 ms at the median. [Episodes
285](../../docs/transcripts/285.md) to [287](../../docs/transcripts/287.md)
are the work that led there.

Every decision goes through our Decisions API. Since 2026-11-13 (#13473),
Google's Gemini Decision 1 answers first, and the model a caller used before
is the fallback ([the door order](../../docs/research/2026-11-13-gemini-decision-1.md);
[`coax/lib/systemone`](../../coax/lib/systemone)). New code never calls one
vendor's model directly.

We do not route by matching keywords. A message goes where the typed decision
says, and chapter 16 measures how often that is right.

## What we build

A plan for what this chapter ships once the draft is approved:

- The front: one typed request per message, answered through the Decisions
  API, turned into a plan.
- A question set pinned by digest, so a result names exactly what was asked.
- Failover across decision routes, with the route that answered written to the
  log.

It builds on what exists today:

- [`coax/lib/agent/router/router.coax`](../../coax/lib/agent/router/router.coax), [`decide.coax`](../../coax/lib/agent/router/decide.coax), [`policy.coax`](../../coax/lib/agent/router/policy.coax), [`native-choice.coax`](../../coax/lib/agent/router/native-choice.coax), and [`replay-check.coax`](../../coax/lib/agent/router/replay-check.coax) (`openagents.router.v2alpha1` typed `RoutePlan`, `66/66` dev / `30/31` held-out, `#14056`, `#14071`)
- [`coax/lib/systemone`](../../coax/lib/systemone)
- [`psionic/lib/decision-models.coax`](../../psionic/lib/decision-models.coax)
- [`psionic/lib/decision-plan.coax`](../../psionic/lib/decision-plan.coax)
- [`coax/lib/nostr/dec`](../../coax/lib/nostr/dec)
- [`coax/lib/nostr/cj`](../../coax/lib/nostr/cj)

On the protocol ([chapter 65](ch065-one-schema-three-carriages.md)):

| Record | Schema | Carriage | Today |
| --- | --- | --- | --- |
| Decision request and answer | `openagents.decision.v1alpha1` `SystemOneRequest`, `SystemOneResponse` ([`systemone.proto`](../../proto/openagents/decision/v1alpha1/systemone.proto); [spec 16.1](../../docs/protocol/openagents-protocol-spec.md#161-openagentsdecisionv1)) | HTTP `POST /api/v1/systemone`; Nostr kind 25910, encrypted (NIP-DEC) | In use on the server: the generated codec `psionic/lib/serve-proto.coax`. The client writes the JSON by hand in `coax/lib/systemone/request.coax`. The JSON contract stays the definition, and a fixture to pin it is planned ([compliance plan](../../docs/protocol/2026-11-11-compliance-plan.md)) |

### The chapter's check

- **Source:** the front in `openagents/agent/front/`, asking the Decisions
  API through a fake decision service that replays recorded
  probabilities. The clock is controlled.
- **Trace:** for the message `hello`, the trace prints the pinned question
  set's digest, each question's probabilities, the chosen route
  (conversation) and the plan built from it. The log names the door that
  answered: Gemini Decision 1.
- **Refusal:** the first door times out on the controlled clock. The front
  asks the fallback, and the log names the fallback as the door that
  answered. A recorded answer for a different question-set digest is
  refused with `refused: question set digest mismatch`, and no plan is
  built.
- **Independent check:** the client's hand-written request JSON from
  `coax/lib/systemone/request.coax` is read by the generated server codec
  `psionic/lib/serve-proto.coax`, a separate implementation of
  `systemone.proto`, and the fields match.

Planned paths: `openagents/agent/front/`.

## Sources

- **Episodes:**
  - [Episode 289, *OpenAgents*](../../docs/transcripts/289.md): 1:00, routes matched through a decision model
  - [Episode 285, *Bendcoder*](../../docs/transcripts/285.md): classification before generation
  - [Episode 286, *System One in Coding Agents*](../../docs/transcripts/286.md)
  - [Episode 287, *Building a System One Coding Agent*](../../docs/transcripts/287.md): measured decision probes
- **Old code at `coder-v1.0.0`, crates:** `jev`, `jev-hosted`, `route-contract`, `openagents-chat`
- **NIPs:** [NIP-DEC](../../nostr/nips/openagents/NIP-DEC.md), [NIP-CJ](../../nostr/nips/openagents/NIP-CJ.md)
- **Also:**
  - *The Return of the General Agent* (`git show coder-v1.0.0:docs/essays/2026-10-01-the-return-of-the-general-agent.md`), "Why the front is feasible now: decision models"
- **Promises covered** ([audit](../../docs/audits/2026-11-10-episode-289-port-audit.md#1-what-episode-289-promised)): P7

## Open questions for the owner

1. Which of our own decision models backs up Gemini Decision 1 for the
   front at 1.0, and what result would move our own model to the first door?
2. What does the front do when no decision route answers: plain conversation
   with no routing, as the old tree did, or a visible error?
