Structured Handoff for AI Agents
Agents hand off work as typed blocks that any orchestrator parses deterministically — with revisions, fix cycles and a validated state machine.
Why H2C Exists
Ambiguous Handoffs
Agents pass state as prose and the next agent guesses. H2C makes every handoff a typed, validated block.
No Structured Protocol
AI agents communicate in unstructured text. H2C provides typed, parseable blocks.
Context Collapse
Long chains accumulate stale context with no signal of what to drop. H2C's PRUNE, COMPACT and FREEZE blocks make that explicit.
Silent Failures
Malformed or out-of-order messages fail silently or get guessed at. H2C's reference validator and state machine reject invalid blocks and transitions with explicit diagnostics.
No Versioned Handoff
Agents can't resume conversations. H2C includes cycle tracking and versioning.
Agent Orchestration
Building multi-agent systems requires custom protocols. H2C is a standard wire format.
Core Features
Structured Grammar
Formal BNF grammar with typed fields, lists, and revisions. Self-describing blocks that LLMs parse natively.
Deterministic Parsing
One grammar, one parser, explicit diagnostics. Round-trip lossless on the reference fixtures.
Universal Transport
Agnostic to transport: stdin/stdout, HTTP, WebSocket, MCP. Integrate with any framework.
Context Management
PRUNE, COMPACT, FREEZE commands mark what can be dropped from long agent chains.
Agent Orchestration
Built-in cycle tracking, retry counters, and versioned handoff. Versioning-aware agent choreography.
Validated State Machine
Every block and transition is checked by the reference validator and finite-state machine — invalid states surface as explicit diagnostics, not silent failures.
Measured, not estimated
| Scenario | Natural language | H2C | Delta |
|---|---|---|---|
| Hello World | 131 tokens | 204 tokens | +56% |
| Calculator | 300 tokens | 434 tokens | +45% |
| Clean Arch | 536 tokens | 922 tokens | +72% |
| RAG Pipe | 800 tokens | 1323 tokens | +65% |
Measured with tiktoken o200k_base. H2C costs more tokens because it carries explicit state. Reproduce: python3 conformance/benchmark.py fixtures
Use Cases
Multi-Agent Orchestration
Architect → Builder → Tester pipelines with retry tracking and versioned handoff.
Long-Running Chains
100+ message conversations with intelligent pruning, compaction, and freezing.
LLM-to-LLM Handoff
Structured output from Agent A → direct consumption by Agent B, no parsing overhead.
Cognitive IR
Structured handoff blocks for retrieval-augmented generation and reasoning transport.
Agent Runtime Protocol
Standard wire format for agent hosting platforms and orchestration frameworks.
Framework Integration
Drop-in layer for LangGraph, AutoGen, CrewAI, Semantic Kernel, and MCP.
Core Syntax
Minimal H2C Example
A structured block replaces a prose description with explicit, versioned fields.
This minimal example shows how H2C blocks replace verbose AI communication with clean, typed fields.
[ARCH:PLAN]
id:api-weather|fw:python3.11|lib:fastapi,httpx|auth:APIKey|struct:[main.py,services/weather.py]
[BUILD:EXEC]
id:m1|target:main.py|desc:setup_fastapi_app
[BUILD:DONE]
id:m1|diff:[main.py~1]|rev:1
[ORCH:END]
final:complete|est_token:15
Real-World Examples
🌤️ Weather API Service
Python FastAPI service with caching, rate limiting, and multi-step build orchestration.
📝 TODO Console App
C# .NET 8 application with SQLite, demonstrating H2C in stateful, long-running workflows.
🔄 PRUNE/COMPACT Chain
Complete v1.4 workflow with context management and a CTX:NEGOTIATE handshake.
🧪 Conformance Stress Test
130-message fixture that exercises PRUNE, COMPACT, and FREEZE through the reference parser, validator, and state machine.
H2C Code Examples
See how H2C blocks replace verbose natural language
[ARCH:PLAN]
id:weather-api
fw:python3.11
lib:[fastapi,httpx,cachetools]
auth:APIKey::env(OPENWEATHER_API_KEY)
struct:[main.py,routers/weather.py,services/weather_service.py]
notes:[cache_TTL_10min,rate-limit_60req-min]
Architecture plan with framework, libraries, auth, and structure
[BUILD:EXEC]
id:m1
target:main.py
desc:setup_fastapi_app
[BUILD:DONE]
id:m1
diff:[main.py~1]
rev:1
Build execution and completion with revision tracking
[TEST:RUN]
id:test_weather_endpoint
cmd:pytest tests/test_weather.py
[TEST:PASS]
id:test_weather_endpoint
pass_count:42
Test execution with results and pass count
[CTX:UPDATE]
~progress:layer=data,status=in_progress
~next:database_setup
~active_files:[main.py~1,models.py~1]
Context update with layer tracking and active files
[CTX:PRUNE]
keep:[m3,m4,t1]|pruned:[m1,m2]|reason:builds_completed
[CTX:COMPACT]
summary:[layer=api,status=done,files:[auth.py~1,routes.py~1]]
keep_active:[auth.py~1,routes.py~1]
pruned_history:msg_2_to_19
Context pruning and compaction for long-running chains
[ORCH:END]
final:complete
est_token:15420
pass_count:42
fail_count:2
Orchestration completion with token estimate and counters
Natural Language vs H2C
❌ Natural Language
I've set up a new FastAPI weather service
using Python 3.11. The service includes
multiple endpoints for weather data fetching
with caching (10 minute TTL) and rate limiting
at 60 requests per minute. I've structured
the code with separate routers and service
layers. Authentication is handled via API key
stored in environment variables...
✅ H2C
[ARCH:PLAN]
id:weather-api|fw:python3.11
lib:[fastapi,httpx,cachetools]
auth:APIKey::env(OPENWEATHER_API_KEY)
struct:[main.py,routers/,services/]
notes:[cache_TTL_10min,rate-limit_60req-min]
Result: explicit, typed fields instead of prose — parsed deterministically, not interpreted
Project Roadmap
v1.0 - Core Grammar
Foundational blocks, base syntax
Releasedv1.1 - Context Management
PRUNE/COMPACT, revisions, counters
Releasedv1.2 - State Machine
FREEZE, cycle tracking, retry logic
Releasedv1.3 - Formal Specification
EBNF ISO 14977, AST model, opcodes
Releasedv1.4 - Handshake & Error Recovery
CTX:NEGOTIATE handshake, BUILD:NACK, DAG transitive closure, formal STATE:FINDINGS
Releasedv2.0 - Reference Implementation
Parser, validator, transpiler
Plannedv3.0 - Runtime & Compiler
Native MCP transport, agent runtime
ResearchEcosystem Integration
H2C works as the structured handoff layer for your favorite frameworks
MCP
Transport H2C blocks via MCP tool calls
LangGraph
H2C as node output format and state schema
AutoGen
H2C as agent response protocol
Semantic Kernel
H2C for function result serialization
CrewAI
H2C as task output format
OpenAI Agents SDK
H2C as structured output format
Frequently Asked Questions
No. H2C is a structured handoff protocol for AI-to-AI communication, completely unrelated to the HTTP/2 cleartext upgrade mechanism defined in RFC 7540. The name stands for "Human-to-Compiler" / "Head-to-Core" — a structured format for AI agent handoff, not a network protocol. If you're looking for HTTP/2 h2c, see RFC 7540.
No, and we measured it. With tiktoken (o200k_base), H2C chains use more tokens than an equivalent natural-language brief on our reference scenarios, because they carry explicit state: ids, revisions, cycle ids. H2C's value is deterministic parsing and versioned handoff, not size. Reproduce with python3 conformance/benchmark.py fixtures.
H2C is plain text with a small grammar, so any model can read and write it; the reference parser and validator make every handoff checkable regardless of which model produced it. We have not published a cross-model benchmark yet.
No. H2C is a plain-text protocol with a formal BNF grammar. You can use it immediately with any LLM — no libraries, no SDK, no runtime. Simply include the H2C grammar in your system prompt, and both you and the AI can start exchanging H2C blocks right away. A reference parser, validator, and transpiler are planned for v2.0.
H2C is purpose-built for AI-to-AI communication, unlike JSON or YAML which are general-purpose serialization formats. Key differences: (1) H2C blocks include built-in semantics for versioning (rev:), cycle tracking (cycle:), and context management (PRUNE, COMPACT, FREEZE) that JSON/YAML lack; (2) LLMs produce valid H2C more reliably because the grammar is optimized for token prediction, not human readability; (3) H2C is designed to be self-describing and self-documenting, reducing the parsing overhead that makes JSON verbose.
Ready to Structure Your Agent Handoffs?
H2C is open-source (MIT), requires zero dependencies, and works with any LLM with an 8K+ context window.
MIT License • Copyright © 2026 Paolino Salamone