Sub-Agents & Hierarchy
Sub-agents allow parent agents to delegate tasks to specialized child agents, enabling complex multi-agent orchestration patterns.
Sub-agents allow you to create specialized agents that a parent agent can delegate to. When you register a sub-agent, it is automatically wrapped as an internal tool that the parent can invoke by calling delegate_to_{agent_name}.
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
When a sub-agent is added, it is wrapped as a tool automatically:
Tool name:
delegate_to_{agent_name}(lowercase, special characters replaced with underscores)Tool description: Built from the sub-agent's
nameanddescriptionTool parameter: A single
taskparameter for the query to delegate
The parent agent's AI model decides when to use the delegation tool based on task context.
Three-Level Hierarchy Example
Sub-Agents vs. Tools
Best for
Delegating reasoning tasks to another AI
Calling external systems/APIs
Invokes
Another AI model
A function/lambda
Context
Child agent has its own memory/instructions
Single function call
Use when
Task requires dedicated expertise or instructions
Task requires data/computation
Sub-Agents with Memory
Each sub-agent maintains its own memory independently:
Related Pages
Getting Started — Creating basic agents
Tools & MCP — Tools vs. sub-agents
Advanced Patterns — Pipeline-based agent chaining
Last updated