Skip to main content

Overview

Handoff contracts validate the structured data passed from one agent session to another via handoff_context. They catch renamed fields, missing keys, wrong types, and broken parent-child links.

Setting up a handoff

Link two sessions by passing parent_trace_id and handoff_context:

assert_handoff_received

Verifies that a child session is linked to its expected parent.
Fails if the child’s parent_trace_id doesn’t match the parent’s trace_id, or if handoff_context is missing.

assert_handoff_matches

Type-checks the handoff_context against a declared schema.

What it checks

  • Every key in the schema must exist in the handoff data
  • Every value must match the declared type
  • Nested dicts, typed lists, and list-of-dicts are supported (see Nested Schemas)
  • bool and int are strictly separated — True is not a valid int

Failure message

assert_handoff_has_fields

Checks that specific field names exist in the handoff context (without type checking):
Use this for quick presence checks when you don’t need full type validation.

assert_no_extra_fields

Verifies that the handoff context contains only the allowed fields:
Catches PII or debug fields accidentally leaking through handoffs. Fails if the handoff contains any key not in the allowed list.

assert_context_preserved

Verifies that specific values survived a handoff unchanged:
Compares the source dict values against the child’s handoff_context for the listed fields. Fails if any value was mutated, truncated, or lost.

Full example