# How the lead agent works

> One lead agent per thread — it assesses complexity, plans when needed, and builds with the full toolset.

Each thread has one interactive **lead agent**. There is no mode picker. The agent has the full toolset on every turn and decides how much ceremony the work needs.

## How it chooses a path

| Complexity | What happens |
| ---------- | ------------ |
| **Trivial** | Implements directly — a typo fix, a one-line change, a quick question. |
| **Moderate** | Sketches a brief approach in chat, then builds. |
| **Complex** | Writes a **living plan** as a versioned document. You review it as a card in the thread — it also appears in the Knowledgebase's Plans section — then click **Build**. |

Plans aren't throwaway chat. They're documents the system keeps honest — re-checked as `main` moves, updated when the ground shifts, one click from becoming a thread that opens a PR. [Plans & the Build button](https://darting.dev/docs/plans-and-build/) covers the whole lifecycle.

## What the lead can do

The lead agent can read and write files, run commands, drive the UI, spawn [sub-agents](https://darting.dev/docs/sub-agents/), and attach or create plan documents. Heavy work — builds, test suites, Playwright runs — happens inside [isolated sandboxes](https://darting.dev/docs/isolated-sandboxes/), not on your machine.

## Streams and recovery

Each turn creates a **completion stream** — a single execution attempt. Streams end when the agent finishes, you stop it, it errors, or it loops. The raw message log is written to disk after each stream, so a refresh, crash, or server restart never loses your history — the conversation is reconstructed from that log, not from memory.

You can **stop** mid-stream and **continue** later; continuing starts a fresh stream that picks up where you left off. See [checkpoints, stop & rewind](https://darting.dev/docs/checkpoints-and-rewind/).
