Five-Layer Wire Protocol Design for AI Agent Communication
This article presents a practical design for a five-layer wire protocol built for AI agent traffic. It explains why conventional HTTP/JSON wastes a large share of tokens on repeated structure descriptions, and identifies four recurring pain points: repeated schema information, missing agent identity at the protocol layer, semantics deferred to inference time, and inconsistent error and retry behavior. The article then walks through the five layers—transport and framing, session and state, semantics and structure, identity and authorization, and policy and observability—along with the direct benefits of embedding identity and moving semantics forward. It also covers reproducible evaluation methodology and openly discusses unresolved issues such as schema negotiation fallback, ecosystem compatibility, cross-implementation consistency, and privacy.
1. Where the Problem Starts: Token Budget Is Being Eaten at the Protocol Layer
Once you connect a large language model to existing HTTP endpoints, one thing becomes clear very quickly: only part of the invocation cost goes toward actual inference. A significant share is consumed by repeatedly explaining the same data structure.
Take the most common paginated list endpoint as an example. Every row in the response carries the full set of field names: identifier, name, price, description, category, stock, and so on. By the first record on the first page, the model already understands this structure. But traditional HTTP/JSON semantics have no notion of “you already know this.” The bytes still have to go over the wire, the tokenizer still has to process them, and the bill still has to be paid.
We ran rough measurements across several internal workloads. On structure-heavy endpoints (product catalogs, accounting ledgers, content feeds), repeated structure descriptions accounted for roughly 30% to 60% of response tokens. This range is strongly workload-dependent, so we do not treat a single number as a conclusion. Instead, we publish the evaluation scripts, the dataset construction method, and the measurement criteria together, forming a reproducible benchmark rather than leaving readers with an isolated percentage.
On its own, this was not enough to justify designing a protocol from scratch. What actually pushed us forward was the list of friction points we kept hitting with HTTP for agents—a list that only kept growing.
2. Four Recurring Low-Level Problems
2.1 Structure Information Repeated with Every Record
Field names travel with each record. This is an inevitable result of representing nested structures in flat text. Query projection approaches can trim unused fields, but they cannot eliminate the fact that the same field name is repeated before every record. In long lists and deep pagination scenarios, this overhead grows linearly with the number of records.
2.2 No Place for Agent Identity at the Protocol Layer
Existing transport-layer authentication was designed for human users or “services pretending to be human.” When an agent makes a call on behalf of a user, it is hard for the server to directly answer four questions at the protocol level: who issued the credential, what the permission scope is, whether it has been revoked, and which principal it represents. The common practice today is to stuff a token into a request header and rely on the gateway to parse it. This works, but every team reinvents the wheel, and implementation details differ. As a result, cross-team integration and audit costs stay high.
2.3 Semantic Interpretation Pushed to Inference Time
Endpoints return only structured data, and the meaning of fields is left for the model to infer. In practice, this forces teams to pile up long prompts that explain, item by item, the format of time fields and mappings such as enum value 2 meaning “shipped.” This explanatory work happens on every inference call and is paid for repeatedly, while the protocol layer remains completely blind to semantics and cannot reuse them.
2.4 Inconsistent Error and Retry Semantics
Human-facing endpoints usually return a human-readable error message. Agents, however, need decidable machine semantics: is this a retryable rate limit, a non-retryable parameter error, or a business rejection that requires human intervention? Without a unified classification, agents can only guess, which leads to ineffective retries and cascading failures.
3. The Five-Layer Design
We split the protocol into five layers. The core principle: each layer solves one class of problem, and no upper layer may assume a lower layer has already solved its problem.
- Transport and framing layer: handles connection reuse, frame boundaries, compression, and flow control. The goal is to make “multiple exchanges within one session” a first-class citizen, rather than rebuilding context on every call.
- Session and state layer: maintains a context identifier within a task so the server can recognize “this is a follow-up request for the same task,” providing the prerequisite for structure negotiation and cache hits.
- Semantics and structure layer: allows the structure description to be negotiated once at the start of a session, after which responses carry only data and deltas. It also carries field-level semantic metadata, moving the cost of interpretation from inference time forward to the protocol layer.
- Identity and authorization layer: makes the issuer, permission scope, revocation status, and delegation chain protocol fields, rather than stuffing them into generic request headers for the gateway to guess.
- Policy and observability layer: unifies error classification, retry decisions, quotas, and audit events, so traffic can be measured and governed at the protocol layer.
A schematic session negotiation can be abstracted as:
HELLO { protocol: "np/1", sdk_lang, agent_id, scope, delegation }SCHEMA { schema_id: "product_page_v3", fields: [...], semantics: {...} }REQ { op: "list", ref: schema_id, page: 2 }RESP { ref: schema_id, rows: [...], err_class: null }
The key point is that schema_id is transmitted only once, and subsequent requests and responses reuse it by reference. semantics makes field meaning travel with the structure, instead of being re-injected with every prompt.
4. Direct Benefits of Embedding Identity
With identity as protocol fields, the server can make authorization decisions without parsing the business payload: whether the issuer is trusted, whether the scope covers the current operation, whether the credential is on the revocation list, and whether the call is a direct user connection or a multi-hop delegation. In multi-agent collaboration scenarios, the delegation chain field can also answer “who is ultimately responsible for this call,” which is critical for accountability and audit trails. It is worth emphasizing that this only places information at the protocol layer; it does not replace gateway-side rate limiting, risk control, or key management. The two are additive, not substitutes.
5. How Moving Semantics Forward Lowers Long-Term Cost
The traditional approach puts semantics in prompts, where cost accumulates linearly with the number of calls. Once semantics are part of the protocol and negotiated once per structure, the cost is roughly amortized to the session level. This brings two additional engineering benefits: first, prompt size drops, so the model’s attention is more focused on the task itself; second, semantic changes can be versioned, so a structure upgrade does not force every caller to update its prompt in sync.
6. Evaluation Criteria: Avoiding Self-Serving Claims
Any performance claim needs a reproducible basis. Our approach is to publish three types of information: how the workload is constructed (endpoint shape, record count, field density), the measurement boundaries (whether handshake and negotiation overhead is included), and the comparison baseline (the traditional calling method under the same workload). Numbers only mean something when compared under the same criteria. We also deliberately separate “share of structure overhead” from “end-to-end latency gains.” The former is easy to measure; the latter is more affected by the network and the inference side, and the two should not be conflated.
7. What We Have Not Figured Out Yet
- Failure and fallback for structure negotiation: when server-side structures change frequently, how should the reference-invalidation strategy be designed to avoid extra round trips?
- Compatibility boundaries with the existing ecosystem: which capabilities should the protocol own, and which should be left to upper-layer frameworks? Right now we only have empirical judgment.
- Consistency across multi-language reference implementations: the risk of semantically equivalent but behaviorally divergent implementations needs a cross-implementation consistency test suite to constrain it.
- Security and privacy: semantic metadata itself may leak the business model, and whether tiered disclosure is needed remains undecided.
If you have also thought seriously about the shape of agent traffic at the protocol layer, feedback from three angles is welcome—workload characteristics, identity models, and semantic reuse—especially real data that can challenge our assumptions.
