Skip to content

Subagent Handoffs

In One Turn, One Tool Call, a shell command returns its output under the original tool call ID. A subagent has a separate thread that can finish after the parent’s turn. This chapter follows how a child result reaches a later parent request.

Source snapshot. Codex CLI 0.172.0. The first trace inspects a scripted integration fixture for the multi_agent_v1 tool namespace. The v2 trace uses a separate fixture at the same revision. Tool namespaces and fixture inputs

Spawn call → child thread starts
├→ spawn result with child thread ID → parent can continue
└→ child reaches terminal status → notification enters parent history
Later user follow-up → parent model request includes the notification
  1. Start the child. The v1 spawn handler puts the delegated input, parent thread ID, and parent turn ID in a SpawnRequest. On success, the tool response contains the new child thread ID and an optional nickname. The parent can continue its own turn with that response. Spawn request · Spawn result
  2. Watch for completion. The spawn path starts a watcher that subscribes to the child thread’s status. It looks for a terminal status. A successful turn can carry the child’s last assistant message in its Completed status. Watcher registration · Status watcher · Status from turn completion
  3. Deliver the result to the parent. The watcher injects a SubagentNotification into the parent. Its payload contains a child reference and status, and the formatter tags it as multi_agent.subagent_notification. The injection path can enqueue the item for active work or record it in the conversation without starting a turn. The fixture below exercises delivery to the next user-initiated turn. Parent injection · Notification format · Injection and recording

The mock provider scripts the parent’s spawn call, the child’s child done response, and the rest of the parent’s first turn. The fixture waits for the notification marker to appear in the parent’s persisted rollout before submitting the follow-up. The model never calls a wait tool in this sequence. Fixture setup · Rollout check

The test checks that at least one captured provider request for the second turn contains a multi_agent.subagent_notification item. The assertion covers delivery to the model input. The mock assistant response is fixed, so evaluating how a model uses the result would require a separate experiment. Request assertion

Parent observes What you can infer
Spawn response with a child ID The child was started and has a reference. Spawn response
Completion notification in the rollout The result reached the parent’s persisted conversation in this fixture. Rollout check
Content kind in a provider request during the parent’s follow-up turn At least one model request in that turn carried the notification. Request check

Label these observations separately when diagnosing a handoff. A successful spawn response alone leaves the child’s result and its delivery unresolved.

The v2 fixture creates two children of the root thread, /root/requester and /root/worker. The requester calls collaboration.followup_task on the worker. Both followup_task and send_message use the same dispatch path. The former selects TriggerTurn and supplies the caller’s turn ID as parent_turn_id. The latter selects QueueOnly. Shared dispatch · Delivery modes · Scripted follow-up

Where to look What the fixture establishes
Worker’s provider request The matcher checks for the follow-up text in the request and for an agent_message item as separate conditions. The test identifies the request by the worker thread ID and extracts the worker turn ID. Request match · Turn ID
Requester’s completion event The harness emits a completed activity item to the initiating sibling. The test checks that the event identifies the requester’s thread and original turn, with an activity ID derived from the worker’s follow-up turn. Event routing · Event assertion
Root’s later provider request The result text is sent to the worker’s parent. After the root receives a new user prompt, the test checks a later request for an agent_message from /root/worker to /root containing peer follow-up finished. The fixture allows the first request in that turn to go out before queued mail is read. Result routing · Request assertion

This walkthrough follows the fixture’s live case. The test enables v2 explicitly and uses scripted model responses. In the live case, the worker assertion leaves the exact message payload and the worker request’s parent_turn_id unchecked. The reloaded_sleep case checks the parent turn ID on a separate wake request. Case-specific assertions The fixture index gives the command filter. Fixture setup

Can a worker start a new task on the root?

Section titled “Can a worker start a new task on the root?”

The two v2 tools treat /root differently. In the send_message handler test, the captured communication names the child as author and the root as recipient, with trigger_turn set to false. In the followup_task test, the same target produces an error and the root receives neither communication nor an interrupt. These assertions check which operations the handler submits. To check when the root sees queued content, inspect its later provider request in the peer fixture above. Queued message · Rejected follow-up

Does a structured handoff improve the parent’s use of delegated evidence? Give a child a versioned dataset to inspect. Supply the same finding to the parent as prose or as fields for dataset version, result, and evidence location. Keep the model and task fixed, then check whether the parent’s conclusion uses the correct version and cites the supporting evidence.

  1. What is available as soon as the spawn call returns?
  2. Why does the v1 fixture poll the rollout before it sends the second user message?
  3. In the v2 peer follow-up, which thread receives the completion event, and which thread later sees the result in a model request?

Answers. The spawn response gives the parent a child thread ID and possibly a nickname. Polling the rollout establishes that the notification has arrived before the follow-up tests whether the next request includes it. The v2 completion event belongs to the requesting sibling’s initiating turn. The worker’s result appears in a later request from its parent, the root thread.

Return to the course overview or design a handoff experiment in the Research Lab.