Overview
Multi-agent workflows enable complex task orchestration by creating teams of specialized agents that work together hierarchically. This system allows you to build sophisticated AI applications where different agents handle specific domains or functions, coordinated by an orchestrator agent. Agents can invoke sub-agents using a hierarchical agent system:- Orchestrator: Main agent that delegates tasks.
- Sub-agents: Specialized agents for specific functions.
- Delegation: Automatic task routing based on agent capabilities.
- Context Sharing: Shared memory and knowledge between agents.
Prerequisites
Before using sub-agents, you must:- Create Sub-agents First: Use the Agent CRUD endpoints (
POST /v2/agents) to create the specialized agents - Reference by key: Add the created agent keys to the
team_of_agentsarray in your orchestrator agent configuration - Include Required Tools: Add
retrieve_agentsandcall_sub_agenttools to your orchestrator’s configuration to enable sub-agent discovery and delegation - Define Roles: Specify each sub-agent’s role to help the orchestrator decide when to delegate.
Example
Creating Agents
We are creating two sub-agents that we will be later orchestrating through an agent run.Calling the Create Agent endpoint to create a Youth Agent
Calling the Create Agent endpoint to create a Formal Agent
To update an existing agent, issue a similar call using the PATCH method to an existing agent_key. e.g.
PATCH /v2/agents/youth-agent . To learn more, see Updating an Agent.Orchestrating Agents
- Orchestrator agents must use the
retrieve_agentstool to discover available sub-agents before delegating tasks. - Include instructions like: “Use
retrieve_agentsto see what specialized agents are available, then usecall_sub_agentto delegate appropriate tasks based on their capabilities.” - Both tools must be included in the orchestrator’s configuration.
Step 1: Create the Orchestrator Agent
Now that you have created the sub-agents, create the orchestrator agent using the CRUD endpoint. Reference the sub-agents through the team_of_agents field by their keys and roles. You can later update this orchestrator (and its sub-agents) using the PATCH endpoint.Calling the Create Agent endpoint to create an Orchestrator Agent
You can update the orchestrator agent and its sub-agents at any time using the PATCH endpoint (e.g.,
PATCH /v2/agents/tone-orchestrator). This allows you to refine instructions, add or remove sub-agents from the team_of_agents array, or modify settings while keeping the same agent key.Step 2: Run the Orchestrator Agent
Once the orchestrator agent is created, invoke it by referencing its key. The orchestrator will use the sub-agents defined in theteam_of_agents array during the creation step.
Calling the Invoke Agent endpoint with the Orchestrator Agent key