# How the Model Actually Works

Course: Agentic Coding: Run Coding Agents Like an Operator — Lesson 2 of 10

The model is stateless and emits only text: see the messages array your harness resends every turn, and how to budget a plan with a weekly cap.

> **The one line:** the model is a stateless text function, your harness resends the whole
> conversation every turn, and all you control is what sits in that array.

## A conversation is an array you resend

The model keeps nothing between calls. Every request carries the whole conversation as an
array of messages, and the answer comes from it alone.

So a bare follow-up fails:

```ts
const messages = [
  { role: "user", content: "What is your best memory about him?" },
];
```

There is no "him". Send the array instead:

```ts
const messages = [
  { role: "user", content: "Who is General Kenobi?" },
  { role: "assistant", content: "A Jedi Master and general in the Clone Wars." },
  { role: "user", content: "What is your best memory about him?" },
];
```

Now "him" resolves: the earlier turns are in the payload.

Your harness stores the transcript, appends your message and resends the lot: `CLAUDE.md`,
`AGENTS.md`, tool schemas, the last forty tool results, all as text in that array. "Context
management" is choosing what goes in there.

## Everything the model emits is text

An edit, a tool call, JSON, an SVG, a git diff: all text, in a shape the harness has agreed
to recognise.

A tool call is a round trip:

1. The harness sends the array plus the tool schemas.
2. The model emits a block naming one tool and its input.
3. The harness stops generation, runs the tool for real, and appends the result.
4. The longer array goes back for the next turn.

```ts
// what the model emitted
const assistantTurn = {
  role: "assistant",
  content: [
    {
      type: "tool_use",
      id: "toolu_01",
      name: "Read",
      input: { file_path: "/src/auth.ts" },
    },
  ],
};

// what the harness appends after running it, before resending everything
const toolResultTurn = {
  role: "user",
  content: [
    {
      type: "tool_result",
      tool_use_id: "toolu_01",
      content: "export const verifyToken = (token: string) => { ... }",
    },
  ],
};
```

The model never opened the file. It emitted a request; your machine did the reading. Edits
work the same way: a patch as text, applied by the harness. Permission prompts sit between
the emitted text and the real action.

Anything the model knows about your repository is text someone put in the array. Cost and
latency scale with it, because you pay for it again every turn.

Runnable demos: [How AI-Powered Apps Actually Work](/blog/ai-powered-apps).

## How much fits

As of writing, current Claude models run a 1M-token window by default on the API; older and
smaller models such as Haiku 4.5 give you 200K. Fable 5, Sonnet 5, Opus 4.6 and newer, and
Sonnet 4.6 support a 1M window on the API; Sonnet 5 is always 1M. In Claude Code the upgrade
is automatic for Opus only, and only on Max, Team and Enterprise; Sonnet 4.6 at 1M needs
usage credits on every plan. You re-send and re-pay for the whole array each turn, so filling
the window costs you on every message after.

## Your plan is a budget, not a tap

On Max 20x two limits apply at once: a rolling five-hour window and a weekly cap. Fable 5 has
its own allowance there, and I would rather run a hundred Opus agents than one Fable pass.

Treat the weekly cap like an allowance: check what is left early in the week and divide by
the days you plan to work. One long refactor, or a workflow spawning dozens of subagents, can
swallow a day's share. Paid plans buy extra usage when you run out, and Anthropic sometimes
grants promotional credits. If my cap is untouched on Friday, I have not been coding enough.

Many cheap agents in parallel beat one expensive model on most real tasks, and they finish
sooner. When usage runs low, one line in your global rules file pushes all subagents onto a
smaller model while your main session stays on Opus:
[Rules Files and Scope](/courses/agentic-coding/rules-files-and-scope).

## What to do

- Read one session transcript and find the message boundaries: system prompt, rules files, your turns, tool results. Raw JSONL is punishing; [`peektrace`](/products/peektrace) renders readable sections.
- Assume nothing carries between turns unless you can point at the text that carries it.
- Check plan usage before a long refactor or a multi-agent run.
- Divide the remaining weekly allowance by the days you plan to work; re-check daily.
- Prefer several cheap agents in parallel over one maximum-effort model.
- Set your global rules file to downgrade subagent models when usage is tight.

## Links

- Lesson page: https://andrey-markin.com/courses/agentic-coding/how-the-model-actually-works
- Course: https://andrey-markin.com/courses/agentic-coding.md
- Next lesson: https://andrey-markin.com/courses/agentic-coding/rules-files-and-scope.md
