# Language reference

> Every block, attribute, function, tool, price, and validation code of the Convoy language. Generated from the dsl package.

# Convoy language reference

<!-- Generated by `go generate ./dsl/spec`. Edit dsl/spec/rules.md, the schema table in dsl/decode, or the rule table in dsl/validate instead. -->

## Language rules

A swarm is a folder of `.cvy` files written in HCL, the syntax Terraform uses. Prompt files usually live in `prompts/`.

- **Files.** Every `*.cvy` file in the folder is read and merged; files in subfolders are not. Block order and file boundaries do not matter. Exactly one `swarm` block must exist across all files.
- **Blocks.** A block is a type, one label, and a body: `agent "writer" { ... }`. There are four block types: `swarm`, `provider`, `topic`, and `agent`. The label is the block's name. Names contain letters, digits, and underscores, start with a letter or underscore, and are unique within their type. The agent name `overseer` is reserved.
- **Attributes.** `name = expression`. Value types are string, number, bool, list, map, and object. Durations are strings with a unit: `"30s"`, `"10m"`, `"4h"`.
- **References.** `provider.<name>`, `topic.<name>`, and `agent.<name>` refer to blocks. `agent.<name>.output` is the JSON an agent passed to `finish`, and `agent.<name>.output.<field>` reads one field of it. References appear only in `provider`, `writes`, `watches`, `depends_on`, `inputs`, `done_when`, and the swarm's `overseer`. Every other attribute is constant: literals and functions only.
- **for_each.** Allowed on `agent` blocks only. The value is a set of strings (use `toset([...])`, never a bare list) or a map. One agent is created per element, named `<name>[<key>]`, for example `researcher[nvidia]`. Inside `prompt` and `vars`, `each.key` and `each.value` refer to the current element. `agent.<name>` is then an object keyed by instance key: `agent.<name>["nvidia"].output` is one instance's output, and `values(agent.<name>)[*].output` is the list of all of them.
- **Dependency graph.** Every reference inside `inputs` or `depends_on` is an edge from the referenced agent to this one. The graph must have no cycles. References inside `writes`, `watches`, and `done_when` are not edges; feedback loops go through topics.
- **Starting and finishing.** An agent with no `inputs` and no `depends_on` starts when the swarm starts; otherwise it starts when every agent it references has finished, and receives its `inputs` as JSON in its first turn. After its first turn, an agent takes another turn when a topic it watches gets a message, or a message is addressed to it. An agent that watches nothing takes continue turns until it calls `finish` or reaches `max_turns`. `finish(output)` ends the agent; when the agent declares `output`, the payload is checked against it.
- **Ending the swarm.** `done_when` is evaluated each time an agent finishes. When it is true, the run is Done. When `max_runtime` elapses first, the run is Stopped with reason `max_runtime`; when spend reaches `max_cost_usd`, it is Stopped with reason `budget`. When every agent has finished and `done_when` is still false, the run Failed.
- **Prompts.** `prompt` is almost always `file("prompts/<name>.md")`. Prompt files are not HCL templates: `${...}` in them is plain text. Use `{{name}}` placeholders, replaced from `vars`; a placeholder with no matching var is left as it is.
- **Functions.** `file(path)` reads a file relative to the folder. `env(name)` reads a variable on the machine running `convoy run`; the value is sent to the server, so never use it for secrets. The arguments of `file()` and `env()` must be literal strings.
- **Models.** A provider's `model` is the default for every agent on that provider, and for the overseer when it names that provider. An agent's own `model` wins. An agent needs one or the other.
- **Secrets.** A provider's `api_key` is the name of a variable in convoyd's environment, never the key itself.
- **Comments.** `#` and `//` to end of line, `/* */` for blocks.

## Block: swarm

Exactly one. Declares the goal and the stopping rules.

| Attribute | Type | Required | Default | Meaning |
| --- | --- | --- | --- | --- |
| `goal` | string | yes |  | The goal in plain language. Shown to every agent and to the overseer. |
| `done_when` | bool expression | yes |  | When true, the swarm is Done. May reference `agent.<name>.output.<field>` for agents that declare an `output` shape. Evaluated each time an agent finishes. |
| `max_runtime` | duration | yes |  | Wall-clock limit for the whole run, such as `"4h"`. When reached, every agent is stopped and the run is Stopped with reason `max_runtime`. |
| `max_cost_usd` | number | no |  | Dollar budget for the whole run, counting every agent and the overseer. When spend reaches it, every agent is stopped and the run is Stopped with reason `budget`. Turns in flight finish, so spend can exceed it by up to one turn per running agent. |
| `overseer` | object `{ provider, model, can_spawn }` | no |  | The overseer's provider (a `provider` reference) and model. `model` may be left out when the provider sets one. `can_spawn` (default `true`) controls whether the overseer may create agents. When omitted, convoyd's `--overseer-provider` and `--overseer-model` are used. |

## Block: provider

One or more. Declares one configured use of a provider type: how to reach a model provider and which driver runs its agents. Besides the core attributes below, a provider block takes the attributes its type defines; the built-in types' attributes are listed under Provider types.

| Attribute | Type | Required | Default | Meaning |
| --- | --- | --- | --- | --- |
| `source` | string | yes |  | The provider type: a built-in type (`claude_agent_sdk`, `openai_agents`, `openai_compatible`), or an address `<namespace>/<name>` or `<host>/<namespace>/<name>` of a type that convoyd fetches from the git repository `convoy-provider-<name>`. |
| `version` | string | no | the newest version the server has | A version constraint, such as `"~> 1.4"` or `">= 1.2, < 2.0"`. Not allowed with a built-in type. A prerelease is selected only by an exact version. |
| `model` | string | no |  | The default model for every agent on this provider, and for the overseer when it names this provider. An agent's own `model` wins. |
| `price` | object `{ input, output, cache_read, cache_write }` | no | the type's model catalog | USD per million tokens for every model on this provider, overriding the type's prices. `input` and `output` are required; the cache prices default to `input`. |
| `settings` | object | no | `{}` | Defaults for the `settings` of every agent on this provider. Its keys are the type's settings. |
| `sdk` | string | no |  | Deprecated name of `source`, accepted for the three built-in types. Set exactly one of `source` and `sdk`. |

## Block: topic

Zero or more. Declares one channel on the message board.

| Attribute | Type | Required | Default | Meaning |
| --- | --- | --- | --- | --- |
| `description` | string | yes |  | One line saying what belongs here. Shown to every agent in its topic list. |

## Block: agent

One or more. Declares one agent, or several when `count` or `for_each` is set.

| Attribute | Type | Required | Default | Meaning |
| --- | --- | --- | --- | --- |
| `count` | whole number | no |  | Creates that many identical agents, named `<name>[0]`, `<name>[1]`, and so on. `count.index` is available in `prompt` and `vars`. `agent.<name>` is then a list. Not allowed with `for_each`. |
| `for_each` | set of strings or map | no |  | Creates one agent per element, named `<name>[<key>]`. `each.key` and `each.value` are available in `prompt` and `vars`. `agent.<name>` is then an object keyed by instance key. |
| `provider` | provider reference | yes |  | The `provider` block to run under, as `provider.<name>`. |
| `model` | string | no | the provider's `model` | The model name, passed to the driver unchanged. Required unless the agent's provider sets `model`. A type with a closed catalog warns about a name it does not list. |
| `prompt` | string | yes |  | The agent's instructions, almost always `file("prompts/<name>.md")`. `{{name}}` placeholders are replaced from `vars`. |
| `vars` | map of string | no |  | Values substituted into the prompt: `{{vendor}}` becomes `vars.vendor`. |
| `tools` | list of string | no | `[]` | Built-in tools of the provider's type that this agent may use. Swarm tools are always available and are not listed here. |
| `settings` | object | no | `{}` | Settings of the provider's type for this agent, such as `{ effort = "high" }`. Each key resolves from the agent's `settings`, then its provider's `settings`, then the type's default; a setting none of them sets is not passed. |
| `inputs` | map of expression | no |  | Named values the agent needs before it starts. Each must reference another agent's output. The agent starts when every referenced agent has finished and receives the values as JSON in its first turn. |
| `depends_on` | list of agent references | no |  | Agents that must finish before this one starts. Like `inputs`, but nothing is passed. |
| `writes` | list of topic references | no | `[]` | Topics this agent may publish to. |
| `watches` | list of topic references | no | `[]` | Topics whose new messages give this agent a turn. With none, the agent takes continue turns until it calls `finish`. |
| `output` | object type | no |  | The shape of the `finish` payload, such as `{ approved = bool, score = number }`. Field types are `string`, `number`, `bool`, `list(...)`, `map(...)`, and nested objects. |
| `max_turns` | number | no | `50` | The agent is stopped after this many turns. |
| `can_spawn` | bool | no | `false` | Whether this agent may call `create_agent`. |

## Provider types

A provider block's `source` names its type. The three built-in types ship with Convoy; any other type is a plugin that convoyd fetches from its git repository, and `convoy provider show <source>` prints its reference. Each type defines the provider block's other attributes, the `settings` its agents take, the built-in tools they may list, and its models with their prices.

### `claude_agent_sdk`

Claude models through the Claude Agent SDK.

| Attribute | Type | Required | Default | Meaning |
| --- | --- | --- | --- | --- |
| `source`, `version`, `model`, `price`, `settings` | | | | The core attributes of every provider block. |
| `api_key` | environment variable name | no | `"ANTHROPIC_API_KEY"` | The **name** of an environment variable in convoyd's environment that holds the key. Never the key itself, and never an expression. The runner receives the value as `ANTHROPIC_API_KEY`. |

| Setting | Type | Default | Meaning |
| --- | --- | --- | --- |
| `effort` | `string`, one of `"low"`, `"medium"`, `"high"`, `"xhigh"`, `"max"` |  | How much effort the model spends on each response. Passed as the Agent SDK's `effort`. |
| `max_thinking_tokens` | `number`, 0 or more |  | The most tokens the model may spend thinking in one response. Passed as the Agent SDK's `max_thinking_tokens`. |

Tools: `web_search`, `bash`, `read_file`, `write_file`, `edit_file`.

| Model | Input | Output | Cache read | Cache write | Notes |
| --- | --- | --- | --- | --- | --- |
| `claude-fable-5-1` | 10 | 50 | 0.25 | 12.5 |  |
| `claude-opus-5-5` | 4 | 20 | 0.2 | 5 |  |
| `claude-sonnet-5-5` | 2 | 10 | 0.2 | 2.5 |  |
| `claude-haiku-5-5` | 0.1 | 0.5 | 0.01 | 0.125 |  |
| `claude-opus-5` | 5 | 25 | 0.5 | 6.25 |  |
| `claude-sonnet-5` | 2 | 10 | 0.2 | 2.5 |  |

Other model names are accepted and passed through unchanged.

### `openai_agents`

OpenAI models through the OpenAI Agents SDK.

| Attribute | Type | Required | Default | Meaning |
| --- | --- | --- | --- | --- |
| `source`, `version`, `model`, `price`, `settings` | | | | The core attributes of every provider block. |
| `api_key` | environment variable name | no | `"OPENAI_API_KEY"` | The **name** of an environment variable in convoyd's environment that holds the key. Never the key itself, and never an expression. The runner receives the value as `OPENAI_API_KEY`. |

| Setting | Type | Default | Meaning |
| --- | --- | --- | --- |
| `temperature` | `number`, 0 to 2 |  | Sampling temperature. Passed as `ModelSettings.temperature`. |
| `max_tokens` | `number`, 1 or more |  | The most tokens one response may produce. Passed as `ModelSettings.max_tokens`. |

Tools: `web_search`, `bash`, `read_file`, `write_file`, `edit_file`, `code_interpreter`, `file_search`.

| Model | Input | Output | Cache read | Cache write | Notes |
| --- | --- | --- | --- | --- | --- |
| `gpt-6-astra` | 10 | 50 | 1 | 12.5 |  |
| `gpt-6.1-sol` | 2 | 10 | 0.1 | 2.5 |  |
| `gpt-6.1-terra` | 1 | 5 | 0.05 | 1.25 |  |
| `gpt-6-luna` | 0.1 | 0.5 | 0.01 | 0.125 |  |

Other model names are accepted and passed through unchanged.

### `openai_compatible`

Any Chat Completions endpoint, through the OpenAI Agents SDK.

| Attribute | Type | Required | Default | Meaning |
| --- | --- | --- | --- | --- |
| `source`, `version`, `model`, `price`, `settings` | | | | The core attributes of every provider block. |
| `api_key` | environment variable name | no | `"OPENAI_API_KEY"` | The **name** of an environment variable in convoyd's environment that holds the key. Never the key itself, and never an expression. The runner receives the value as `OPENAI_API_KEY`. |
| `base_url` | `string` | yes |  | The endpoint, for example `http://localhost:11434/v1`. |
| `headers` | `map(string)` | no |  | Headers sent with every request, as the client's default headers. |

| Setting | Type | Default | Meaning |
| --- | --- | --- | --- |
| `temperature` | `number`, 0 to 2 |  | Sampling temperature. Passed as `ModelSettings.temperature`. |
| `max_tokens` | `number`, 1 or more |  | The most tokens one response may produce. Passed as `ModelSettings.max_tokens`. |

Tools: `bash`, `read_file`, `write_file`, `edit_file`.

Models: any name, passed to the endpoint unchanged.

Every agent also has the swarm tools, which are never listed in `tools`: `list_topics`, `read_topic`, `publish`, `watch_topic`, `create_topic`, `list_agents`, `create_agent`, `stop_agent`, `report_progress`, `finish`. `create_agent` is given only to agents with `can_spawn = true`.

## Functions

`concat`, `contains`, `distinct`, `env`, `file`, `fileexists`, `flatten`, `format`, `join`, `jsondecode`, `jsonencode`, `keys`, `length`, `lookup`, `lower`, `merge`, `replace`, `split`, `templatefile`, `tobool`, `tolist`, `tomap`, `tonumber`, `toset`, `tostring`, `trimspace`, `upper`, `values`

`file`, `fileexists`, and `templatefile` take paths relative to the swarm folder. `env` fails when the variable is not set. `toset` turns a list into a set for `for_each`. `agent.<name>[*].output` lists every output of a `count` agent, and `values(agent.<name>)[*].output` every output of a `for_each` agent.

## Prices

When `max_cost_usd` is set, every model needs a price: the provider's `price`, else the price in its type's `model` block. The built-in types' prices, USD per million tokens:

| Type | Model | Input | Output | Cache read | Cache write |
| --- | --- | --- | --- | --- | --- |
| `claude_agent_sdk` | `claude-fable-5-1` | 10 | 50 | 0.25 | 12.5 |
| `claude_agent_sdk` | `claude-opus-5-5` | 4 | 20 | 0.2 | 5 |
| `claude_agent_sdk` | `claude-sonnet-5-5` | 2 | 10 | 0.2 | 2.5 |
| `claude_agent_sdk` | `claude-haiku-5-5` | 0.1 | 0.5 | 0.01 | 0.125 |
| `claude_agent_sdk` | `claude-opus-5` | 5 | 25 | 0.5 | 6.25 |
| `claude_agent_sdk` | `claude-sonnet-5` | 2 | 10 | 0.2 | 2.5 |
| `openai_agents` | `gpt-6-astra` | 10 | 50 | 1 | 12.5 |
| `openai_agents` | `gpt-6.1-sol` | 2 | 10 | 0.1 | 2.5 |
| `openai_agents` | `gpt-6.1-terra` | 1 | 5 | 0.05 | 1.25 |
| `openai_agents` | `gpt-6-luna` | 0.1 | 0.5 | 0.01 | 0.125 |

Any other model needs a `price` on its provider, such as `price = { input = 0, output = 0 }` for a local model.

## Validation codes

`convoy validate` reports these. Errors stop `convoy run`; warnings are printed.

| Code | Severity | Rule |
| --- | --- | --- |
| TS001 | error | Exactly one `swarm` block. |
| TS002 | error | A required attribute is missing. |
| TS003 | error | An attribute has the wrong type, or a constant attribute refers to something. |
| TS004 | error | An agent or the swarm's `overseer` has no model: it sets no `model`, and neither does its provider. |
| TS010 | error | A reference names a block or instance that does not exist. The message suggests the closest name. |
| TS011 | error | `source` is neither a built-in type name nor a well-formed address; `version` is not a valid constraint or is set on a built-in type; both `source` and `sdk` are set, or neither; `sdk` is not one of the three built-in types. |
| TS012 | error | The provider block does not match its type: a required attribute is missing (such as `base_url` for `openai_compatible`), an attribute the type does not define is set, or a value fails its type or its checks. |
| TS013 | error | A `tools` entry the provider's type does not offer. The message lists the offered tools. |
| TS014 | error | An `env_name` attribute, such as `api_key`, is not a literal environment variable name (for example, it calls `env()` or contains a key). |
| TS015 | error | An agent is named `overseer`, which is reserved for the built-in overseer. |
| TS016 | error | The provider type could not be resolved: no version meets the constraint, the repository was not found, the manifest is invalid, or its runner contract is not supported. |
| TS017 | warning | The provider type was not checked, because no server could be reached. When a cached manifest was used instead, the message names its version and age. |
| TS018 | error | `settings` on a provider or an agent does not match the type's settings: an unknown key, a wrong type, or a failed check. |
| TS019 | warning | `model` is not in the type's catalog, and the type does not set `open_models`. The message suggests the closest name. |
| TS020 | error | The dependency graph (`inputs` and `depends_on`) has a cycle. |
| TS021 | error | `done_when` or an `inputs` value reads `agent.X.output.<field>` where X declares no `output`. |
| TS022 | error | `done_when` or an `inputs` value reads a field that is not in X's `output` type. |
| TS023 | error | `done_when` or an `inputs` value references something other than an agent's output. |
| TS030 | error | `for_each` is a list, a set of non-strings, or not known before the swarm runs. |
| TS031 | error | `each` is used in an agent without `for_each`. |
| TS032 | error | `count` is not a whole number from 0 to 1000, or is not known before the swarm runs. |
| TS033 | error | `count.index` is used in an agent without `count`. |
| TS034 | error | An agent sets both `count` and `for_each`. |
| TS040 | error | A `file()` path does not exist, is outside the swarm folder, or is not UTF-8. |
| TS041 | error | A `file()`, `templatefile()`, `fileexists()`, or `env()` argument is not a constant string, so `convoy run` cannot bundle what it names. |
| TS042 | error | A variable named by `env()` is not set when `convoy run` builds the bundle. |
| TS050 | warning | A topic that no agent writes to. |
| TS051 | warning | A topic that no agent watches. |
| TS052 | warning | An agent with non-empty `watches` and no explicit `max_turns`. |
| TS053 | warning | An agent with no `watches`, no `inputs`, and no `writes`, whose `output` no `inputs` or `done_when` reads: its work reaches no one. |
| TS054 | warning | A var in `vars` that the prompt never uses. |
| TS055 | warning | An agent with no `watches`, no `output`, and no explicit `max_turns`: it takes continue turns until it calls `finish`, so it should set its own limit. |
| TS060 | error | `max_cost_usd` is set and a model used by an agent or the declared `overseer` has no price: no `price` on its provider and none in its type's `model` block. |
| TS061 | warning | `max_cost_usd` is not set; nothing limits the swarm's spend. |
| TS062 | error | `max_cost_usd` is not a number greater than zero. |
| TS063 | error | `price` is not an object with numeric `input` and `output` of 0 or more, or has keys other than `input`, `output`, `cache_read`, `cache_write`. |
| TS070 | warning | A deprecated attribute, setting, or model of the provider's type is used. The message carries the type's `deprecated` text. |

## Manifest codes

`convoy provider validate` reports these for a provider type's `convoy-provider.hcl`. All are errors.

| Code | Rule |
| --- | --- |
| PM001 | Exactly one `provider` block, whose label matches `^[a-z][a-z0-9_]*$`. |
| PM002 | A required attribute is missing, an attribute or block type is unknown, a value has the wrong type, or the file does not parse. |
| PM010 | Not exactly one of `driver` and `command`. |
| PM011 | `driver` is not a built-in type, or `tools` lists a tool the built-in type does not offer. |
| PM012 | `driver_config` or `driver_settings` references an attribute or setting the manifest does not declare, or does not produce the built-in type's attributes or settings. |
| PM013 | An attribute or block of the other kind: `tool` blocks, `contracts`, or `inject_as` in a preset; `driver_config`, `driver_settings`, or `tools` in a driver plugin. |
| PM020 | A duplicate or invalid name among `attribute`, `setting`, `model`, or `tool` blocks, or an `attribute` named like a core attribute (`source`, `version`, `sdk`, `model`, `price`, `settings`). |
| PM021 | An invalid type; a `default` or `enum` value that does not fit the type or its checks; `pattern` on a non-string or `min`/`max` on a non-number; an invalid `pattern`. |
| PM022 | `env_name` on a `setting`; an `env_name` attribute with no `inject_as` in a driver plugin; `inject_as` on another type or not a variable name; an `env_name` default that is not a variable name. |
| PM030 | A `model` price is malformed (the rule of TS063). |
| PM040 | `contracts` is missing, empty, or lists a number below 1; `format` is not supported. |
| PM041 | `command` is empty, or a `{package}` path in it leaves the package. |
