# 12. The simplest agent

> **Status: partly implemented.** The unified 24-layer pure-Coax agent runtime
> ([`openagents/core/core.coax`](../../openagents/core/core.coax),
> [`openagents/core/query_loop.coax`](../../openagents/core/query_loop.coax),
> [`openagents/core/wire.coax`](../../openagents/core/wire.coax)) and native
> worker ([`coder/tui/oa-worker.coax`](../../openagents/runtime/oa-worker.coax),
> `#14050`–`#14053`) ship and pass their `#test` checks on `cpu`, driving
> [`apps/openagents-desktop`](../../apps/openagents-desktop) behind the
> OpenAgents Cloud gateway and local `psionic-inkling-serve`. Remaining: wiring
> the opening chapter 6 `coax drive` chat-page case directly through `oa-worker`
> and adding the standalone `openagents/agent/loop.coax` teaching wrapper.

## Premise

Chapter 4 left the chat page on the iPhone answering from a fake service,
and chapter 6 runs its case. This chapter puts the first real agent behind
it: one loop that reads a message, calls one model, streams the reply and
writes both to a log. Every later chapter adds one thing to this loop and says how to tell
whether it helped.

## Draft

An agent is a loop around a model. [Episode 5](../../docs/transcripts/005.md)
defines it with five words: chat, plans, actions, users and tasks. The
smallest version has only the first. You type a message, the loop sends it to
a model, and the model's reply comes back.

That loop is where the 2023 wave of general agents started, and it is where
they stalled. The loop can talk, but it can't do dependable work. It doesn't
know your repository, your policy or your customer. Nobody can say whether it
is right. Its cost has no bound. It has no job a buyer would pay for. And
nothing says what it may touch. The general-agent essay calls these six
pressures: execution, local knowledge, evaluation, cost, a buyer and
authority.

We start with the bare loop on purpose. You can read all of it in one sitting,
and each of the six gaps is easy to see in it. The rest of the book closes
them one at a time. It does not close them by making the loop smarter. It
closes them by putting specialized members behind the loop and by measuring
each member before the loop relies on it.

The Coder book starts from the same place for one job, a repository task. This
book starts there for every job. Where the two overlap, this book links to
Coder's chapter and does not repeat it.

## What we build

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

- A loop in Coax: one message in, one model call through the gateway, one
  reply out, and a log line for each.
- The loop answers chapter 4's chat page in place of the fake service's
  replies, through the same actions, so chapter 6's case still passes.
- A `chat` verb in the `openagents` command line that runs the loop from a
  terminal. This is a plan; the verb's name is the owner's to set.
- A fixture run with a recorded model reply, so the loop's checks run with no
  network.

It builds on what exists today:

- [`openagents/core/core.coax`](../../openagents/core/core.coax), [`openagents/core/query_loop.coax`](../../openagents/core/query_loop.coax), and [`openagents/core/wire.coax`](../../openagents/core/wire.coax) (unified 24-layer pure-Coax runtime, `#14050`–`#14057`)
- [`coder/tui/oa-worker.coax`](../../openagents/runtime/oa-worker.coax) (native worker running behind Desktop and CLI)
- [`coax/lib/gateway`](../../coax/lib/gateway)
- [`coax/lib/agent/journal.coax`](../../coax/lib/agent/journal.coax)
- [`apps/openagents-cli`](../../apps/openagents-cli)

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

| Record | Schema | Carriage | Today |
| --- | --- | --- | --- |
| The log | Coder's transcript log, id `openagents.session.v1` on disk; planned package `openagents.session.log.v1alpha1` ([compliance plan](../../docs/protocol/2026-11-11-compliance-plan.md), step C1) | A file of JSON lines; not sent | Planned. Written by hand in `coax/lib/agent/session/log.coax` |

### The chapter's check

- **Source:** the loop in `openagents/agent/loop.coax`, run against a fake
  gateway that replays one recorded model reply. No network is used.
- **Trace:** chapter 6's case, with the loop in place of the fake
  service's replies: `type composer.input hello`, `tap composer.send`,
  then `state transcript` prints `you: hello` and the recorded reply,
  byte for byte. `logs` prints one line for the message and one for the
  reply.
- **Refusal:** the fake gateway answers the model call with an error. No
  reply part appears, the transcript ends with `notice: model call
  failed`, and `logs` records the failed call.
- **Independent check:** chapter 6's case passes unchanged on every target
  it names, and the session record's own checks
  (`coax/bin/coax test coax/lib/agent/session/session.coax`) still pass.
  The logged reply matches the fixture's reply, written by hand.

Planned paths: `openagents/agent/loop.coax`. It drives the engines and the
session record in [`coax/lib/agent/`](../../coax/lib/agent) and adds no
second session record.

## Sources

- **Episodes:**
  - [Episode 1, *Intro*](../../docs/transcripts/001.md): the first statement of the project
  - [Episode 5, *Agent First Principles*](../../docs/transcripts/005.md): agents as chat, plans, actions, users and tasks
  - [Episode 289, *OpenAgents*](../../docs/transcripts/289.md): what the loop becomes
- **Old code at `coder-v1.0.0`, crates:** `openagents-chat`, `openagents-cli`
- **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`), Part I: the six pressures
  - [Coder book, chapter 1: The simplest loop](../../coder/book/ch001-the-simplest-loop.md)
- **Promises covered** ([audit](../../docs/audits/2026-11-10-episode-289-port-audit.md#1-what-episode-289-promised)): P1
