Context Handoff: Passing State Between Agents Cleanly
Context handoff is the act of transferring ownership of the next subgoal from one agent to another with enough state to succeed - and no more.
Clean handoffs use a packet outbound and a return contract inbound, optionally backed by a shared task store for large artifacts.
Dirty handoffs paste entire transcripts, drop critical ids, or duplicate the same facts until context windows melt.
Define a versioned packet schema (subgoal, constraints, inputs, success/failure contracts, budget), validate it at the boundary, run the specialist, validate the return, then merge artifacts into shared task state by reference.
A structured bundle describing the subgoal, constraints, inputs, success criteria, and budget for the receiving agent.
Should the specialist see the original user message?
Only when wording fidelity matters. Prefer a redacted digest plus entity ids to reduce PII and distraction.
How large should a packet be?
Small enough to validate and log; large enough that the specialist does not need archaeology. Prefer refs for anything multi-kilobyte.
What is a return contract?
A structured outcome: status, summary, artifacts or refs, errors, optional next-agent hint.
How do I version schemas?
Include schema_version and keep readers tolerant of N and N-1 during deploys. Fail closed on unknown required fields.
Message passing or shared state?
Use both: messages for control and intent, shared store for bulky artifacts. Pure either extreme tends to hurt at scale.
How do handoffs interact with short-term memory?
Task state for the active run should live in the shared record or packets. Role-private memory is for durable style/domain notes, not split-brain task facts.
What if the specialist needs a tool result from a prior agent?
Store the tool result (or summary) under an artifact key and pass the key. Re-running the same tool blindly causes duplication and drift.
Can packets include tool allowlists?
Yes - optional tools_allowed makes privilege explicit per hop and helps audits.
How do I test handoffs?
Unit-test builders/validators; integration-test missing-field failures; eval live runs for silent omission rates.