Designing a Five-Layer Wire Protocol for AI Agent Communication

    This article explores the design of a five-layer wire protocol built for AI agent communication, addressing structural redundancy in LLM responses, missing agent identity standards, externalized semantics, and unclear streaming boundaries. It breaks down the transport, framing, schema, identity, and session layers, then walks through key tradeoffs around schema caching, backward compatibility, security, and observability. Readers will find a phased adoption path, an evaluation baseline, and the open problems that still need input from protocol practitioners.

    1. Where It Started: The “Repeated Tax” in Token Bills

    After connecting a large language model to existing HTTP APIs, one pattern becomes obvious: a significant share of response tokens carry no new information. They simply restate the same structure over and over. Take a common paginated list endpoint. Every row repeats the same field names. The model already learned the field set on page one, but the transport layer has no concept of “I already know this.” The serializer sends it anyway, the tokenizer splits it anyway, and the caller pays for it anyway.

    In schema-heavy workloads such as product catalogs, financial transaction records, and content feeds, this repeated structure can account for 30% to 60% of response tokens. That range is strongly tied to the workload and should not be treated as a universal figure. A rigorous approach is to define a reproducible measurement first: field-name frequency, the share of tokens spent on structural description, and cross-page repetition rate. Then report results on a fixed dataset and fixed endpoints instead of throwing out a single number.

    That alone is not enough to justify rebuilding a protocol. What actually pushed us toward a general communication layer was a growing list of pain points.

    2. Reframing Four Underlying Problems

    1. Repeated transmission of structural information. Query projection can trim irrelevant fields, but field names still repeat on every record. Compression reduces bytes; it does not remove semantic redundancy.
    2. No standard place for agent identity. Existing authentication mechanisms are designed for humans or human-like services. They cannot express at the protocol layer which agent initiated a call, who it represents, what scope it was granted, whether it has been revoked, and how long it is valid or what delegation chain applies.
    3. Semantics are fully externalized. APIs provide structure but not meaning. Field definitions, enum values, time formats, units, and null-value conventions all have to be explained on the fly through prompts at inference time. That is expensive and unreliable.
    4. Blurred semantic boundaries for streaming and tool calls. Incremental chunks, end markers, mid-stream errors, parallel tool calls, and cancellation semantics lack a unified representation. Clients fall back on ad hoc parsing conventions.

    3. The Five Layers: Keeping Each Concern in Its Own Cage

    For discussion, a wire protocol for agents can be abstracted into five layers, from bottom to top:

    • Transport and connection layer: Reuses mature reliable transport and encryption capabilities. Handles connection reuse, congestion control, and reconnect recovery. Carries no business semantics.
    • Framing and encoding layer: Defines frame types, length prefixes, compression, and chunking rules. Supports structured data and binary payloads side by side.
    • Semantics and schema layer: Exchanges field dictionaries, enums, units, and constraints through “negotiate once, reuse for a long time.” Subsequent data rows carry only values and reference identifiers.
    • Identity and authorization layer: Carries verifiable caller identity, delegation chain, scope declarations, and revocation status in frame headers or a dedicated handshake frame. Authorization decisions happen at the protocol layer rather than inside a gateway’s private logic.
    • Session and flow control layer: Manages multiplexing of requests and responses, ordering of incremental chunks, cancellation and timeouts, backpressure, and priority.

    The value of this layering is controlled replacement cost. Swap the encoding layer and the semantics layer stays intact. Swap the identity layer and the session layer stays intact.

    4. Key Design Tradeoffs

    • Schema negotiation caching and invalidation. Use a schema version number plus a digest as the cache key. The server sends an invalidation signal when the version changes. Clients must implement a “miss means fall back to full payload” path.
    • Compatibility and evolution. Once a wire protocol is released, it is hard to take back. Keep unknown-field passthrough, capability negotiation, and default-value semantics for backward compatibility.
    • Security and privacy. Identity frames need replay and forgery protection. Semantic dictionaries may expose internal enums and should be trimmed following a minimal-disclosure principle.
    • Observability. Frame-level logs need sampling and redaction. Avoid writing full payloads to logging services. Track negotiation failure rates and fallback rates through monitoring and alerts.

    Illustrative frame structure (pseudocode, conveying the idea only):

    1. Frame {
    2. version: u8
    3. type: DATA | SCHEMA | AUTH | STREAM_END | ERROR
    4. stream_id: u32
    5. schema_ref: u64 // semantics layer reference
    6. auth_ref: u64 // identity layer reference
    7. payload: bytes
    8. }

    5. Evaluation and Adoption Advice

    Establish a baseline first: field-name repetition rate, average response tokens, time to first byte, and end-to-end latency. Then introduce schema reuse and identity frames, and measure incremental gains and fallback rate.

    A three-step adoption path: first, pilot the semantics layer on a single internal endpoint; second, add identity and authorization frames running in parallel with the existing gateway; third, consider multiplexing and priority-based flow control.

    6. What We Still Have Not Figured Out

    Governance of cross-organization schema dictionaries, verifiable revocation of delegation chains, and version compatibility strategy for semantic dictionaries all lack satisfying answers. We would rather get challenges and edge cases from protocol practitioners than generic agreement.