DELEGATE for a hidden, one-shot sub-task.
Concept
ADELEGATE is an internal call. The caller waits. The target runs in its own scope and receives only the INPUT fields. The target never speaks to the customer. The caller writes the final answer.
When the target finishes, RETURNS copies target fields into caller variables. The caller stays the active agent for the whole call.
Choose
DELEGATE when all of these are true:
- The caller keeps the conversation.
- The target needs no customer input beyond what the caller passes.
- The caller needs a value back, such as a score, a status, or a flag.
- The customer does not need to see the target.
HANDOFF when the target must talk to the customer. See When to use HANDOFF instead of DELEGATE.
Rules the platform enforces
How a delegate starts
On a normal turn, the model calls thedelegate_to_<Agent> tool. PURPOSE and WHEN describe the tool to the model.
An expression in WHEN is a hard guard. The runtime blocks the call when it is false. A quoted plain-language WHEN guides the model and does not block.
After a returned child, the runtime runs each authored delegate whose WHEN is true. Each entry runs once.
A delegate called from a flow step is out of scope here. See Call a sub-agent and map its result back.
Minimal working example
A loan agent collects the applicant ID. It delegates a credit lookup and tells the customer the band. The customer never sees the lookup agent. The lookup tool needs an execution binding in your project, such as an HTTP endpoint. That binding is a project-local assumption.agents/loan-application-agent.agent.abl
agents/credit-check-agent.agent.abl
How it works
- The customer gives the applicant ID. The
WHENexpression becomes true. - The runtime starts
Credit_Check_Agentin its own session scope.INPUTsuppliesapplicant_id. - The child runs its flow, calls the tool, and sets
credit_band. The child output stays hidden. RETURNScopiescredit_bandfrom the child into the parent variablecredit_band.USE_RESULT: credit_resultstores the full result undercredit_result. If you omitUSE_RESULT, the platform usesdelegate_result. Text with spaces is not stored anywhere.- The parent
COMPLETErule fires and the parent answers.
ON_FAILURE then decides what happens.
A
RETURNS target that reads as a type name, such as string or number, is treated as a result schema and not as a variable. Name caller variables in lowercase.
Common variations
Delegate a hidden check, then hand off on the result
Use this when a silent check decides who owns the next step. The orchestrator screens the beneficiary. A clear result goes to the payment agent. A match goes to the compliance agent. Both routes are permanent, so the specialists talk to the customer.agents/transfer-desk-agent.agent.abl
agents/sanctions-screening-agent.agent.abl
agents/payment-agent.agent.abl
agents/compliance-review-agent.agent.abl
Run several delegates at once
A singleDELEGATE entry runs one sub-agent to completion. When a customer sends several independent requests in one message, multi-intent fan-out can run several delegates at the same time. See Run multiple agents in parallel with multi-intent fan-out.
Withhold a delegate for some sessions
ENABLED_WHEN also applies to DELEGATE entries. It decides once per session whether the route exists.
Verification
- Give the applicant ID. Expect a
delegate_startevent forCredit_Check_Agent, then adelegate_completeevent withsuccess: true. - Expect the customer to see one answer from
Loan_Application_Agent. The child output does not reach the customer. - Check the parent session values. Expect
credit_bandandcredit_resultto hold values. - Make the lookup tool fail. Expect
delegate_completewithsuccess: falseand theON_FAILUREmessage. - Expect no
handoffevent for the delegate. The active agent does not change. - For the transfer example, expect a
handofftoPayment_Agentafterscreening_clearbecomes true.
Production readiness checklist
- The child declares every field that
RETURNSnames. The compiler warns withUNKNOWN_DELEGATE_RETURN_FIELDotherwise. - The child has no required
GATHERfield thatINPUTleaves unmapped. - The lookup tool has an execution binding, a timeout, and no side effects.
- Each delegate sets
TIMEOUTandON_FAILUREon purpose. - The caller covers the failure path. A
continuefailure leaves the result variable empty. - Tests cover success, tool failure, timeout, and a missing input value.
- Trace checks confirm
delegate_completeevents withsuccess: true.