Skip to main content
Back to how-to guides Use this when a supervisor should stop answering and let a specialist own the next turn, or when a temporary gate must run first.

Concept

The active agent is the agent that answers the customer. Only HANDOFF changes it. Each route sets how long the change lasts. DELEGATE does not switch the active agent. It runs a sub-task and the calling agent stays active. A delegate child cannot wait for customer input, so a gate that asks the customer a question needs RETURN: true. A permanent specialist keeps the conversation until it completes, escalates, or hands off. Give it its own HANDOFF entries when it must switch again.

Minimal working example: a gate, then a permanent switch

The supervisor sends every request to Customer_Lookup_Agent until customer_id is set. The gate returns the ID and replays the original request. The supervisor then hands off for good. This example is a project-level set. Account_Service_Agent and Billing_Agent are short stand-ins for your real specialists.

How it works

  1. customer_id IS NOT SET is true until the ID exists. The runtime checks this condition before the model runs, so the first message goes to the gate.
  2. The gate is a child (RETURN: true). The supervisor waits and the child talks to the customer.
  3. When customer_id IS SET, the child completes and returns. MAP copies the child field on the left into the supervisor variable on the right.
  4. ON_RETURN with action: resume_intent replays the message that caused the handoff. The supervisor routes it again. The replay depth limit is one.
  5. customer_id IS SET is now true. The supervisor model picks the account or billing route. RETURN: false ends the supervisor thread, and the specialist answers from then on.
IS SET and IS NOT SET handle an empty variable. Do not compare an empty variable with != "". That comparison is true when the value is missing. A route without HISTORY passes the full conversation history. A project default can change this value.

Common variations

Gate on a verified flag

An authentication gate follows the same shape. Gate on a flag and map the flag back. Replace the first HANDOFF entry with this entry.
is_authenticated != true is true when the variable is empty or false. Declare is_authenticated as a boolean in MEMORY. Change the other two routes to read is_authenticated == true. Authentication_Agent must declare or set is_authenticated. Otherwise the compiler reports UNKNOWN_HANDOFF_RETURN_FIELD for the MAP line. Set the flag from a verification tool result. Never set it from what the customer says about themselves.

Choose which message the supervisor replays

ON_RETURN takes resume_with. Add it under action. The default is original_handoff_utterance, the message that started the handoff. The other values are latest_child_user_utterance, latest_session_user_utterance, and forwarded_return_message.

Temporary child that does not replay

Use action: continue when the supervisor should carry on without routing again. The child still returns its mapped fields.

Verification

  1. Start a new session and send “I want to change my address”. Expect Customer_Lookup_Agent to ask for the ID. The handoff event shows returnExpected: true and reasonCode: handoff_return_expected.
  2. Send an ID. Expect handoff_return_handler with mappedFields: ["customer_id"], then a resume_intent event.
  3. Expect a second handoff event to Account_Service_Agent with returnExpected: false and reasonCode: handoff_permanent.
  4. Send a billing request in a new session and give an ID. Expect Billing_Agent.
  5. Send another message. Expect the specialist to answer. The supervisor does not see it.

Production readiness checklist

  • Every TO target exists. Replace the stand-in specialists with real agents.
  • MAP names a child field that the child sets, and a supervisor variable that the routes read.
  • A route or a direct answer covers requests that match neither category.
  • Flags that gate access come from a tool result or an identity service.
  • Each route sets RETURN on purpose.
  • Each PASS list holds only what the target needs.
  • Tests cover a new session, a returning customer with the ID set, an unknown request, and a customer who leaves the gate unanswered.

Common mistakes

Troubleshooting