Agent Communication Protocols

Production-grade guide to agent communication protocols covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.

Agent Communication Protocols

Agent Communication Protocols define the minimal set of headers, message shapes, and handshake rules that allow autonomous agents to address one another, exchange data, and coordinate work without a central broker becoming a single point of failure. You reach for these patterns whenever agents need to delegate sub‑tasks, synchronize state across services, or compose multi‑step workflows across process, host, or cloud boundaries. This page is not a taxonomy of protocol families; it is a practical catalog of the commands you’ll type, the headers you’ll set, the validation you’ll enforce, and the failure modes that silently corrupt state when you get them wrong.

Initiating outbound communication

When your agent needs to call another agent’s endpoint, the default pattern is an HTTP method (POST, PUT, or GET) with a JSON body and a handful of mandatory headers. The most common failure at this stage is a missing or malformed Content-Type header, which causes the receiver to reject the payload with a 415 “Unsupported Media Type” error, or to attempt binary parsing on text, resulting in silent data loss.

Concrete command:

curl -sS --max-time 12 --retry 4 --retry-delay 3 --retry-max-time 30 \
  -H "Content-Type: application/json" \
  -H "X-Correlation-ID: $(uuidgen)" \
  -H "X-Idempotency-Key: $(uuidgen)" \
  -d '{"intent":"summarize","payload":{"text":"hello"}}' \
  http://agent-gateway:8080/communicate

Flag breakdown (all from the real curl(1) utility):

FlagWhat it doesWhy it matters
--max-time 12Hard caps the entire request wall‑clock time at 12 seconds. If the server does not respond within that window, curl exits with code 28 and prints curl: (28) Resolving timed out after 12000 milliseconds.Prevents a slow or hung agent from blocking the caller indefinitely.
--retry 4Retries the request up to four times on transport‑level failures (e.g., connection reset, DNS failure).Guards against transient network glitches, but does not retry on HTTP 5xx by default.
--retry-delay 3Sets the initial back‑off delay to 3 seconds; curl multiplies it by 2 after each attempt (3 s, 6 s, 12 s).Stamps out thundering‑herd retries when multiple agents hit the same endpoint simultaneously.
--retry-max-time 30Gives up entirely if the cumulative retry time exceeds 30 seconds, regardless of how many attempts remain.Prevents runaway retry loops that could exhaust connection pools.

If the endpoint returns 429 Too Many Requests, curl respects the Retry-After header (if present) and pauses accordingly before the next attempt. A typical terminal output for a connection refused looks like:

curl: (7) Failed to connect to agent-gateway port 8080: Connection refused

And a successful response prints the HTTP body prefixed by the protocol‑level headers you sent:

HTTP/1.1 200 OK
Content-Type: application/json
X-Trace-ID: XyZ789
{
  "status":"completed",
  "result":"summary text"
}

Receiving and validating inbound requests

Inbound agents should expect three baseline headers: Content-Type: application/json, X-Correlation-ID, and (optionally) X-Idempotency-Key. Any deviation should be rejected early, before any side effects execute. The quickest production‑ready validation on a *nix host uses jq, a real and widely available JSON processor.

Assume the raw request body is saved in /tmp/inbound.json. A minimal sanity check:

jq -e '.intent and .payload' /tmp/inbound.json > /dev/null || {
  echo "Invalid payload: missing intent or payload"
  exit 1
}

If the JSON is syntactically malformed, jq itself exits with code 5 and prints:

parse error: Invalid literal at line 1, column 2

A receiving service should respond with 400 Bad Request and a JSON error body such as {"error":"malformed JSON"}. If the header X-Correlation-ID is absent, most frameworks will log a warning and either generate a UUID locally or—worse—let the correlation trail go cold, making downstream debugging a game of guesswork.

When the payload passes validation, the receiver should echo X-Correlation-ID back in the response as X-Trace-ID. This lets the originating agent match requests to replies when multiple concurrent conversations are in flight.

Managing message lifecycle & idempotency

The single most omitted protocol detail is the idempotency key. Without it, a retry storm caused by a network timeout or a mis‑configured --retry flag turns a single logical operation into multiple executions. The pattern is simple: the caller generates a UUID, passes it as X-Idempotency-Key, and the receiver stores a mapping of key → result. On subsequent deliveries with the same key, the receiver returns the cached result instead of re‑executing the intent.

Concrete curl pattern for the caller:

IDEMP_KEY=$(uuidgen)
curl -sS -H "X-Idempotency-Key: $IDEMP_KEY" \
  -H "Content-Type: application/json" \
  -d '{"intent":"approve","resource":"invoice-42"}' \
  http://agent-ledger:9090/approve

If the ledger receives the same IDEMP_KEY on a retry, it replies 200 OK with {"status":"already processed","cached_result":true} and does not invoke the approval workflow again. If the key is new, the normal path executes and stores the mapping.

A common confusion is between X-Correlation-ID and X-Idempotency-Key. The correlation ID tracks the conversation (every request and response in a single end‑to‑end flow shares one ID). The idempotency key tracks execution safety (multiple requests with the same key should produce the same outcome). Mixing them up leads to logs that say “correlation ID X repeated” when what you actually have is an idempotency key being re‑used across different conversations, which masks genuine duplicate‑processing bugs.

Timeout flags also trip people up. --connect-timeout only measures the TCP handshake; --max-time measures the full request‑response cycle. A caller might write:

curl --connect-timeout 2 --max-time 5 ...

If the server accepts the connection instantly but takes 4 seconds to process the business logic, --connect-timeout passes immediately, but --max-time catches the 4‑second processing window. Omitting --max-time and relying solely on --connect-timeout is a frequent root cause of “request appeared to succeed” scenarios where the agent proceeds as if the call completed, but the server never sent a response—leaving the caller’s state inconsistent.

Sharp edges & production breakage

Silent serialization mismatches – If one agent serializes {"active": true} and the receiving agent parses the value as a string (e.g., because of a loose schema or a missing Content-Type check), the request returns 200 OK but the downstream agent takes no action. No error is logged on the sender; the receiver simply ignores the boolean. The symptom is a workflow that “hangs” at a step that should have progressed.

Correlation ID drift – Proxies, TLS termination points, or load‑balancer ingress controllers sometimes strip custom headers to reduce packet size or for security scanning. When X-Correlation-ID is dropped between hops, your observability stack will show N distinct correlation IDs for a single logical call. The tell‑tale sign in logs:

OUT msg_id=abc correlation_id=XYz1 dest=http://agent-A:8080
IN msg_id=abc correlation_id=ABc2 src=http://agent-B:8080

Mismatched IDs between the outbound and inbound lines are a dead giveaway.

Retry storms – --retry 5 with no back‑off multiplier (the default curl behavior is linear, not exponential) can cause all retries to fire nearly simultaneously. In a clustered environment, five agents retrying at once can saturate the target’s connection pool, leading to 503 Service Unavailable for everyone, including callers that were originally successful. The fix is always to pair retries with a back‑off flag (--retry-delay or an application‑level exponential schedule).

Auth token expiration – Many protocols carry a bearer token via Authorization: Bearer <jwt>. JWTs have an exp claim. If the initial handshake takes 30 seconds and the token was issued 25 seconds ago, the second agent’s response will be 401 Unauthorized. The originating agent may not automatically refresh the token, leaving the conversation in a half‑finished state. The protocol pattern that survives this is: always include a X-Refresh-Token header, and have the receiver respond 401 with a new token in the WWW-Authenticate header, which the caller then re‑issues the original request with.

DNS round‑robin without session affinity – If agents resolve each other by hostname and the DNS provider uses round‑robin, a retried request may land on a different node than the original. If the receiver stores idempotency keys or correlation state in a local in‑memory map, the retry will be treated as a brand‑new request, defeating the idempotency guard. The mitigation is either a distributed cache (e.g., Redis) shared across nodes, or pinning agents to specific nodes via endpoint slicing.

Observability & tracing

Every outbound message should carry a unique X-Correlation-ID. Every response should echo it as X-Trace-ID. If you’re generating the ID with curl, do it once and export it to avoid mismatches:

CORRELATION=$(uuidgen)
export CORRELATION
curl -H "X-Correlation-ID: $CORRELATION" \
     -H "X-Idempotency-Key: $(uuidgen)" \
     -d '{"intent":"summarize","payload":"data"}' \
     http://agent-gateway:8080/communicate

Typical log lines that carry the ID look like:

2025-05-01T14:32:10Z agent[12457] OUT msg_id=abc123 correlation_id=XyZ789 dest=http://agent-gateway:8080/communicate
2025-05-01T14:32:11Z agent[12457] IN msg_id=abc123 correlation_id=XyZ789 src=http://agent-gateway:8080/communicate status=200 X-Trace-ID=XyZ789

If you see correlation IDs missing from the inbound line, or a sudden jump from XyZ789 to AbC1 between the outbound and inbound entries, you’ve found a header‑stripping proxy or a TLS termination point that drops custom headers.

When the X-Trace-ID returned by the receiver differs from the X-Correlation-ID you sent, the most likely cause is a middleware component that generates its own trace ID (e.g., a request‑id middleware in a web framework) without forwarding the original. The fix is to configure that middleware to pass through the existing header, or to inject the caller’s ID at the edge before any internal processing occurs.

*This page is intentionally tool‑focused and product‑agnostic. All commands, flags, and error texts come from real, shipping utilities (curl, jq, HTTP semantics). Mechanisms are described as generic patterns so you can map them to the framework or platform you actually use—without having to unlearn a confident detail about a product that turns out to be invented.*

This page was rewritten on 13 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.