Subagents
Subagents let the Spectral coding agent delegate work to specialized sub-agents. Each sub-agent runs in an isolated context window with its own system prompt, filtered tool set, and optional model override — keeping the main conversation lean and focused.
How It Works
┌──────────────────────────────────────────┐
│ Main Agent Session │
│ │
│ User: "Review all auth files" │
│ │ │
│ ▼ │
│ subagent({ agent: "reviewer", │
│ task: "Review src/auth/" }) │
│ │ │
│ ▼ (isolated context) │
│ ┌──────────────────────────┐ │
│ │ Sub-agent: reviewer │ │
│ │ Tools: read, grep, ls │ │
│ │ Model: claude-haiku-4-5 │ │
│ │ → reads auth files │ │
│ │ → produces review │ │
│ └──────────┬───────────────┘ │
│ │ │
│ ▼ │
│ Main agent receives review result │
│ → continues with the output │
└──────────────────────────────────────────┘
Defining an Agent
Agents come from two sources only:
- Built-in system agents — compiled into the CLI (
ghostorchestrator plusresearcher,executor,reviewer, andforksubagents). Read-only. - Cloud agents — your team's agents, managed in Aexol Studio on the
/agentspage and synced to the CLI through the backend.
Local agent folders are not read. Files in
~/.spectral/agent/agents/or.spectral/agents/do not produce agents — create and manage agents in Studio (/agents) instead.
Example: Code Reviewer
Frontmatter Fields
| Field | Required | Type | Purpose |
|---|---|---|---|
name | ✅ Yes | string | Unique identifier (snake_case). Used when calling subagent({ agent: "…" }). Set on the Studio /agents page. |
description | ✅ Yes | string | Sent to the LLM so it knows when to delegate to this agent. |
systemPrompt | ✅ Yes | string | Instructions injected as the agent's system prompt. |
mode | ❌ No | string | "subagent" (default) or "primary". A primary agent's prompt is injected into the main session. |
model | ❌ No | string | Model override (e.g. claude-haiku-4-5, anthropic/claude-sonnet-4-5). Falls back to session model if omitted. |
Available Tools
Built-in tools: read, bash, apply_patch, bash_status, bash_kill.
Extension-registered tools (like recall, designer_*) are also resolved dynamically — any tool registered by loaded extensions is available, minus the subagent-excluded tools: subagent, compact_context, receive_agent_observations, and share_project_observation.
Execution Modes
The agent invokes subagents through the subagent tool with three modes:
Single Mode
Delegate one task to one agent:
{
"agent": "reviewer",
"task": "Review all route handlers in src/routes/ for missing error handling"
}
Parallel Mode
Run up to 8 tasks in parallel (max 4 concurrent):
{
"tasks": [
{ "agent": "reviewer", "task": "Review src/auth/" },
{ "agent": "reviewer", "task": "Review src/api/" },
{ "agent": "doc-writer", "task": "Generate docs for packages/parser/" }
]
}
Chain Mode
Sequential execution where each step sees the previous output via {previous}:
{
"chain": [
{ "agent": "investigator", "task": "Find all type errors in the project" },
{ "agent": "fixer", "task": "Fix the following errors: {previous}" }
]
}
If any step fails, the chain stops and returns the error.
Context Isolation
Each sub-agent invocation gets:
| Resource | Isolated? | Detail |
|---|---|---|
| Messages | ✅ Fresh | Starts with only the task message |
| System prompt | Combined | Main prompt + sub-agent instructions |
| Context window | ✅ Separate | No access to main conversation history |
| Tools | ✅ Filtered | Full tool set minus the subagent-excluded tools |
| Model | Overridable | Agent-configured model or session default |
| Abort signal | Propagated | Main session's abort signal passed through |
Agent Discovery
Discovery merges two layers — later layers override earlier ones on name collision (a cloud agent replaces a built-in system agent with the same name):
| Layer | Source | Notes |
|---|---|---|
| 1. System | Built-in SYSTEM_AGENTS in the CLI code | Read-only; always available, even offline |
| 2. Cloud | Backend cache via the GraphQL agents query | Refreshed at session start and on team bind; managed in Studio /agents |
Cloud agents are always enabled — there is no agentScope parameter on the subagent tool anymore. Discovery never throws and never touches the network: offline or logged-out sessions simply get the built-in system agents.
Model Resolution
Sub-agents resolve their model in this order:
- Session model (if available and has configured auth)
- Agent-configured model (from the
modelfrontmatter field) - Error — if neither is available
The model string supports two formats:
- Short:
claude-sonnet-4-5(fuzzy match by model ID) - Fully qualified:
anthropic/claude-sonnet-4-5(exact provider + model ID)
Example Agents
Documentation Writer
---
name: doc-writer
description: Generates API documentation from source code
tools: read, grep, find, ls
model: claude-sonnet-4-5
---
You are a technical writer. When given a source file or directory:
1. Read the code thoroughly
2. Extract the public API surface (exports, functions, classes, types)
3. Write clear, concise documentation with examples
4. Output valid Markdown suitable for API references
Test Generator
---
name: test-gen
description: Generates unit tests for uncovered code paths
tools: read, grep, find, ls, bash, write
model: claude-sonnet-4-5
---
You are a test engineer. When given a source file:
1. Read the file and its existing tests (if any)
2. Identify uncovered branches and edge cases
3. Generate thorough unit tests following project conventions
4. Write the test file using the `write` tool
Agents vs. Extensions
| Aspect | Agents | Extensions |
|---|---|---|
| Definition | Studio (/agents) or built-in system agents | TypeScript (index.ts) |
| Purpose | Specialized LLM sub-processes | Tools, commands, event hooks |
| Context | Isolated per invocation | Shared with main agent |
| Tool access | Filtered subset | Full access + register new tools |
| Loading | Startup + cloud refresh (GraphQL agents query) | Runtime discovery at startup |
| Locations | Code (SYSTEM_AGENTS), cloud backend cache | .spectral/extensions/, ~/.spectral/agent/extensions/ |