What Are Sub-Agents?
A sub-agent is a temporary agent with:- Read-only access - Can search, read files, and list directories
- Weak model - Uses the fast, cheap model from your config
- Scoped search - Operates within a specified directory scope
- Isolated execution - Runs in its own process, doesn’t affect main session
- Time-bounded - Maximum 10 iterations before automatic termination
When to Use Sub-Agents
Sub-agents are ideal for exploratory tasks:Finding Usage Patterns
Finding Usage Patterns
“Where is the User schema used in the codebase?”A sub-agent searches for references and summarizes usage patterns.
Understanding Conventions
Understanding Conventions
“How are controllers typically structured in this project?”A sub-agent examines multiple controller files and extracts common patterns.
Locating Implementation Details
Locating Implementation Details
“How does authentication work in this app?”A sub-agent traces through auth-related modules to build a summary.
Dependency Analysis
Dependency Analysis
“What modules depend on the Accounts context?”A sub-agent searches for imports and function calls.
How to Use Sub-Agents
Automatic Invocation
The main agent can automatically spawn sub-agents when it recognizes an exploratory task:Explicit Invocation
You can explicitly request a sub-agent search:Programmatic Usage
Call the sub-agent tool directly:Sub-Agent Workflow
When a sub-agent is spawned:Available Tools
Sub-agents have access to four read-only tools:file_read
Read file contents:file_search
Find files matching a glob pattern:content_search
Search file contents with regex:directory_list
List directory contents:Scoping Sub-Agents
By default, sub-agents search the entire project. Use thescope parameter to restrict the search space:
- Full Project
- Specific Directory
- Subsystem
Configuration
Weak Model Selection
Sub-agents use the “weak” model from your config:.loom.toml
- Claude Haiku 4-5 - Fastest Anthropic model, excellent for search
- GPT-3.5 Turbo - Fast, cheap, good reading comprehension
- Groq LLaMA 3 8B - Free tier, very fast inference
Iteration Limit
Sub-agents are limited to 10 tool call iterations to prevent runaway searches:Example: Finding a Feature
User Request
Main Agent Response
Sub-Agent Execution
Search for Files
lib/myapp/notifications.exlib/myapp/notifications/email.exlib/myapp_web/live/notifications_live.ex
Final Output
Performance Considerations
Cost
Sub-agents use the weak model, so they’re cheap:- Claude Haiku: ~$0.25 per million input tokens
- GPT-3.5 Turbo: ~$0.50 per million input tokens
Speed
Sub-agents run in parallel with the main agent (technically sequential in current implementation, but async support planned):- Single search: 2-5 seconds
- Complex multi-step search: 10-15 seconds
Memory
Each sub-agent runs in its own process and is garbage collected after completion. Minimal memory overhead.Implementation Details
Sub-agents are implemented inlib/loom/tools/sub_agent.ex:
lib/loom/tools/sub_agent.ex:1 for the full implementation.
Limitations
No State Persistence
Sub-agents don’t save their findings to the decision graph or conversation history. They return a summary and terminate.Sequential Execution
Currently, sub-agents run sequentially. Parallel sub-agent execution (true agent swarms) is planned for Phase 5.Read-Only
Sub-agents can’t make changes. If they discover an issue, the main agent must handle the fix.Fixed Tool Set
Sub-agents can’t use custom tools or MCP servers (coming in Phase 4).Best Practices
Use for Broad Searches
Sub-agents excel at answering “where” and “how” questions:Scope Appropriately
Narrow scopes are faster and more focused:Trust the Summary
Sub-agents synthesize findings into concise summaries. Don’t re-search manually—trust the summary and ask follow-up questions if needed.Combine with Main Agent
Use sub-agents for discovery, then switch to the main agent for action:Future Enhancements
Parallel Sub-Agents
Spawn multiple sub-agents simultaneously for faster exploration:Persistent Sub-Agents
Keep sub-agents alive across multiple queries for conversational exploration.Custom Tool Sets
Allow sub-agents to use MCP tools or custom tool modules.Sub-Agent Swarms
Coordinate multiple sub-agents via OTP message passing for complex investigations.Troubleshooting
Sub-Agent Returns Empty Results
Cause: The search scope was too narrow or the pattern didn’t match. Solution:- Widen the scope:
scope: "lib"instead ofscope: "lib/myapp/accounts" - Try different search terms
- Ask the main agent to refine the query
Sub-Agent Exceeds Iteration Limit
Issue: Error:Sub-agent exceeded maximum iterations (10)
Cause: The task was too complex or the model got stuck in a loop.
Solution:
- Break the task into smaller pieces
- Narrow the scope
- Try a stronger weak model (Haiku → Sonnet)
Sub-Agent Slow to Respond
Cause: Large codebase, complex regex patterns, or slow model. Solution:- Narrow the scope:
scope: "lib/myapp"instead of entire project - Use a faster weak model (Groq, GPT-3.5)
- Simplify the search task
Next Steps
Architect Mode
Use two-model workflows for complex changes
Project Rules
Define project-specific instructions and constraints