Skip to main content

What are Sub-Agents?

Sub-agents allow you to create modular, reusable agents that can be composed together. A parent agent can delegate specific tasks to specialized sub-agents through tool calls.
Sub-agents are automatically converted to tools that parent agents can call. Each sub-agent uses the parent entry’s maxSteps, then the leaf agent’s own maxSteps, then the 100-step default.

Basic Usage

Define a Sub-Agent

Create researcher.agentuse:
The agent name is automatically derived from the filename (e.g., researcher.agentuse becomes researcher).

Use the Sub-Agent

Create main.agentuse:
Sub-agents are called as tools using their filename (without .agentuse). The researcher.agentuse becomes available as the researcher tool.

Multiple Sub-Agents

Sub-Agent Configuration

You can customize sub-agent behavior:

Path Resolution

All sub-agent paths are resolved relative to the parent agent file’s directory, ensuring portability across different execution contexts.
See Agent Syntax - Subagents for complete path resolution examples and directory structure recommendations.

Remote Sub-Agents

Remote sub-agents are not currently supported. Sub-agents must be local files accessible via the filesystem.

Passing Context

Sub-agents accept optional parameters when called as tools:

Sub-Agent Tool Schema

Each sub-agent tool accepts:
  • task (optional string): Additional instructions for the sub-agent
  • context (optional object): Structured data to pass to the sub-agent
The sub-agent receives its original instructions plus any additional task and context.

Advanced Patterns

Conditional Delegation

Limitations: No Nested Sub-Agents

Important: Sub-agents cannot have their own sub-agents. Any subagents configuration in a sub-agent file will be ignored.
This limitation is intentional to:
  • Prevent infinite recursion (Agent A → Agent B → Agent A)
  • Avoid deep nesting complexity that’s hard to debug
  • Reduce resource consumption and token usage
  • Keep execution traces manageable
Sub-agents only have access to their configured MCP tools, not other sub-agents. Each sub-agent creates its own isolated MCP connections.

Parallel Processing

Sub-agents run sequentially, not in true parallel. The parent agent calls each sub-agent tool one at a time.

Sub-Agent Communication

Tool and Resource Inheritance

Sub-agents create their own isolated tool environments:
MCP server commands with relative paths are resolved from the agent file’s directory, ensuring consistent behavior across different execution contexts.
Each sub-agent manages its own MCP connections and tools. They don’t automatically inherit parent tools.

System Context

All sub-agents receive consistent system context:
  • Date and time information
  • Autonomous agent behavior prompts
  • Model-specific system messages (e.g., “Claude Code” for Anthropic models)

Best Practices

Each sub-agent should have one clear purpose. This makes them reusable and easier to maintain.
Define clear expectations for what each sub-agent receives and returns.
Parent agents should handle sub-agent failures gracefully.
Use lighter models (like Haiku) for simple sub-agents to reduce costs and latency.
Test sub-agents independently before composing them.

Example: Customer Support System

Performance Optimization

Model Selection

Model Override Inheritance

When you use --model, it overrides the model for both the parent and ALL sub-agents:
See CLI Commands - Model Override for complete details on model override behavior and sub-agent inheritance.

Step Limits

Control sub-agent execution limits:
Default step limit for sub-agents is 50 (compared to 1000 for main agents).

Debugging Sub-Agents

Enable Verbose Logging

Trace Execution

Test Sub-Agents Individually

Security Considerations

Sub-agents run with the same system permissions as the parent process. Each sub-agent:
  • Creates its own MCP connections with full permissions
  • Can access any tools defined in its configuration
  • Runs with the same file system and network access
  • Has access to environment variables

Best Practices for Security

  • Audit sub-agent configurations carefully
  • Use minimal necessary permissions in MCP server configs
  • Avoid loading sub-agents from untrusted sources
  • Review sub-agent instructions for potentially harmful commands
  • Use disallowedTools in MCP configs to restrict dangerous tools

Next Steps

Remote Agents

Learn about remote agent execution

Examples

See sub-agent examples