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

    This article examines the recurring cost of repeatedly transmitting structural descriptions when large language models are connected to HTTP APIs, and proposes a five-layer protocol to address it. It breaks down four underlying problems—repeated schema definitions, missing agent identity, semantics deferred to inference time, and fragmented observability—then maps each to a dedicated layer covering transport and encoding, structure, identity and authorization, semantics, and orchestration with observability. The article also covers key design tradeoffs around compatibility, cache invalidation, least-privilege credentials, and observability-first design, followed by a four-phase rollout plan and a list of open questions. Readers will find a reproducible approach to measuring baseline costs and validating whether a dedicated agent protocol is warranted for their workloads.

    1. Where the Problem Starts: The Repeated “Context Tax”

    When you connect a large language model to a set of HTTP APIs, the first cost that surfaces is usually not the price per token of the model itself, but the repeated transmission of structural descriptions. A typical paginated list response repeats the same field names in every record: identifier, name, price, description, category, stock. The model has already “learned” this structure by the first page, but the transport layer has no concept of “you already know this.” The bytes are still sent, the tokenizer still splits them, and the bill is still charged.

    On several schema-dense internal workloads (product catalogs, accounting ledgers, information feeds), repeated structural descriptions can account for 30% to 60% of total response tokens. This range is strongly workload-dependent: APIs with few fields and long records yield limited savings, while APIs with many fields and short records yield significant savings. Any claim of a “universal fixed percentage of savings” is not credible. The right approach is to measure first, decide second, and publish a reproducible measurement method.

    This alone is not enough to justify “building a new protocol.” What truly drove the design was a steadily growing list of problems.

    2. Four Underlying Problems

    2.1 Structural Descriptions Repeat with Every Record

    Field selection can only narrow the range of data retrieved; field names still appear record by record. To eliminate the repetition, the protocol layer must introduce a mechanism for “declare structure once, reference it afterward.”

    2.2 Agent Identity Has No Place to Live

    Existing authentication designs target humans or “services pretending to be humans.” When an agent makes a call on behalf of a user, the server cannot reliably answer at the protocol layer: who issued it, what permission scopes it holds, whether it has been revoked, and which principal it represents. The common workaround is to stuff a token into a request header and hope the gateway parses it. The result is that every team reinvents its own wheel, each in a different shape.

    2.3 Semantics Are Pushed to Inference Time

    APIs return only structured data, and the meaning of fields must be explained by an ever-expanding system prompt—for example, the unit of a time field or the enumeration meaning of a status code. These explanations are consumed repeatedly on every call, and they are hard to version and hard to reuse.

    2.4 The Call Chain Lacks a Unified Observability Standard

    Agent calls are characterized by multiple steps, branching, and frequent retries. Traditional logging and metrics centered on a single request struggle to reconstruct the full picture of a task, leaving fault localization and cost accounting without a common language.

    3. The Layering Approach of a Five-Layer Protocol Stack

    Separating concerns is the prerequisite for controlling complexity. A five-layer organization is recommended, where each layer solves only one class of problem and can evolve independently.

    • Layer 1, Transport and Encoding: handles byte transport, compression, chunking, and streaming delivery, staying compatible with existing network infrastructure.
    • Layer 2, Structure: supports declaring a structure once and reusing it later via a reference identifier, and provides incremental evolution and version negotiation.
    • Layer 3, Identity and Authorization: uses verifiable credentials to carry the issuer, permission scopes, represented principal, and revocation status, with token verification separated from policy decisions.
    • Layer 4, Semantics: turns field meanings, units, enumerations, and constraints into addressable metadata, transmitted separately from the data, cacheable and versionable.
    • Layer 5, Orchestration and Observability: assigns a correlation identifier to a task that spans multiple calls, and unifies the recording of decision points, retries, and cost attribution.

    A schematic of structure reuse can be abstracted as:

    1. # First interaction: declare structure and register a reference identifier
    2. schema(id="catalog.item.v3", fields=[id,name,price,currency,status])
    3. data(ref="catalog.item.v3", rows=[[1001,"A",19.9,"CNY","shipped"], ...])
    4. # Subsequent interactions: send only the reference and data
    5. data(ref="catalog.item.v3", rows=[[1002,"B",5.0,"CNY","created"]])

    Separating semantic metadata from data:

    1. meta(target="catalog.item.v3.status",
    2. enum={"1":"created","2":"shipped","3":"closed"},
    3. unit_hint={"price":"minor_unit,currency=CNY"})

    4. Key Design Tradeoffs

    First, compatibility comes first. If a new protocol requires a network-wide overhaul, its chances of adoption are extremely low. A reasonable path is to perform bidirectional conversion at the gateway: keep the existing API shape externally, while enabling efficient encoding and identity credentials internally, so that existing callers gain benefits with zero changes.

    Second, the invalidation strategy for semantic caching. Structure and semantic metadata can be cached, but there must be a clear version identifier and invalidation notification. Otherwise, hidden errors like “the data is new but the explanation is old” will occur.

    Third, least privilege and revocability for identity credentials. Credentials should be short-lived, issued at task granularity, and support immediate revocation; permission decisions should live in the server-side policy layer, avoiding placing all trust on the client.

    Fourth, observability standards come first. If the correlation identifiers and cost fields of Layer 5 are not defined early in the design, the cost of backfilling data later is extremely high.

    5. A Phased Rollout Roadmap

    • Phase 1: Establish a baseline. Select two or three schema-dense APIs, measure the proportion of repeated structure, average response latency, and cost per task, and produce reproducible scripts.
    • Phase 2: Gateway pilot. Implement structure reuse and externalized semantics at the gateway, roll out gradually, and compare token consumption and end-to-end latency against the baseline.
    • Phase 3: Identity and policy. Integrate verifiable credentials, connect revocation and auditing, and complete full-chain tracing for multi-step calls.
    • Phase 4: Standardization and tooling. Consolidate multi-language reference implementations, compatibility test suites, and benchmark reports, and clarify a list of unresolved problems.

    6. Open Questions

    First, the trust boundary of structure references in cross-organization scenarios, and how to prevent reference identifiers from being abused. Second, the multi-party co-construction and governance of semantic metadata. Third, the error recovery semantics when streaming output is combined with structure reuse. Fourth, the attribution model for cost accounting under retries and branching. Writing these uncertainties explicitly is more valuable than claiming “everything is solved.”

    7. Conclusion

    The gains at the protocol layer come from eliminating repetition and unifying semantics, not from piling on new concepts. To decide whether a dedicated protocol is needed, answer just two questions: do repeated transmission and semantic explanation already constitute a major cost; and can existing authentication and observability means support multi-step agent tasks? If the answer is yes, evolving step by step across the five layers and validating gains with reproducible benchmarks is the lowest-risk path. Peers who have thought seriously at the protocol layer are welcome to help refine this design with concrete workload data rather than conclusion slogans.