Concept
A child agent runs in its own scope. When it finishes, nothing comes back unless you map it. The mapping names each child field and the parent variable that receives it. Two constructs return values. They use the samechild_field: parent_variable shape.
Choose by who talks to the customer. A child that asks the customer questions is a returnable
HANDOFF. A hidden call that returns a result is a DELEGATE. See When to use HANDOFF instead of DELEGATE.
Only mapped fields come back. A child field that you do not map stays in the child.
Minimal working example
A refill agent needs a delivery postcode before it can confirm the request. A delivery agent talks to the customer and collects it.MAP copies the postcode to the parent. SET records that delivery is confirmed.
The delivery agent is a short stand-in in the same project. Replace it with your real agent.
agents/refill-request-agent.agent.abl
agents/delivery-agent.agent.abl
delivery_postcodein the child is aGATHERfield.MAPcopies it to the parent variable of the same name.delivery_confirmedis set by theSETline afterMAPruns.
How it works
- The parent routes to the child.
RETURN: truemakes the parent wait. - The child talks to the customer and gathers its field.
- The child’s
COMPLETErule fires. The child returns control. - The runtime applies
MAP: it reads each child field and writes it to the parent variable. A child field with no value is skipped. - The runtime applies
SETassignments. - The
actiondecides what the parent does next.continueresumes the parent without routing again.resume_intentreplays the customer’s request through the parent routes.
MAP:
- Write
child_field: parent_variable. The child field is on the left. - The child must declare or produce the child field. Otherwise the compiler reports
UNKNOWN_HANDOFF_RETURN_FIELDas an error. The check runs for local children withRETURN: true. - The parent must be allowed to write each target. If one target is not writable, the runtime applies none of the return effects. See Transfer control to another agent and return later.
ON_RETURNwithoutRETURN: trueis unreachable. The compiler warns withHANDOFF_ON_RETURN_WITHOUT_RETURN.
RETURNS on a delegate:
- Write
child_field: parent_variable. The runtime looks for the child field in the result, then in the JSON response, then in the delegate’s session values, then in its state context. - A field that has no value is skipped.
- If
RETURNSis declared and no field maps, the delegate fails and theON_FAILUREpath runs. - An empty string never overwrites a parent variable that holds a value. Return
nullto clear one on purpose. - The compiler warns with
UNKNOWN_DELEGATE_RETURN_FIELDwhen the child does not declare the field. - The full result also lands in the variable that
USE_RESULTnames. The default isdelegate_result.
Common variations
Map a delegate result
A delegate returns two values to the caller.MEMORY fields and the Refund_Checker agent from Delegate and map the result.
Map several fields and replay the request
Add moreMAP lines and use resume_intent when the parent must route again with the new values.
delivery_window must be a child field and preferred_window a parent variable.
Reuse return behavior with a handler
Define a named handler inRETURN_HANDLERS when several routes share the same return behavior. A handler cannot combine RESPOND with RESUME_INTENT. See Transfer control to another agent and return later.
Remote children
A remote child can also return values. The remote agent sends an A2Adata part with a returnValues object, and MAP reads its keys. The compiler does not check MAP fields for a remote target, so a wrong key is skipped without an error. See Preserve context when calling remote agents.
Verification
- Run the validator on both files. Expect no errors and no warnings.
- Send “Refill my prescription.”
- Expect a
handofftrace event toDelivery_AgentwithreturnExpected: true. - Answer the postcode. Expect the child to complete.
- Expect a
handoff_return_handlertrace event.mappedFieldsmust listdelivery_postcode. - Expect the parent reply “Your refill ships to” followed by your postcode.
- Change the
MAPchild field to a name the child does not declare. ExpectUNKNOWN_HANDOFF_RETURN_FIELD. Revert the change.
Production readiness checklist
- Every
MAPandRETURNSentry names a child field that the child sets on every successful path. - Every parent variable is declared in
MEMORY, and the parent reads it. - The parent can write every
MAPandSETtarget. - A failure path exists for the child. See Transfer control to another agent and return later.
- Tests cover a child that returns every field, a child that returns some fields, and a child that never completes.
- Trace checks confirm
mappedFieldson every return.
Common mistakes
Troubleshooting
Related articles: