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

Recursive Delegation

Sub-agents can declare and invoke their own subagents. Each relative path is resolved from the directory of the file that declares it, so a team can be organized into reusable folders without depending on the root agent’s location. Delegation is bounded. AgentUse rejects circular dependencies and allows two sub-agent levels by default. Set MAX_SUBAGENT_DEPTH to a positive integer when a workflow intentionally needs a different limit; declarations beyond the active limit are skipped with a warning.
Each sub-agent receives only its own configured tools and declared sub-agent tools. MCP connections remain isolated to the agent that configured them.

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

Ordinarily, every agent uses the model: declared in its own file. A parent’s configured model does not replace its children’s models. When you explicitly use --model, that run-wide override applies to the parent and every nested sub-agent:
Configured aliases keep their complete fallback order and cooldown at every depth. The resolved override is also stored with the session, so a suspended or restarted run resumes with the same policy even if the alias configuration has changed since the run began.
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 allowedTools in MCP configs to load only the tools an agent needs, or disallowedTools to block specific ones

Next Steps

Remote Agents

Learn about remote agent execution

Examples

See sub-agent examples