# Overview

> The components of Convoy, what each owns, what talks to what, and the path a convoy run takes from your terminal to a running agent.

Convoy has three programs and one language. The `convoy` CLI validates files and calls the server. The `convoyd` server holds all state and runs the control loop. A Python **runner** process, one per agent, wraps an agent SDK. The DSL package, `dsl`, is shared by the CLI and the server, so a file that validates on your laptop validates on the server with the same code.

## The parts

| Part | What it does | MVP choice |
| --- | --- | --- |
| [`convoy` CLI](/docs/cli/) | Generates swarm files from a goal, validates them, sends them, shows status | Go, single binary |
| [API server](/docs/architecture/api/) | Holds every swarm, agent, topic and message. The only way anything changes | Go, REST plus SSE, plus an MCP endpoint for agents |
| State store | Agent specs and status, an append-only event log, the messages | SQLite |
| [Controller](/docs/runtime/controller/) | Every few seconds and on every event, compares what is running with what is declared, then starts or stops agents and enforces limits and the budget | Go |
| [Message board](/docs/runtime/board/) | Topics as append-only logs, one read cursor per agent per topic, messages optionally addressed to one agent | Tables in the state store, streamed to `convoy watch` over SSE |
| [Runner](/docs/runtime/runner/) | One process per agent. Runs the SDK session, waits on the server between turns, reports each turn's token usage | Python, one driver per SDK |
| [Overseer](/docs/concepts/overseer/) | A built-in agent that reads the board, judges progress against the goal, and creates, stops or instructs agents | A runner with a fixed prompt, started by convoyd |
| [DSL](/docs/dsl/) | Parsing, decoding, `for_each` expansion, references, validation, the dependency graph, provider type manifests and the three built-in types, the bundle format | Go packages, HCL via `hcl/v2` |

## What talks to what

| From | To | How |
| --- | --- | --- |
| CLI | convoyd | HTTP under `/v1`, JSON bodies, SSE for `watch`. Types and client in the public `api` package |
| convoyd | runner | Starts a process through the process backend; writes `start.json` into its work folder; sends stop through the `wake` response, then `SIGTERM` |
| runner | convoyd | REST for `wake`, `GET /agents`, `GET /topics` |
| model (inside the SDK) | convoyd | MCP over Streamable HTTP at `/v1/swarms/{name}/mcp` |
| controller | board | Publishes to `system`; signals stop to a blocked `wake` |
| controller, handlers | store | Transactions that write state and events together |
| overseer | convoyd | The same MCP tools as any agent, plus `note_progress` |

Two rules follow. The CLI and the runners never talk to each other. And no component reaches into another's internals: every meeting point is a public Go package or a versioned wire contract, listed on [Seams and contracts](/docs/architecture/contracts/).

## A convoy run, end to end

### The CLI validates and bundles

`convoy run` loads the folder with the `dsl` package and validates it. It then builds a **bundle**: every `.cvy` file, every file named by `file()`, and the non-secret `env()` values. API keys are never read or sent.

```json
{
  "format_version": 1,
  "files": {"main.cvy": "...", "prompts/writer.md": "..."},
  "env": {}
}
```

### PUT /v1/swarms/{name}

The CLI sends the bundle. The server checks the format version, loads the bundle with the same `dsl` code, and runs its own checks: the name matches, no run of this swarm is active (`swarm_active`), an overseer is declared or defaulted (`overseer_missing`), every provider key variable is set in convoyd's environment (`missing_env`), and every model has a price when a budget is set (`unpriced_model`). Provider types that are not built in are resolved first, from convoyd's store or their git repository, and a driver plugin is started once in check mode (`provider_check_failed`); the run records the version and digest of each.

```http
PUT /v1/swarms/edge_chips HTTP/1.1
Authorization: Bearer <token>
```

### One transaction creates the run

The server inserts a run with the next number and status `pending`, one `agents` row per instance (also `pending`), the declared topics plus `progress` and `system`, and the overseer's row. It emits `run.created` and answers 201 with the run number and the agent list.

```json
{"name": "edge_chips", "run": 1, "status": "pending", "agents": ["..."]}
```

### The controller starts the run

On its next pass the controller sets the run `running`, emits `run.started`, and posts `swarm started` to `system`. It starts the overseer first, then every agent whose `inputs` and `depends_on` are satisfied, as long as fewer than `--max-processes` runners are alive. For each: mint a token, build `start.json`, create the work folder, exec the runner.

```text
.convoy/work/edge_chips/1/researcher__nvidia__/start.json
```

### Runners turn, wake, and call tools

Each runner reads `start.json`, builds its system prompt, and runs the first turn. The model calls swarm tools over MCP: `publish`, `read_topic`, `report_progress`, `finish`. When the turn ends the runner calls `wake` with the turn's usage. The server prices the turn, adds it to the run's spend, and holds the call until the board has news, a stop, or 30 seconds pass.

```http
POST /v1/swarms/edge_chips/agents/writer/wake
```

### The run ends

After every event the controller checks the budget, `max_runtime` and `done_when`. When one fires, it stops every agent through the stop sequence, keeps all outputs, and emits `run.ended`. The CLI, which exited long ago, can read the result with `convoy status`.

```console
$ convoy status edge_chips
```

Meanwhile `convoy watch` holds one SSE connection to `GET /v1/swarms/{name}/watch`. It receives the same ordered event log the controller reads, so the terminal view needs no polling.

## Repository and processes

One repository and one Go module hold everything, laid out so each component can later move out. See [Repository layout](/docs/architecture/repository/). For the server's internals, see [convoyd](/docs/runtime/).
