Parallel Market Analysis with Sub-Agents
This example demonstrates how a single coordinator agent can dynamically create specialized sub-agents and delegate parallel research tasks — perfect for complex analyses that benefit from domain-specific expertise.What This Example Shows
- Enabling sub-agent delegation with
max_loops="auto" - How the coordinator autonomously creates and assigns work to sub-agents
- Parallel execution across multiple research domains
- Result aggregation into a unified report
How Sub-Agents Work
Unlike agent handoffs where specialist agents are pre-defined in your request, sub-agents are created dynamically at runtime by the coordinator. The coordinator decides how many agents to create and what each one specializes in.Step 1: Setup
Step 2: Configure the Coordinator Agent
The coordinator agent needsmax_loops="auto" to enable autonomous tool use, including create_sub_agent and assign_task:
Step 3: Run the Analysis
- Create sub-agents — e.g., “Financial-Analyst”, “Competition-Researcher”, “Industry-Trends-Analyst”, “Risk-Assessor”
- Assign tasks — Each sub-agent receives a focused research task
- Execute in parallel — Sub-agents run concurrently
- Compile results — The coordinator synthesizes all findings into a unified report
Sub-agent workflows take longer than single-agent calls since multiple agents are created and run. Use a timeout of 300 seconds or more for complex delegation tasks.
Next Steps
- Sub-Agent Delegation Reference — Full documentation on sub-agent tools and parameters
- Autonomous Agent Tutorial — Learn the autonomous mode that powers sub-agents
- HierarchicalSwarm — Pre-defined multi-agent hierarchy for known team structures