Agent Communication Protocol Design: Best Practices and Common Pitfalls

    This article examines why connecting large language models to standard HTTP APIs often increases both token costs and engineering complexity, and proposes a layered communication protocol as a practical response. It breaks the problem into four root causes—repeated schema fields, missing agent identity in the protocol, semantics deferred to inference time, and weak error recoverability—then defines five layers covering session, schema, identity, semantics, and encoding. It also outlines key design choices, boundaries with existing approaches, a phased adoption roadmap with acceptance metrics, and open questions that still need reproducible data.

    Introduction: Why Bills and Complexity Rise Once Agents Connect to APIs

    After connecting a large language model to a set of ordinary HTTP endpoints, many teams observe two patterns. First, response payloads look small, yet token consumption on the model side climbs rapidly. Second, integration testing consumes a large amount of time explaining field meanings and inventing ad hoc ways to pass identity. The first is a cost problem; the second is an engineering consistency problem. This article does not focus on any specific product. Instead, it abstracts these patterns into a communication protocol design problem between agents and web services, and discusses a more rigorous layered approach and engineering practices.

    1. The Problem Starts with a Paginated Response

    Consider a common paginated query. Every row in the result carries the same field names: identifier, name, price, description, category, stock, and so on. The model has already “learned” this structure from the first page, but traditional text-based transfer formats have no concept of “you already know this.” As a result, field names must be resent for every page and every record, the tokenizer has to segment them again, and the caller pays for it.

    On structure-dense endpoints (catalogs, ledgers, feeds), this repeated overhead often accounts for a considerable share of the response content. The exact share depends heavily on the workload and cannot be generalized. The rigorous approach is to publish a reproducible benchmark with ranges and a documented test method, rather than a single isolated number.

    2. Breaking “Hard to Use” into Four Underlying Problems

    1. Schema descriptions are retransmitted with every record. Even if you select only the fields you need, field names still travel with each record and cannot be reused at the session level.
    2. Agent identity has no place in the protocol. Traditional authentication is designed for humans or for services that “pretend to be human.” When a model calls on behalf of a user, the server cannot directly learn at the protocol layer who issued the agent, what its authorization scope is, whether it has been revoked, or how long it remains valid. The common workaround is to stuff this into a generic carrier header, but implementations differ across teams and gateway parsing capabilities vary.
    3. The semantic layer is pushed to inference time. Endpoints return only structured data. Field meanings, enum values, units, time zones, and null semantics must be explained on the fly through system prompts, repeated on every call and completely invisible at the protocol layer.
    4. Errors and recoverability are poorly expressed. Models need machine-readable, decision-ready error semantics (retryable or not, whether user input is required, whether authorization must be switched), not a block of human-readable text.

    3. The Goal: A Layered Protocol for Agent Traffic

    Split communication into five layers, where each layer solves exactly one problem, instead of cramming everything into a single text stream:

    • Session layer: establish, renew, and close sessions; negotiate capability sets and versions.
    • Schema layer: negotiate the structure once (fields, types, constraints, enums), then reference it by version.
    • Identity layer: a standardized agent identity and authorization context that is verifiable, revocable, and auditable.
    • Semantic layer: externalize field meanings, units, null policies, and similar information as cacheable metadata.
    • Encoding layer: compact, incremental, streamable data encoding with support for references and deltas.

    Illustrative session negotiation pseudocode (it expresses the layering idea only and does not represent any real API):

    1. OPEN session
    2. capabilities: [schema_ref, agent_identity, semantics_ref, delta_encoding]
    3. versions: {schema: "v1", semantics: "v1"}
    4. -> SESSION_READY
    5. REQUEST page=2
    6. schema_ref: "catalog@v1" # no repeated field names
    7. identity: <signed context> # verifiable authorization context
    8. semantics_ref: "catalog@sem1"
    9. -> DATA rows=[...] + delta patches

    4. Four Key Design Choices

    1. Negotiate the schema once, reference it many times. Exchange fields and constraints on the first turn within a session, then send only the version number and row data. Version changes go through an explicit upgrade flow to avoid silent drift.
    2. Standardize the identity context. Put the issuer, scope, validity period, revocation identifier, and delegation relationship into a verifiable context object, and have servers and gateways validate it under unified rules rather than per-team custom logic.
    3. Externalize and cache semantics. Deliver enums, units, time zones, and null meanings as metadata once, then let clients and the model side cache and reuse them to reduce repeated explanation at inference time.
    4. Use compact encoding and delta updates. Transmit only what changed, represent list data as references plus patches, and keep streaming output incrementally parseable.

    5. Boundaries with Existing Approaches

    Selecting only required fields reduces useless fields but cannot eliminate record-level field-name repetition. Generic carrier headers can carry tokens but lack unified agent identity semantics. System prompts can patch semantics temporarily, but they are not reusable, observable, or governable. The value of a layered protocol is to converge these fragmented, “everyone does their own thing” parts into contracts that are negotiable, cacheable, and auditable.

    6. Adoption Roadmap and Acceptance Metrics

    • Phase 1: enable schema references on structure-dense endpoints; measure the reduction in repeated overhead and the change in first-packet latency.
    • Phase 2: adopt the standardized identity context; connect gateway validation and revocation flows.
    • Phase 3: externalize semantic metadata; observe changes in system prompt length and call cost.
    • Phase 4: introduce delta encoding; evaluate incremental parsing stability in streaming scenarios.

    Suggested acceptance metrics: token cost per unit of response, time to first byte, integration testing time, authentication failure rate, share of recoverable errors, and cross-language SDK consistency. Every metric should come with a reproducible test method rather than a single point number.

    7. Open Questions

    • The long-term governance cost of version negotiation and backward compatibility.
    • How to express authorization chains when multiple agents act for different users.
    • The trust boundary and signature mechanism for semantic metadata.
    • Trade-offs of delta encoding under weak networks and high concurrency.

    Conclusion

    The bottleneck in agent-to-web-service communication is shifting from “can we get the call through” to “is it efficient, governable, and interoperable.” Handling schema, identity, semantics, and encoding in separate layers is a pragmatic path to reducing token waste and engineering fragmentation. If you have thought carefully at the protocol layer, share reproducible data and real workload feedback to help make this layered approach more rigorous.