Agent Templates
Reusable agent definitions for d:spatch workspaces.
An agent template is a reusable package that defines what code an agent runs. Templates are referenced by name in workspace configurations — the same template can power multiple agent instances across different workspaces.
Template structure
Each template lives in its own directory with a dspatch.agent.yml configuration file:
The dspatch.agent.yml file declares the template's metadata, entry point, dependencies, and what resources it needs from the host environment.
Template sources
Templates can come from three places:
| Source | Description |
|---|---|
| Local directory | A path on your machine. Useful during development. |
| Git repository | A remote repo URL with optional branch or commit pinning. |
| Community Hub | Published templates shared by the d:spatch community. |
When a workspace starts, the container runtime clones or copies each template's source into the container and installs its dependencies.
Template vs. instance
A template defines what an agent does. A workspace config defines where and how it runs — its name, position in the hierarchy, environment variables, and relationships with other agents.
Agent Template Configuration
Every agent template must contain a dspatch.agent.yml file at the root of its directory. This is the only accepted filename.
Directory structure
Only dspatch.agent.yml is required. All other files are optional and depend on your agent's needs.
Field reference
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | yes | — | Display name for the agent template. |
description | string | yes | — | Short description of what the agent does. |
entry_point | string | no | agent.py | Python file to execute as the agent's main process. |
readme | string | no | — | Path to a README file, relative to the template root. |
pre_install | string | no | — | Shell script to run before dependency installation. |
post_install | string | no | — | Shell script to run after dependency installation. |
fields | map | no | — | Base64-encoded key-value pairs for template configuration. |
required_env | list | no | — | Environment variable keys this agent requires at runtime. |
required_mounts | list | no | — | Container paths that must be bind-mounted by the workspace. |
Full example
name: Code Reviewer
description: Reviews pull requests for correctness and style.
entry_point: reviewer.py
readme: README.md
pre_install: ./scripts/pre_install.sh
post_install: ./scripts/post_install.sh
fields:
system_prompt: WW91IGFyZSBhIGNvZGUgcmV2aWV3ZXIu
authority: UmV2aWV3IGFuZCBzdWdnZXN0IGNoYW5nZXMu
required_env:
- ANTHROPIC_API_KEY
required_mounts:
- /root/.claude/.credentials.jsonDependency installation
d:spatch automatically installs dependencies based on the files present in the template directory. The resolution order is:
pyproject.toml— installed withuv sync --no-devrequirements.txt— installed withpip install -r requirements.txtpackage.json— installed with the detected package manager (npm, pnpm, or yarn)
If pre_install or post_install scripts are defined, they run before and after the dependency installation step respectively.
Validation
When a workspace starts, d:spatch validates that:
- Every
required_envkey is present in the workspace or agent-levelenvmap. - Every
required_mountspath is satisfied by a mount in the workspace configuration.
If validation fails, the workspace will not start and an error is reported.
Environment Variables
Environment variables are resolved in three layers at container startup. Later layers override earlier ones.
System variables
Set by d:spatch automatically (DSPATCH_*). These cannot be overridden.
Workspace-level variables
Defined under the env key in dspatch.workspace.yml. Applied to all agents.
Per-agent overrides
Defined under agents.<name>.env in the workspace config. Override workspace-level defaults.
System variables
These are set automatically by d:spatch on every agent container.
Prop
Type
Required environment variables
Only keys listed in your template's required_env are forwarded from the host to the container. Access them with os.environ as usual.
required_env:
- OPENAI_API_KEY
- CUSTOM_SERVICE_TOKENWorkspace config example
env:
LOG_LEVEL: debug
SHARED_TOKEN: "abc123"
agents:
coder:
template: my-agent
env:
LOG_LEVEL: info # overrides workspace-level
reviewer:
template: my-agent
# inherits LOG_LEVEL=debug and SHARED_TOKEN from workspaceTemplate Fields
Use fields in dspatch.agent.yml to embed configuration that gets base64-encoded into environment variables at startup.
fields:
- name: system_prompt
label: System Prompt
type: textarea
default: "You are a helpful coding assistant."
- name: authority
label: Authority
type: textarea
default: "You may refactor code and fix bugs. Escalate API changes."Two field names are well-known and automatically decoded by the SDK:
| Field name | Environment variable | Used as |
|---|---|---|
system_prompt | DSPATCH_FIELD_SYSTEM_PROMPT | Default system_prompt in ctx.setup() |
authority | DSPATCH_FIELD_AUTHORITY | Default authority in ctx.setup() |
Explicit arguments win
Explicit arguments to ctx.setup() always override template field defaults.
Manual encoding
Field values are base64-encoded. To encode a value manually:
echo -n "Your prompt here." | base64The SDK decodes DSPATCH_FIELD_* variables automatically when referenced through ctx.setup() defaults.