A Five-Layer Protocol for AI Agent Communication: Design and Practice

    This article examines why conventional request-response APIs struggle with AI agent traffic and presents a five-layer protocol design that addresses four structural gaps: repeated schema descriptions in every record, the lack of a standard place for caller identity, semantics deferred to inference time, and ambiguous failure and retry boundaries. It details the responsibilities of the transport, wire format, identity and authorization, semantic, and session/observability layers, with pseudocode examples for schema-once encoding, field-level principal assertions, and cacheable field contracts. It also covers idempotency keys, failure classification, trace identifiers, audit events, a phased adoption path with reproducible measurement criteria, and open questions around cache eviction, delegation chains, contract versioning, and cross-organization trust anchors.

    1. Where the Problem Starts: Why Agent Traffic Breaks Traditional APIs

    Once you put a large language model behind a conventional request-response API, one thing becomes immediately obvious: a meaningful share of the model’s context budget is consumed by repeated structural descriptions. Take a common paginated list query. Every row in the response carries the same field names again and again — identifier, name, price, description, category, stock, and so on. The model has already “learned” that structure from the first record, but plain text-based data formats have no concept of “you already know this.” The bytes still go over the wire, the tokenizer still processes them, and the caller still pays for them.

    In schema-heavy business scenarios such as product catalogs, account transaction records, and content feeds, this repeated structural description can account for roughly half of the response content. That ratio is strongly dependent on the specific workload and should not be treated as a universal conclusion; the rigorous approach is to publish a reproducible measurement method rather than simply throwing out a number.

    This alone is not enough to justify the decision to redesign an entire protocol. What actually makes the case is a problem list that keeps growing.

    2. Four Underlying Gaps

    2.1 Structural descriptions are transmitted with every record

    Even with a query scheme that allows fields to be fetched on demand, field names still travel with every single record. What gets saved is the “fields you don’t need,” not the “structure you have already expressed.”

    2.2 No standard place for caller identity

    Traditional API authentication is designed mainly for human users or for “services disguised as humans.” When an agent makes a call on behalf of a user, the server side has difficulty asking four questions at the protocol level: who issued it, which permission scopes were granted, whether it has been revoked, and what its validity period and delegation chain are. The prevailing practice in the real world is to carry a token and parse it at the gateway. It works, but every team is reinventing the wheel, in different shapes, which makes interoperability difficult.

    2.3 Semantic interpretation is pushed to the inference stage

    The API returns only structured data, and the meaning of each field has to be figured out by the model itself. As a result, engineering teams are forced to pile up lengthy prompts that repeatedly explain the format of a given timestamp field, or whether a given status code means “shipped” or “cancelled.” These explanations happen on every inference, so the cost is multiplied by the number of calls, while the protocol layer remains completely unaware of any of it.

    2.4 Failure semantics and retry boundaries are blurry

    Agent calls are characterized by multiple steps, long chains, and possible self-correction. Does a timeout mean the operation never ran, that it ran but the receipt was lost, or that it failed halfway through? Without a unified failure taxonomy and idempotency identifiers, upper layers can only retry blindly, amplifying the risk of side effects.

    3. Layered Design: Dividing Responsibilities Across a Five-Layer Protocol Family

    The point of layering is not to add concepts. It is to let each layer solve exactly one class of problem and evolve independently.

    • Transport layer: responsible for reliable byte delivery, supports long-lived connections and streaming, and handles reconnection and backpressure.
    • Wire format layer: defines the encoding rule of “declare the structure once, then send only values,” and is the core of redundancy reduction.
    • Identity and authorization layer: carries the caller principal declaration, permission scopes, delegation chain, and revocation information.
    • Semantic layer: describes field meanings, value domains, and units as cacheable contracts, moving interpretation cost forward from inference time to connection establishment.
    • Session and observability layer: unifies trace identifiers, failure classification, idempotency keys, and audit events.

    Key conventions of the wire format

    The core idea is “declare the structure only once.” A sketch follows (pseudocode, expressing the encoding idea only):

    1. # First interaction: declare structure and field order
    2. SCHEMA id=1 fields=[item_id, name, price, currency]
    3. # Subsequent interactions: send values only, aligned to the declared order
    4. DATA schema=1 rows=[
    5. [1001, "Sample Product", 39.90, "CNY"],
    6. [1002, "Sample Product Two", 19.90, "CNY"]
    7. ]
    8. # Increment the version when the structure changes; never reuse an old id
    9. SCHEMA id=2 fields=[item_id, name, price, currency, stock]

    There are three key points: the structure identifier must be explicit and monotonically increasable; field order is the contract and must not change implicitly; and a parser encountering an unknown structure identifier should be able to raise a clear error rather than guess.

    Making identity and authorization field-level

    Turn “who I am, what I can do, who authorized me” into protocol fields instead of stuffing them into generic headers:

    1. ASSERT principal=agent:7f3c
    2. issuer=platform-a
    3. scope=catalog:read orders:write
    4. delegation=[user:9a21 -> agent:7f3c]
    5. expires=2026-07-01T10:00:00Z
    6. revocation_endpoint=...

    This way, gateways, servers, and audit systems no longer each have to parse a private format, and revocation checks gain a single entry point.

    4. The Semantic Layer: Moving Interpretation Cost Forward

    The goal of the semantic layer is to make “what a field means” a cacheable contract instead of something restated on every inference. Practical approaches include: attaching type, unit, enumerated values, and business meaning to each field; giving enums stable identifiers rather than magic numbers; and caching the contract by structure identifier so it is negotiated once at connection establishment and then reused.

    1. FIELD status type=enum
    2. values=[0:created, 1:paid, 2:shipped, 3:closed]
    3. semantics="Order fulfillment status, for display and flow decisions only"

    The benefits run both ways: on the model side, shorter prompts and a lower probability of misinterpretation; on the server side, a stable field contract that makes validation and version governance easier.

    5. Reliability and Observability

    • Idempotency keys: write operations must carry a unique identifier generated by the caller, which the server uses for deduplication to avoid duplicate side effects caused by retries.
    • Failure classification: distinguish at least three categories — “safe to retry,” “requires an upper-layer decision,” and “not retryable” — each with a reason code.
    • Trace identifiers: one business session spans multiple rounds of calls and needs a unified identifier to link them, making it easier to pinpoint which step introduced the deviation.
    • Audit events: identity assertions, authorization changes, and revocation check results should be replayable, meeting compliance and troubleshooting needs.

    6. Adoption Path and What Is Still Unsettled

    A gradual rollout is recommended: first do structure deduplication and field contract caching at the gateway and validate the gains; then introduce standardized principal assertions and revocation checks; finally fill in failure classification and auditing. Each stage needs a reproducible measurement basis, for example the share of repeated structure, average context length, and retry amplification rate.

    Several open questions must be acknowledged: cache eviction strategies for structure negotiation with very large field sets; rules for permission convergence in multi-hop delegation chains; version compatibility and canary rollout for semantic contracts; and how to govern trust anchors in cross-organization scenarios. None of these have a once-and-for-all answer; they need repeated calibration against real traffic.

    The most valuable takeaway for developers is this: the communication bottleneck for agent-facing systems is often not “whether the connection works,” but whether these four kinds of information — structure, identity, semantics, and failure — have a stable place in the protocol. Pulling them out of prompts and private headers and turning them into negotiable, cacheable, auditable contracts is what makes an evolvable foundation. If you have related practice, feel free to share your measurement methods and lessons learned in the comments.