Agent Handoffs: Shared State, Ownership, and Context Contracts
Design agent handoffs with versioned context packets, explicit ownership, stale-worker fencing, and evidence provenance across specialist workflows.
Abhishek Raj · · 8 min read
Prepared with AI research assistance. Sources are linked throughout; worked examples are illustrative unless stated otherwise. Editorial approach.
An agent handoff transfers responsibility for a task. Passing the latest conversation messages is only one part of that transfer. The receiving agent also needs a goal, current evidence, unresolved questions, an authority boundary, and an unambiguous rule for who may commit the next change.
Without those contracts, a specialist can repeat completed work, inherit an unsupported conclusion, or act while the previous worker is still running. This guide proposes an illustrative handoff design for a hypothetical order-resolution workflow. The envelope and ownership rules are engineering recommendations, not a tested framework implementation.
Distinguish delegation, routing, and ownership
A delegation asks another worker for a result while the caller retains responsibility. Routing selects the next handler. An ownership transfer changes which worker may advance authoritative task state. These can occur together, but they are different operations.
LangChain describes handoffs as state-driven changes in configuration or active agent. Its documentation supports both a single agent whose tools and prompt change and multiple agent subgraphs. It also warns that subgraph handoffs require deliberate message selection and valid tool-call/response pairing. That is a conversation protocol requirement, rather than a distributed ownership guarantee. LangChain handoffs documentation.
For example, an order specialist may delegate a read-only shipment investigation to a logistics worker while retaining authority over the customer response. A later transfer to a returns specialist might change both the conversational role and task ownership. Name these operations separately in the application interface so that a model cannot accidentally convert a consultation into permission to mutate an order.
Make the handoff envelope a versioned interface
A useful envelope answers what must be done, why the receiver is involved, what is already known, and what remains prohibited. Here is illustrative JSON, not an SDK contract:
{
"schema_version": 2,
"handoff_id": "handoff_104",
"task_id": "task_23",
"expected_revision": 18,
"from_role": "order_triage",
"to_role": "returns_review",
"goal": "Determine whether this order qualifies for replacement",
"evidence_refs": ["order_82@v7", "shipment_19@v4"],
"open_questions": ["Has the carrier confirmed loss?"],
"completed_steps": ["Verified requester access to order"],
"permitted_action_classes": ["read_order", "draft_replacement"],
"prohibited_actions": ["issue_refund", "submit_replacement"],
"deadline_ref": "deadline_23",
"authorization_context_ref": "authctx_87"
}
The service generates identities, authoritative revision numbers, and authorization references. Model-generated text may propose the goal or describe uncertainty, but it does not establish access rights. Validate the target role against a server-side allowlist and verify that the requested transition is legal for the current task stage.
Version the schema explicitly. Adding an optional explanatory field can be compatible; changing whether a permission is advisory or enforceable is a semantic change. Reject unsupported versions before starting the receiving agent, and preserve the original envelope for diagnosis rather than silently rewriting it into whatever the current parser expects.
Separate authoritative state from interpretations
Use at least three conceptual stores: authoritative business records, workflow execution state, and agent-produced interpretations. They can share infrastructure, but they should not share trust semantics.
| Information | Appropriate treatment | Example |
|---|---|---|
| Business fact | Read from its owning service with a version | Shipment status from carrier integration |
| Execution fact | Persist as a validated workflow event | Handoff accepted at revision 19 |
| Agent conclusion | Keep evidence links and uncertainty | Package appears likely to be lost |
| Instruction from retrieved text | Treat as untrusted content | A document requests bypassing approval |
A receiving agent should be able to distinguish an observed status from an inference. If an upstream summary says the customer is eligible, it must identify the policy version and evidence supporting eligibility. Otherwise, the receiver must recheck the relevant facts or preserve the conclusion as unverified.
The W3C PROV family provides a vocabulary for identifying things, attributing their production, and describing derivation and processing. Its overview is a non-normative roadmap, not a requirement that an agent platform adopt RDF. The useful principle here is that a conclusion should retain its production history. W3C PROV overview.
A compact evidence entry can therefore record a source identifier, source version, retrieval time, producing tool, and the specific claim supported. A hash helps detect changed content; it does not prove that the original content was correct or that the caller was entitled to read it.
Transfer ownership in the control plane
A handoff message can be delivered twice or arrive late. Do not let message receipt alone establish ownership. In this proposed design, a transactional state store records the active role, execution owner, revision, and ownership epoch for each task.
The sender requests a transfer against an expected revision. A successful conditional update creates the durable handoff record, increments the epoch, changes the owner or transfer state, and records work that must be dispatched. A dispatcher then sends the notification from durable storage. If notification delivery repeats, the receiver checks the handoff identifier and current epoch before accepting work.
This design needs an explicit policy for the transition interval. One option is a TRANSFERRING state in which neither agent may perform business mutations. Another is to activate the new owner atomically and allow only that owner to begin. The choice affects availability, but ambiguous dual authority should not be an accidental consequence of transport timing.
For the surrounding durability mechanics, see checkpointing and recovery in agent workflows.
Fence stale workers at the action boundary
An ownership lease helps recover from failed workers, but a paused worker can resume after its lease has expired. Kubernetes uses Lease objects for coordination, including component leader election and heartbeats. That demonstrates the coordination primitive; it does not mean a Lease object automatically protects an unrelated order service. Kubernetes Lease concepts.
AWS describes the same underlying difficulty: a process can pause between checking a lock and performing work, and failure conditions can leave multiple processes believing they are leaders. It recommends designing correctness around those cases rather than assuming the lease prevents them. AWS leader election discussion.
In the hypothetical workflow, every mutation request carries the task's ownership epoch. An action gateway validates that epoch against the authoritative control record immediately before accepting the operation, within a contract that prevents an ownership change from racing acceptance. Old epochs are rejected. Checking only when the agent starts leaves a gap.
Be precise about the boundary: an already accepted remote request may still complete after ownership changes. Fencing does not undo it. Record accepted actions durably and reconcile their status during transfer. Use a stable business-action identity across ownership changes to prevent a new worker from submitting the same replacement again. These are distinct protections; idempotency for agent actions covers duplicate-effect handling.
Walk through a delayed order handoff
Consider a fictional task at revision 18, owned by triage worker A with epoch 6. A requests transfer to returns review. The control service validates the transition, commits revision 19 and epoch 7, and creates handoff 104. Worker B receives the notification and accepts the current assignment.
A was paused immediately before an unauthorized attempt to submit a replacement. When it resumes, its epoch-6 request is rejected by the gateway. B receives evidence that a replacement was drafted, but no accepted submission exists. It checks the carrier record because the envelope still lists loss confirmation as unresolved.
Next, suppose a submission had already been accepted under epoch 6 before the transfer. B must reconcile that action identity before creating another submission. It cannot infer failure from A's disappearance. This distinction prevents a recovery procedure from becoming a duplicate-order procedure.
Finally, the customer adds a new delivery address. The workflow records a new revision. B's planned action references an older snapshot, so the gateway requires revalidation of the affected fields. A valid handoff does not freeze the underlying world.
Validate handoffs as sequences
Test adversarial event orderings, not just JSON shape. Deliver the same handoff twice. Deliver an old handoff after a newer transfer. Pause a sender between its last ownership check and an action request. Crash after committing the transfer but before publishing its notification. Change evidence access permissions before the receiver loads it.
Assert both state and effects: only the current assignment may advance the workflow, stale epochs cannot accept new mutations, repeated notifications do not create repeated ownership changes, and accepted actions remain discoverable after recovery. Also check that summaries retain unresolved questions and that evidence references cannot cross tenant boundaries.
Track transfer acceptance latency, rejected stale actions, unresolved transfers, repeated specialist bouncing, and tasks completed after transfer. A high transfer count alone is not evidence of effective collaboration. Limit repeated routing between the same roles and escalate when no new evidence or capability is introduced.
Frequently asked questions
Should every agent share the entire conversation?
Only when it is useful and permitted. Prefer a bounded task packet with source references, required conversational context, and explicit uncertainty. Retain complete history in appropriate storage without forcing every worker to consume it.
Does a handoff need a distributed lease?
A single-process workflow may only need a validated state transition. Leases become relevant when workers can fail independently and assignments must be reclaimed. Even then, downstream action checks and deduplication determine whether stale workers can cause harm.
Can a signed handoff establish that its conclusions are true?
No. A signature can establish integrity and origin under its key-management assumptions. It cannot prove that evidence was interpreted correctly, that a source remains current, or that the requested operation is authorized. Verify those properties independently.
Source reference list
Related reading
- Durable AI Agent Workflows: Checkpoints, Replay, and Recovery
Design durable AI agent workflows with checkpoints, recorded decisions, safe retries, and recovery paths that handle crashes without duplicating actions.
- Idempotency for AI Agent Actions: Preventing Duplicate Side Effects
Prevent duplicate AI agent actions with stable intent identities, immutable request fingerprints, durable ledgers, and recovery for uncertain outcomes.
- Multi-Agent Task Scheduling: Dependencies, Leases, and Fairness
Design multi-agent task scheduling with validated dependencies, renewable ownership, enforced fencing, bounded capacity, and measurable fairness across tenants.