Sub-Agents & Hierarchy
Sub-agents allow parent agents to delegate tasks to specialized child agents, enabling complex multi-agent orchestration patterns.
Creating Agents with Sub-Agents
// Create specialized sub-agents
mathAgent = aiAgent(
name : "MathAgent",
description : "A mathematics expert",
instructions: "You help with mathematical calculations and concepts"
)
codeAgent = aiAgent(
name : "CodeAgent",
description : "A programming expert",
instructions: "You help with code review, writing, and debugging"
)
// Create parent agent with sub-agents
mainAgent = aiAgent(
name : "OrchestratorAgent",
description : "Main coordinator that delegates to specialists",
instructions: """
Analyze each request and delegate to appropriate sub-agents:
- MathAgent: For mathematical tasks
- CodeAgent: For programming tasks
Answer directly for simple queries that don't require specialists.
""",
subAgents : [ mathAgent, codeAgent ]
)
// The parent agent automatically has delegation tools available
response = mainAgent.run( "Write a function to calculate factorial" )
// → OrchestratorAgent decides to delegate to CodeAgentFluent Sub-Agent API
Sub-Agent Management
Sub-Agent Config Introspection
How Delegation Works
Three-Level Hierarchy Example
Sub-Agents vs. Tools
Sub-Agents
Tools
Sub-Agents with Memory
Related Pages
Last updated