Concept
The active agent is the agent that answers the customer. OnlyHANDOFF 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 toCustomer_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
customer_id IS NOT SETis true until the ID exists. The runtime checks this condition before the model runs, so the first message goes to the gate.- The gate is a child (
RETURN: true). The supervisor waits and the child talks to the customer. - When
customer_id IS SET, the child completes and returns.MAPcopies the child field on the left into the supervisor variable on the right. ON_RETURNwithaction: resume_intentreplays the message that caused the handoff. The supervisor routes it again. The replay depth limit is one.customer_id IS SETis now true. The supervisor model picks the account or billing route.RETURN: falseends 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 firstHANDOFF 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
Useaction: continue when the supervisor should carry on without routing again. The child still returns its mapped fields.
Verification
- Start a new session and send “I want to change my address”. Expect
Customer_Lookup_Agentto ask for the ID. Thehandoffevent showsreturnExpected: trueandreasonCode: handoff_return_expected. - Send an ID. Expect
handoff_return_handlerwithmappedFields: ["customer_id"], then aresume_intentevent. - Expect a second
handoffevent toAccount_Service_AgentwithreturnExpected: falseandreasonCode: handoff_permanent. - Send a billing request in a new session and give an ID. Expect
Billing_Agent. - Send another message. Expect the specialist to answer. The supervisor does not see it.
Production readiness checklist
- Every
TOtarget exists. Replace the stand-in specialists with real agents. MAPnames 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
RETURNon purpose. - Each
PASSlist 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.