Skip to main content

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 needs max_loops="auto" to enable autonomous tool use, including create_sub_agent and assign_task:

Step 3: Run the Analysis

Expected Behavior: The coordinator will autonomously:
  1. Create sub-agents — e.g., “Financial-Analyst”, “Competition-Researcher”, “Industry-Trends-Analyst”, “Risk-Assessor”
  2. Assign tasks — Each sub-agent receives a focused research task
  3. Execute in parallel — Sub-agents run concurrently
  4. 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