RC-401h · Module 2
Handoff Protocols and Shared Context Management
5 min read
An agent handoff is a context transfer. The sending agent has accumulated state — task history, intermediate results, decisions made, constraints surfaced — and the receiving agent needs a precise, validated subset of that state to continue the work. The handoff protocol defines what gets transferred, how it is formatted, what is validated on receipt, and what happens when the transfer fails.
Most teams design handoffs as an afterthought. The sending agent dumps its full context into a JSON blob, the receiving agent tries to parse it, and the coordination falls apart the first time a field is missing or a format expectation diverges. A production handoff protocol is a named, versioned schema — the same schema contract discipline from Module 1, applied to the inter-agent boundary.
// Handoff protocol: three-phase transfer with validation gate
// CLAWMANDER's OpenClaw framework specifies this as mandatory
// for all cross-agent task transfers.
export async function executeHandoff(
sender: AgentInstance,
recipient: AgentInstance,
task: TaskRecord,
artifacts: Artifact[]
): Promise<HandoffReceipt> {
// Phase 1: Sender prepares the handoff payload
// The sender's prompt system produces a structured payload
// via its registered handoff prompt variant
const rawPayload = await sender.invokePrompt('handoff', {
task,
artifacts,
recipient_role: recipient.role,
context_budget: HANDOFF_CONTEXT_BUDGET,
});
// Phase 2: Validate against the registered schema contract
// Validation failure triggers incident logging and fallback routing
const payload = validateHandoff(rawPayload);
// Phase 3: Recipient acknowledges receipt with a confirmation schema
// If acknowledgment fails, the handoff is retried or escalated to lead
const receipt = await recipient.acknowledgeHandoff(payload);
// Log the full handoff event for prompt telemetry
await logHandoffEvent({
sender: sender.agentId,
recipient: recipient.agentId,
task_id: task.id,
sender_prompt_version: sender.promptVersion('handoff'),
recipient_prompt_version: recipient.promptVersion('handoff'),
payload_schema_version: HANDOFF_SCHEMA_VERSION,
validation_result: 'pass',
timestamp: new Date().toISOString(),
});
return receipt;
}
Shared context management is the harder problem. In a multi-agent system, multiple agents may need access to the same context — a customer profile, a document under review, a running task log. If each agent maintains its own copy of shared context, you get synchronization failures: AGENT-A updates the customer record while AGENT-B is mid-task using a stale version. The solution is a shared context store with versioned reads.
The shared context store is not an agent — it is infrastructure. Agents read from it using a snapshot model: they request a context snapshot at the start of a task, and that snapshot is what they work with for the duration. Updates are committed back to the store when the task completes, with a conflict check against any concurrent modifications. This is optimistic concurrency for agent context — the same pattern relational databases use for long-running transactions.