Agents and roles
The agent lifecycle, roles, vendors and the tools an agent sees.
Agent lifecycle
shepherd spawn <role> <task> (or s in the Agents view, or a pattern run) does this:
- Resolves the role into a vendor, a model and a fallback, using the configuration.
- Checks the limits (
max_concurrent,max_depth). - If the role has
worktree: true, creates agit worktreeand a branchshep/<n>-<task>under~/.shepherd/worktrees/<repo>/. - Installs the role's skills and starts the vendor in a terminal pane, with Shepherd's MCP server injected and a token of its own.
- Sends the first prompt: the task, or the persona defined in a pattern.
States: starting, then working and idle alternating. blocked means a person is needed (a trust dialog, a login, a question). done means it delivered a result. killed and exited are final.
$ shepherd agents
ID STATE ROLE VENDOR MODEL TASK
specialist-1 starting specialist codex - Task-1-demo- Open its terminal:
shepherd attach <agent>(orEnterin the Agents view). That is where you answer permission prompts and questions. - Clean up: a finished agent is removed with
xin the Agents view. Its snapshots are kept according tomax_per_agent. - Agents without MCP: bus messages are typed into their terminal as
[shep] from <role>#<n>: ...when the pane is idle. - Inherited configuration: agents inherit your global vendor configuration (for example
~/.claude/CLAUDE.md). If it demands plan approval before editing, the agent will wait. Include the approval in the task.
shepherd spawn accepts --vendor and --model to override a role for one agent, and --task-id to link the agent to a task. To link or detach an agent later, use shepherd assign <agent> <task-id|none> (or l in the terminal Agents view). After a server restart, shepherd resume (u in the terminal Agents view) marks the agents it left behind and shepherd reconcile checks them against their terminals; neither starts anything.
Roles
A role is a named job description. It is not a vendor: it says which vendor and model are the default for that job, plus permissions and skills.
| Role | Default vendor | Purpose | Own worktree | May start agents |
|---|---|---|---|---|
brain | claude / opus | Plan, split work, aggregate results | no | yes |
coder | codex (fallback gemini, claude) | Implement | yes | no |
reviewer | gemini (must differ from the coder's vendor) | Review code and security | no | no |
docs | gemini | Documentation and docs questions | no | no |
tester | claude / sonnet | Tests and debugging | no | no |
See what your configuration resolves to:
$ shepherd roles list
brain claude/opus
coder codex/default
docs gemini/default
reviewer gemini/default
tester claude/sonnetChanging a role or adding one
Roles live in config.yaml, globally (~/.config/shepherd/config.yaml) or per project (<repo>/.shepherd/config.yaml). Write only what changes; everything else comes from the defaults, and maps merge deeply (a null value resets a key).
roles:
coder:
vendor: claude # instead of codex
model: sonnet
worktree: true
specialist: # a new role with any name
vendor: codex
worktree: false
prompt: You focus on database migrations.
skills: [lang-go, debug]| Field | Meaning |
|---|---|
vendor | Which vendor runs the role |
model | Model; empty means the vendor's default |
fallback | Alternative vendors if the main one is not available |
must_differ_from | The vendor must differ from another role's (cross-review) |
worktree | The agent works in its own worktree and branch |
can_spawn | The agent may start sub-agents (the spawn_agent tool) |
skills | Skills specific to this role |
prompt | Your own instructions for the role |
Check the result with shepherd config validate. Common problems it reports: a role pointing at an unknown vendor or fallback, a must_differ_from that names an unknown role, or limits below 1.
In the native app, the Models view lists the agents and models installed on your machine, grouped by vendor, and lets you pick them for each role without editing YAML.
What you do with a role
- Use one as it is. The five built-in roles are enough to start:
brainplans,coderimplements,reviewerreviews,docswrites documentation,testerwrites and runs tests.shepherd spawn coder "..."or a pattern that namesrole: coderuses it. - Change one. Write only what changes in
config.yaml, for exampleroles: {coder: {vendor: claude, model: sonnet}}. Everything else keeps its default. - Add your own. Add a new name under
roles:when a job needs its own vendor, model, skills or prompt: agopher, amigrator, asecurity-auditor. Patterns can use it right away. - Check it.
shepherd config validatefinds a role that points at an unknown vendor, amust_differ_fromthat names an unknown role, and skills that do not exist.shepherd roles listshows what each role resolves to.
Vendors
Shepherd drives agent CLIs. Three are built in:
| Vendor | Command |
|---|---|
claude | claude |
codex | codex |
gemini | agy |
$ shepherd vendors list
claude claude available
codex codex available
gemini agy availableA vendor entry in config.yaml describes how to start it and how to reach it:
| Field | Meaning |
|---|---|
command, args | Executable and startup arguments |
models, default_model, model_flag | Available models, the default, and the flag that selects one |
print_args | Arguments of the non-interactive mode |
mcp.supported, mcp.style | Whether MCP is supported and how it is injected |
skills.mode, skills.style, skills.file | How skills are delivered (native, instructions, prompt) |
shepherd_agent | The name the agent detector knows it by |
disabled | Excludes the vendor; roles fall back to their fallback |
To switch a vendor off: vendors: { gemini: { disabled: true } }.
MCP tools an agent sees
Agents with MCP support see these as tools of the shepherd server (a local HTTP server, with one token per agent).
| Tool | What it does |
|---|---|
spawn_agent | Start a sub-agent (only roles with can_spawn: true) |
send_message, read_messages | Direct message to another agent by id or role; read and drain pending ones |
wait_for | Wait for given agents to deliver a result or exit |
submit_result, get_result | Deliver the final result; read another agent's without blocking |
list_agents | Agents in the session with role, vendor, state and worktree |
get_diff | Full diff of a coder's worktree against the base branch |
run_checks | Runs the project's checks (workflow.checks, or cargo test, pytest, npm test, go test ./... when it has none) in an agent's worktree, yours by default, and returns PASSED or FAILED with each command's exit code and the end of its real output. Pass or fail is the exit code, not an agent's reading. Each command has a time limit (timeout_secs, default 600, at most 3600) and is killed with everything it started when it runs out |
read_output | Last N lines of an agent's pane |
ask_docs | Ask the docs agent (started if needed) and wait |
get_task_context, update_task_context | Read the task (issue, spec, criteria, plan) or, for brain and docs only, update it. In pattern runs it returns the objective and the topology |
get_workspace_instructions | Repository instructions, effective skills, detected checks |
publish, subscribe, poll, ack, replay, list_topics | The event bus, see Topics and events |
Limits protect you from runaway trees: max_depth bounds how deep agents may start agents, and max_concurrent bounds how many work at once.