Skip to main content
Back to how-to guides Use this pattern when the calling agent keeps the conversation and needs a result from another agent. Choose DELEGATE for a hidden, one-shot sub-task.

Concept

A DELEGATE 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.
Choose 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 the delegate_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

  1. The customer gives the applicant ID. The WHEN expression becomes true.
  2. The runtime starts Credit_Check_Agent in its own session scope. INPUT supplies applicant_id.
  3. The child runs its flow, calls the tool, and sets credit_band. The child output stays hidden.
  4. RETURNS copies credit_band from the child into the parent variable credit_band.
  5. USE_RESULT: credit_result stores the full result under credit_result. If you omit USE_RESULT, the platform uses delegate_result. Text with spaces is not stored anywhere.
  6. The parent COMPLETE rule fires and the parent answers.
If the child returns no mapped value, the delegate fails. 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 single DELEGATE 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

  1. Give the applicant ID. Expect a delegate_start event for Credit_Check_Agent, then a delegate_complete event with success: true.
  2. Expect the customer to see one answer from Loan_Application_Agent. The child output does not reach the customer.
  3. Check the parent session values. Expect credit_band and credit_result to hold values.
  4. Make the lookup tool fail. Expect delegate_complete with success: false and the ON_FAILURE message.
  5. Expect no handoff event for the delegate. The active agent does not change.
  6. For the transfer example, expect a handoff to Payment_Agent after screening_clear becomes true.

Production readiness checklist

  • The child declares every field that RETURNS names. The compiler warns with UNKNOWN_DELEGATE_RETURN_FIELD otherwise.
  • The child has no required GATHER field that INPUT leaves unmapped.
  • The lookup tool has an execution binding, a timeout, and no side effects.
  • Each delegate sets TIMEOUT and ON_FAILURE on purpose.
  • The caller covers the failure path. A continue failure leaves the result variable empty.
  • Tests cover success, tool failure, timeout, and a missing input value.
  • Trace checks confirm delegate_complete events with success: true.

Common mistakes

Troubleshooting