Agent handoff protocol
The handoff is where multi-agent teams leak. The sender knows why a constraint
matters; the receiver gets a wall of transcript and guesses. It inherits too
little and re-derives a decision wrong, or too much and burns its context window
on noise. A handoff protocol is the edge in the team graph: a typed envelope, a
size ceiling, and a rule for what has to survive the crossing.
Method
- Define the artifact contract. The envelope is structured, not prose:
task, inputs, constraints, done_criteria, provenance. Pick a format
the receiver can parse, JSON or fenced fields in markdown, and reject
anything that fails the schema on arrival.
- Set a context budget. Cap the payload in tokens, often one to two
thousand. The sender summarizes decisions and their reasons; it does not
forward the chat log. A payload over the cap is a signal to split the task,
not to raise the ceiling.
- Carry decisions, not narration. The envelope states what was decided and
the constraint behind it: "auth reuses the session cookie, add no token
store." The receiver should never need the sender's reasoning turns to act
correctly.
- Validate on receipt and fail closed. The receiver checks that required
fields are present and specific before it starts. A missing
done_criteria
or a vague constraint bounces back as a defect. A receiver that guesses at a
thin envelope is how a whole pipeline goes wrong in silence.
- Stamp provenance and keep it replayable. Record which agent produced the
envelope, from which inputs, at which version. A handoff you can replay from
its inputs is one you can debug when the output surprises you.
- Acknowledge or reject out loud. The receiver returns an ack that the
contract is met, or a rejection naming the missing field. Silence is not
acceptance: an unacknowledged handoff is an open failure.
Run it
In Claude Code, write each handoff to a file the next subagent reads first
rather than piping a full transcript into its prompt. The orchestrator enforces
the budget by distilling sender output into the envelope before spawning the
receiver, and refuses to spawn on a malformed one. Treat a handoff as complete
only on an explicit ack; on rejection, route back to the sender with the named
defect. To port, the envelope is a CrewAI task output_pydantic model, an
AutoGen structured message, or a typed edge payload in a LangGraph State that
the next node reads and the graph validates.
Signals it works
- The receiver never asks for context the envelope should have carried.
- No handoff exceeds its token budget without triggering a task split.
- Every crossing ends in an explicit ack or a named defect, never in silence.
Boundaries
This governs one edge between two agents; the nodes it connects are defined by
agent-role-definition. It assumes the roles already do not overlap: a clean
contract cannot rescue two agents fighting over one deliverable. Match envelope
strictness to blast radius, a throwaway draft needs less ceremony than a handoff
into a production deploy.
1---2name: agent-handoff-protocol3description: Design each handoff between two agents as an explicit artifact contract with a context budget and a rule for what must survive the crossing. Use when work passes from one agent to the next and the receiver keeps losing constraints, re-deriving decisions, or drowning in raw transcript.4---56# Agent handoff protocol78The handoff is where multi-agent teams leak. The sender knows why a constraint9matters; the receiver gets a wall of transcript and guesses. It inherits too10little and re-derives a decision wrong, or too much and burns its context window11on noise. A handoff protocol is the edge in the team graph: a typed envelope, a12size ceiling, and a rule for what has to survive the crossing.1314## Method15161. **Define the artifact contract.** The envelope is structured, not prose:17 `task`, `inputs`, `constraints`, `done_criteria`, `provenance`. Pick a format18 the receiver can parse, JSON or fenced fields in markdown, and reject19 anything that fails the schema on arrival.202. **Set a context budget.** Cap the payload in tokens, often one to two21 thousand. The sender summarizes decisions and their reasons; it does not22 forward the chat log. A payload over the cap is a signal to split the task,23 not to raise the ceiling.243. **Carry decisions, not narration.** The envelope states what was decided and25 the constraint behind it: "auth reuses the session cookie, add no token26 store." The receiver should never need the sender's reasoning turns to act27 correctly.284. **Validate on receipt and fail closed.** The receiver checks that required29 fields are present and specific before it starts. A missing `done_criteria`30 or a vague constraint bounces back as a defect. A receiver that guesses at a31 thin envelope is how a whole pipeline goes wrong in silence.325. **Stamp provenance and keep it replayable.** Record which agent produced the33 envelope, from which inputs, at which version. A handoff you can replay from34 its inputs is one you can debug when the output surprises you.356. **Acknowledge or reject out loud.** The receiver returns an ack that the36 contract is met, or a rejection naming the missing field. Silence is not37 acceptance: an unacknowledged handoff is an open failure.3839## Run it4041In Claude Code, write each handoff to a file the next subagent reads first42rather than piping a full transcript into its prompt. The orchestrator enforces43the budget by distilling sender output into the envelope before spawning the44receiver, and refuses to spawn on a malformed one. Treat a handoff as complete45only on an explicit ack; on rejection, route back to the sender with the named46defect. To port, the envelope is a CrewAI task `output_pydantic` model, an47AutoGen structured message, or a typed edge payload in a LangGraph `State` that48the next node reads and the graph validates.4950## Signals it works5152- The receiver never asks for context the envelope should have carried.53- No handoff exceeds its token budget without triggering a task split.54- Every crossing ends in an explicit ack or a named defect, never in silence.5556## Boundaries5758This governs one edge between two agents; the nodes it connects are defined by59`agent-role-definition`. It assumes the roles already do not overlap: a clean60contract cannot rescue two agents fighting over one deliverable. Match envelope61strictness to blast radius, a throwaway draft needs less ceremony than a handoff62into a production deploy.