# Agent Design Guidelines Agents should be lean, focused, and trust the system around them. ## Target Structure Every agent should follow this template (~50-150 lines total): ```markdown --- frontmatter (name, description, model, effort, skills, tools or disallowedTools, omitClaudeMd) --- # Agent Name [Identity paragraph - 2-4 sentences describing role and autonomy level] ## Input Context [What the orchestrator passes: structured list of parameters] ## Responsibilities [5-7 numbered items: what this agent does] ## Principles [4-6 focused principles guiding behavior] ## Output [Simple structured report format] Report cap: [the final message is at most about 1,500 tokens; longer material goes to a `mktemp` file whose path the message gives; name the exempt fields, which stay inline in full: the ones a command or test parses, or an orchestrator passes to another agent] ## Boundaries [What to escalate vs handle autonomously] ``` ## Tool Restrictions Use the `tools` frontmatter field to restrict which tools an agent can access. Claude Code enforces this at platform level — the agent physically cannot call tools outside the allowlist. This is far more reliable than prompt-level prohibitions. ```markdown --- name: Skim tools: ["Bash", "Read"] --- ``` When an agent only needs a subset of tools, prefer platform-enforced restriction over prompt instructions. An agent holds one tool policy, never both: - **Allowlist (`tools:`)** — the agent holds exactly the tools named. This is the default for an agent that needs no user-environment MCP or web access. A whole-server entry `mcp__` grants every tool that server exposes, deferred behind `ToolSearch`; an entry for a server that is not connected grants nothing and does not block launch. Git and Tracker list only built-in tools in source, and the installer appends one `mcp__` per configured tracker server. - **Denylist (`disallowedTools:`)** — the agent keeps every tool except the ones named, MCP and web tools included. Use it where the agent must keep that access (Code, Fix, Refactor, Research). Code, Fix, Refactor, Research, Harden and Polish also deny `Monitor`, `TaskStop`, `Workflow`, `Artifact`, `ListAgents` and `ReportFindings`, because no path of these agents uses them, and each start pays tokens for every tool it lists. They start, stop and message no agent and publish no page. None of them starts a background run: Harden runs only the test files it changed, and Polish runs no build, test or lint command. The end notice re-invokes a spawned subagent whose foreground call passes its timeout, so none needs `Monitor`. None of them reports findings with `ReportFindings`: Harden reports in its final message and Research writes its findings to `OUTPUT_PATH`. Harden and Polish also deny `mcp__*`, which drops every MCP tool and keeps web access, so code scanning runs in Code alone. Spell every other name out: a wildcard removes every name it matches. Add a new key as a YAML block list, one name per line. Neither key is touched by `devflow agents --set` or by the reapply on `devflow init`, which rewrite only the `model:` and `effort:` lines; the tracker-server stamp is the one installer edit to a `tools:` line. An allowlist silently constrains how an agent can act, so the body must not direct a tool its frontmatter removes. That covers a call, "the X tool", a skill load and a `ToolSearch` `select:` load, and also every verb: update, refresh, amend, append and patch imply `Edit`, and loading a skill implies `Skill`. `tests/guards/agent-config.test.ts` holds the shipped table and checks the body and each preloaded skill against it. An agent that has Bash is given no Grep or Glob tool in Claude Code, even when its `tools:` list names them. Write its search steps as Bash commands (`git grep -P`, `find`), and never rely on the two names. ## Effort and Project Context - `effort:` (`low`, `medium`, `high`, `xhigh` or `max`) is the agent's shipped reasoning effort, set on the line after `model:`. Lower effort on a mechanical agent is a deliberate saving. An agent with no `effort:` line follows the session. - `omitClaudeMd: true` keeps CLAUDE.md (user, project, local) and the rule files under `~/.claude/rules/` out of the agent's context. Thirteen agents ship it: Validate, Git, Triage, Evaluate, Test, Research, Knowledge, Tracker, Curate, Skim, Synthesize, Explore, Plan. Each restates the core rules it works by under `## Core rules`, exactly its `CORE_RULES_DIGEST` row (`tests/fixtures/agent-config.ts`, held by `tests/guards/core-rules-digest.test.ts`). An agent that needs more reads it: Curate reads the root CLAUDE.md and the installed devflow rules before its first already-encoded comparison. Code, Fix, Refactor, Harden, Polish, Review, Design and Debug keep CLAUDE.md. ## Length Guidelines | Agent Type | Target Lines | Examples | |------------|-------------|----------| | Utility | 50-80 | Skim, Polish, Validate | | Worker | 80-120 | Code, Review, Git, Design | | Orchestration | 100-150 | (Commands handle orchestration, not agents) | ## What Belongs Where | Content | Location | Rationale | |---------|----------|-----------| | Engineering patterns (Result types, DI) | Skills | Shared across agents | | Git safety, commit conventions | Skills | Consistent enforcement | | Review methodology | Skills | Reusable across review types | | Branch setup | Orchestrator | Agent receives ready feature branch | | Codebase exploration | Explore agents | Dedicated agents do exploration | | Implementation planning | Plan agents | Dedicated agents do planning | | Task identity + responsibilities | Agent | Core agent definition | | Input/output contract | Agent | Interface with orchestrator | | Escalation boundaries | Agent | Clear handoff points | ## Anti-Patterns to Avoid 1. **Duplicating skill content** - Don't re-document what skills provide. Reference skills via frontmatter. 2. **Embedding bash scripts** - Agents know how to code. Don't over-specify implementation details. 3. **Re-doing orchestrator work** - If orchestrator creates feature branch, agent shouldn't document branch creation. 4. **Verbose phase documentation** - A worker agent implements; it doesn't need exploration and planning phases. 5. **Progress tracking templates** - Trust the agent to log appropriately without detailed echo scripts. 6. **Listing auto-activating skills** - Skills auto-activate based on context; no need to enumerate triggers. 7. **Skill-invoking a frontmatter-preloaded skill** - Any skill in the agent's `skills:` frontmatter is already active. A body instruction to invoke that same skill via `Skill(skill="devflow:")` hits the re-entrancy guard and returns `devflow: already running`. The agent treats this guard string as a terminal instruction and returns with zero tool uses while the workflow reports success — a silent complete-failure. Symptom: agent finishes in under 5 seconds with no tool calls. Fix: remove the `Skill(...)` call for any skill already in the frontmatter. (See `skills-architecture.md` § "Frontmatter preload and Skill-tool invocation are mutually exclusive".) ## Quality Checklist Before committing a new or modified agent: - [ ] Under 150 lines (ideally under 120) - [ ] Single identity paragraph (not multiple paragraphs of context) - [ ] Input contract clearly defined - [ ] Output format simple and structured, ending in a `Report cap:` line that names the exempt fields (grep the commands that spawn the agent for the fields they read) - [ ] Boundaries section present (escalate vs handle) - [ ] No duplicated skill content - [ ] No bash script templates - [ ] Skills referenced in frontmatter, not re-documented in body ## Per-Agent Model Overrides Devflow ships with explicit model assignments in agent frontmatter (Opus for analysis, Sonnet for execution, Haiku for I/O). You can override these per-agent without touching the source files — overrides persist across `devflow init` reinstalls. **Source of truth:** `~/.devflow/agent-models.json` stores deviations from shipped defaults (absent entry = shipped default, model and effort alike; `"model": "default"` and `"effort": "default"` remove the key). A shipped default is the `model:` and, when the agent has one, the `effort:` of its frontmatter, so an agent that ships an effort keeps it across a reapply. `"effort": "inherit"` is a stored value, not a removal: it drops the agent's `effort:` line so the agent follows the session, and the shipped effort does not apply behind it. `memory` is a settable worker entry in the same map (Claude models and effort levels only); it is not an agent and has no frontmatter to rewrite. **Management:** ```bash npx devflow-kit agents # Interactive TUI — navigate, cycle model, save npx devflow-kit agents --list # Print all agents with current assignments npx devflow-kit agents --set review --model sol # Assign one agent via CLI (alias auto-tracks current generation) npx devflow-kit agents --reset # Reset all agents to shipped defaults (prompts) npx devflow-kit agents --reset --yes # Skip confirmation prompt ``` **Convergence:** `reapplyAgentMapping` runs after every `devflow init` (post-install). It reads `agent-models.json` and rewrites the matching agent frontmatter so your assignments survive reinstalls and plugin updates. **Dormancy:** GPT model assignments are dormant when external model routing is disabled. The TUI shows dormant assignments with a dim annotation (`sol saved`). Enabling routing via `devflow proxy --enable` applies the saved mapping; disabling reverts frontmatter to Claude defaults while preserving the mapping for re-enable. Model aliases (e.g. `sol`, `terra`, `luna`) auto-track the current generation — no config edit needed when new models ship. **When adding a new agent:** the shipped model and effort in frontmatter are the default; if users have overridden them via `agent-models.json`, `reapplyAgentMapping` will apply their override on the next `devflow init`. **Spawns never name a model:** a spawn that passes `model=` (or a workflow `agent()` call that passes `opts.model`) overrides the installed frontmatter at spawn time, so a user's override for that agent never reaches it. Leave the model to the frontmatter; `tests/guards/spawn-no-hardcoded-model.test.ts` fails on any spawn in the prompt sources that names one. ## Adding New Agents ### Shared Agents (used by multiple plugins) 1. Create the agent in `src/assets/agents/{agent-name}.md` 2. Follow existing agent patterns (clear specialty, restricted tools, focused scope, specific output) 3. Add agent name to the `agents` array of each plugin entry in DEVFLOW_PLUGINS (`src/core/plugins.ts`) that needs it 4. For an agent whose prompt is generated rather than hand-written, author it instead as an `.mds` generator host `src/assets/agents/{agent-name}.mds` declaring `output-dir: dist/agents` in its leading steering block, and run `npm run build:mds` to compile it to `dist/agents/{agent-name}.md` 5. Run `node dist/cli.js init` to install (a hand-authored `.md` needs no build step; a generator host must be compiled first) 6. Test with explicit invocation ### Plugin-Specific Agents (tightly coupled to one workflow) All agents live in `src/assets/agents/` — there is no separate per-plugin agent directory. For an agent used by only one plugin, add it to `src/assets/agents/` and declare it in only that plugin's `agents` array in DEVFLOW_PLUGINS. **Hook-spawned agents.** `curate` and `tracker` are spawned by session-start directives, never by a command. `tracker` sits in `devflow-core-skills`, whose empty `commands: []` is what makes the registry's reverse spawn check skip it structurally rather than by exemption. **Note:** `src/assets/agents/` holds the source for every agent. A hand-authored `{name}.md` (for example, `test.md`) installs directly with `node dist/cli.js init`. Compile an `.mds` generator host (for example, `evaluate.mds`, `git.mds` or `code.mds`) with `npm run build:mds`. The installer checks the compiled sources first, then `src/assets/agents/`. If neither has the agent, the installer reports an error. Evaluate uses the variant for the machine's [UI design check](../cli-reference.md#design).