# Seams and contracts

> Every place two Convoy components meet, how each is versioned, and the formats that cross each boundary: the bundle, start.json, check mode, tools.json, provider manifests and the process backend interface.

A **seam** is a place where two components meet. In Convoy each seam is either a public Go package or a versioned wire contract. Nothing reaches into another component's internals. Version numbers exist so that, once components ship from separate repositories, an old one meeting a new one fails clearly instead of misbehaving.

## The seams

| Seam | Form | Version field |
| --- | --- | --- |
| Everything that reads `.cvy` files to `dsl` | Public Go packages, including `dsl/hcldiags` | Go module version |
| CLI to server | HTTP under `/v1`; types and client in the public `api` package | The `/v1` path |
| CLI to server bundle | `bundle.Bundle` JSON | `format_version` |
| Server to runner, and to a driver plugin | `start.json`, check mode, REST `wake`, MCP, exit codes. Golden JSON in `api/contract/` | `contract` |
| Provider type to convoyd and the CLI | `convoy-provider.hcl`, compiled to `manifest.Manifest` JSON, which convoyd stores and serves | `format` |
| `dsl` tool catalog to runner tool table | `dsl/spec/tools.json`, generated from the built-in provider manifests | `version` |
| Server to process backends | Public `sdk/proc.Backend` interface | Go module version |

## Versioning policy

Bump a version only for a change an older peer would misread. Additions it can ignore do not bump it.

- **`format_version`** (bundle) is 1. The server rejects any version outside `SupportedFormats` with 422 `bundle_version_unsupported`, naming the supported ones. It checks before parsing, so an older server never guesses at a newer bundle. The CLI and server ship together in the MVP; the field is for when they do not.
- **`contract`** (runner contract) is 2. The runner contract is the shape of `start.json`, check mode, the runner's exit codes, the `wake` request and response, and `tools.json`. A runner that does not support the version exits 2 with a log line naming both versions. Version 2 carries the provider type's configuration and adds check mode. A driver plugin lists the versions it supports in its manifest's `contracts`, and convoyd refuses one with none in common.
- **`format`** (provider manifest) is 1. A server rejects a manifest whose `format` it does not know.
- **`version`** in `tools.json` changes when the file's shape changes, not when a tool is added.
- **`/v1`** is the HTTP API version.

A component that consumes a contract file keeps a copy of it. `contracts_test.go` fails when a copy differs from its source.

## The bundle

What `convoy run` sends and convoyd stores with the run.

```json title="bundle.Bundle"
{
  "format_version": 1,
  "files": {"main.cvy": "...", "prompts/writer.md": "..."},
  "env": {"REPORT_REGION": "emea"}
}
```

| Field | Content |
| --- | --- |
| `format_version` | `CurrentFormat`, 1 when built by this CLI |
| `files` | Path relative to the folder to contents. Every `.cvy` file and every file named by a `file()` call |
| `env` | Only the variables that `env()` calls reference, read on the laptop |

`env()` is for values that are not secret: they are stored with the run and returned by the API. API keys are never in the bundle; a provider's `api_key` only names a variable in convoyd's environment. The server evaluates the same files with `Bundle.Env` standing in for the environment. Nothing else from your machine reaches it.

The bundle's hash (sha256 over the format version, sorted files and env keys) is stored with each run so runs can be compared. The server does not trust the CLI's validation: it loads the bundle again and rejects the `PUT` with rendered diagnostics if there are errors.

## start.json

Instead of passing a large first turn through the environment, the controller builds `start.json` and hands it to the backend as `ExecSpec.Files["start.json"]`. The backend places it in the agent's workspace before the runner starts. Locally that is `.convoy/work/<swarm>/<run>/<agent>/start.json`. The Go type is `api.StartFile`; the version constant is `api.RunnerContract`.

```json title="start.json"
{
  "contract": 2,
  "swarm": {"name": "edge_chips", "run": 3, "goal": "...",
            "done_when": "agent.critic.output.approved == true"},
  "agent": {"name": "writer", "prompt": "<rendered prompt>",
            "output_schema": {},
            "provider": {"driver": "openai_compatible", "source": "acme/acme", "version": "1.4.2",
                         "model": "acme-large-1",
                         "config": {"base_url": "https://api.acme.example/v1",
                                    "headers": {"X-Acme-Tier": "priority"}},
                         "settings": {"temperature": 0.2}},
            "writes": ["drafts"], "watches": ["review"], "tools": ["web_search"],
            "max_turns": 50, "can_spawn": false},
  "inputs": {"findings": []},
  "server": {"url": "http://127.0.0.1:7070",
             "mcp_url": "http://127.0.0.1:7070/v1/swarms/edge_chips/mcp"}
}
```

`output_schema` and `inputs` are `null` when the agent has no `output` or `inputs`. In `provider`, `driver` is the built-in type whose driver the runner selects, empty for a driver plugin; `config` is what the driver receives, and `settings` holds only the settings that are set. `server.url` is the address the runner uses to reach convoyd: `http://127.0.0.1:<port>` by default, or `--public-url`. The token and the provider key are passed in the environment as `CONVOY_TOKEN` and the variable the provider type names, never written to disk.

### Check mode

The runner command with `--check` in place of `--start-file` loads its driver, confirms its SDK imports, prints one line, and exits 0. convoyd runs a driver plugin this way before a run's agents start.

```json title="check.json"
{"contracts": [2], "runner_version": "0.2.0"}
```

Golden copies of `start.json`, `check.json`, `wake_request.json` and `wake_response.json` live in `api/contract/`, written from the Go types, and the runner's tests read copies of them.

## Provider manifests

A [provider type](/docs/providers/) is one file, `convoy-provider.hcl`. Package `dsl/manifest` parses it with the same HCL toolkit as `.cvy` files and compiles it to `manifest.Manifest`, whose JSON is what convoyd stores and what `/v1/providers` serves, so the CLI never parses HCL it did not read from disk. The three built-in types are manifests embedded in `dsl/manifest`. See [Writing a provider type](/docs/providers/writing/#the-manifest).

## tools.json

The Python runner does not read Go, so the tool catalog crosses as data. `go generate` in `dsl/spec` writes `tools.json` from the built-in types' manifests, and a staleness test fails when it is out of date. The key `by_sdk` is kept, keyed by built-in type.

```json title="tools.json"
{
  "version": 1,
  "by_sdk": {
    "claude_agent_sdk": ["web_search", "bash", "read_file", "write_file", "edit_file"],
    "openai_agents": ["web_search", "bash", "read_file", "write_file", "edit_file",
                      "code_interpreter", "file_search"],
    "openai_compatible": ["bash", "read_file", "write_file", "edit_file"]
  },
  "swarm_tools": ["list_topics", "read_topic", "publish", "watch_topic", "create_topic",
                  "list_agents", "create_agent", "stop_agent", "report_progress", "finish"]
}
```

The runner's `test_contract` loads its copy and fails if a DSL name listed for an SDK has no row in the runner's table, or the table names a tool the file does not list. See [Runner](/docs/runtime/runner/#tool-name-mapping).

## Process backend

The package `sdk/proc` is public because out-of-tree backends implement it. It imports only the standard library.

```go title="sdk/proc/proc.go"
type Backend interface {
    Create(ctx context.Context, spec CreateSpec) (Handle, error)        // make the agent's workspace
    Exec(ctx context.Context, h Handle, cmd ExecSpec) (Process, error)  // write cmd.Files, then start cmd.Argv
    Kill(ctx context.Context, processID string) error                   // by stored ID, even from before a restart
    Destroy(ctx context.Context, h Handle) error                        // kill and remove
}

type CreateSpec struct{ Swarm string; Run int; Agent string }

type ExecSpec struct {
    Argv  []string
    Env   map[string]string
    Files map[string][]byte   // path relative to the workspace root; written before Argv starts
}

type Process interface {
    ID() string                  // opaque to convoyd: a pid locally, a container or sandbox id elsewhere
    Wait() <-chan ExitStatus
    Logs() io.ReadCloser         // combined stdout and stderr
    Kill() error
}
```

Rules every backend follows, so a remote sandbox can implement the same interface:

- **No shared filesystem.** Everything the runner needs arrives in `ExecSpec.Files` and `ExecSpec.Env`. convoyd never reads the workspace.
- **HTTP only.** The runner reaches convoyd over HTTP at `server.url` and `server.mcp_url`. The exit status and logs come back through `Process`. Nothing else crosses.
- **Opaque identifiers.** `Handle` and `Process.ID()` are stored and passed back unchanged.
- **Runner availability is the backend's job.** The runner command must exist in the workspace: locally `convoyd` unpacks its built-in runner and starts it with `uv`, and a container or sandbox has it baked into the image.

The runner command is `[--runner, "--start-file", "start.json"]` for a built-in type or a preset. For a driver plugin it is the manifest's `command`, with `{package}` replaced by the package folder, then `--start-file start.json`.

### The local backend

`server/internal/proclocal` is the MVP backend. `Create` makes `<work-dir>/<swarm>/<run>/<agent>/`. `Exec` writes the files, then runs the command in that folder with a clean environment (`PATH`, `HOME`, `CONVOY_TOKEN`, and the variables the provider type names, such as its key) and its own process group, so `Kill` can signal the group. Stdout and stderr go to `agent.log` events in 4 KB chunks. `ID()` is the pid. `Destroy` kills the group and leaves the folder; `convoyd gc` removes folders of ended runs.

### Future sandbox plugins

Post-MVP, the interface gains `Reattach(ctx, h, processID) (Process, error)` so a backend can adopt a runner that outlived a convoyd restart. Out-of-tree backends, such as a Docker or remote sandbox backend, implement the same interface without changing the DSL. A backend whose processes run on another host requires `--public-url`.

## The store interface

Everything above storage depends on `store.Store`, not on `database/sql`. It is internal to the server, so it is not a public seam, but it is a contract: any backend must pass the suite in `store/storetest`, which checks atomic rollback, compare-and-set status updates, gapless increasing `seq` per run, atomic turn accounting, durability across reopen and concurrent transactions. The MVP ships only SQLite. See [convoyd](/docs/runtime/#storage).
