Skip to content

Commit bd45e88

Browse files
authored
Merge pull request #23897 from dvdksn/cagent-handoffs
cagent: explain sub_agents vs handoffs
2 parents 56f8119 + 90ce519 commit bd45e88

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

content/manuals/ai/cagent/best-practices.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ agents:
102102
Each agent has clear responsibilities. The writer doesn't worry about line
103103
wrapping. The editor doesn't generate content. The reviewer just runs tools.
104104
105+
This example uses `sub_agents` where root delegates discrete tasks and gets
106+
results back. The root agent maintains control and coordinates all work. For
107+
different coordination patterns where agents should transfer control to each
108+
other, see the `handoffs` mechanism in the [configuration
109+
reference](./reference/config.md#task-delegation-versus-conversation-handoff).
110+
105111
**When to use teams:**
106112

107113
- Multiple distinct steps in your workflow

content/manuals/ai/cagent/reference/config.md

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,70 @@ metadata: # Optional - author, license, readme
6161

6262
### Task delegation versus conversation handoff
6363

64-
Use `sub_agents` to break work into tasks. The root agent assigns work to a
65-
sub-agent and gets results back while staying in control.
64+
Agents support two different delegation mechanisms. Choose based on whether you
65+
need task results or conversation control.
6666

67-
Use `handoffs` to transfer the entire conversation to a different agent. The new
68-
agent takes over completely.
67+
#### Sub_agents: Hierarchical task delegation
68+
69+
Use `sub_agents` for hierarchical task delegation. The parent agent assigns a
70+
specific task to a child agent using the `transfer_task` tool. The child
71+
executes in its own context and returns results. The parent maintains control
72+
and can delegate to multiple agents in sequence.
73+
74+
This works well for structured workflows where you need to combine results from
75+
specialists, or when tasks have clear boundaries. Each delegated task runs
76+
independently and reports back to the parent.
77+
78+
**Example:**
79+
80+
```yaml
81+
agents:
82+
root:
83+
sub_agents: [researcher, analyst]
84+
instruction: |
85+
Delegate research to researcher.
86+
Delegate analysis to analyst.
87+
Combine results and present findings.
88+
```
89+
90+
Root calls: `transfer_task(agent="researcher", task="Find pricing data")`. The
91+
researcher completes the task and returns results to root.
92+
93+
#### Handoffs: Conversation transfer
94+
95+
Use `handoffs` to transfer conversation control to a different agent. When an
96+
agent uses the `handoff` tool, the new agent takes over completely. The
97+
original agent steps back until someone hands back to it.
98+
99+
This works well when different agents should own different parts of an ongoing
100+
conversation, or when specialists need to collaborate as peers without a
101+
coordinator managing every step.
102+
103+
**Example:**
104+
105+
```yaml
106+
agents:
107+
generalist:
108+
handoffs: [database_expert, security_expert]
109+
instruction: |
110+
Help with general development questions.
111+
If the conversation moves to database optimization,
112+
hand off to database_expert.
113+
If security concerns arise, hand off to security_expert.
114+
115+
database_expert:
116+
handoffs: [generalist, security_expert]
117+
instruction: Handle database design and optimization.
118+
119+
security_expert:
120+
handoffs: [generalist, database_expert]
121+
instruction: Review code for security vulnerabilities.
122+
```
123+
124+
When the user asks about query performance, generalist executes:
125+
`handoff(agent="database_expert")`. The database expert now owns the
126+
conversation and can continue working with the user directly, or hand off to
127+
security_expert if the discussion shifts to SQL injection concerns.
69128

70129
### Commands
71130

0 commit comments

Comments
 (0)