How A2A over MQTT Transforms AI Agent Collaboration

This article explains the challenges of traditional point‑to‑point AI agent communication, introduces the A2A protocol and its limitations, and details how combining A2A with MQTT via Tencent Cloud TDMQ creates a dynamic, loosely‑coupled, and scalable solution with practical SDK examples and real‑world case studies.

Tencent Cloud Middleware
Tencent Cloud Middleware
Tencent Cloud Middleware
How A2A over MQTT Transforms AI Agent Collaboration

Background

When AI agents are deployed at scale, traditional point‑to‑point communication suffers from difficult service discovery, tight coupling, and low reliability in distributed environments. A transport that provides dynamic registration, decoupled messaging, and built‑in reliability is required.

MQTT Protocol Overview

MQTT (Message Queuing Telemetry Transport) is a lightweight publish‑subscribe protocol designed for low‑bandwidth, unreliable networks. It supports retained messages, last‑will messages, QoS levels (0‑2), and persistent sessions, making it suitable for asynchronous, loosely‑coupled communication.

A2A Protocol Overview

The Agent‑to‑Agent (A2A) protocol defines a standard interaction model for AI agents. Each agent publishes an AgentCard – a JSON document that describes its capabilities and the topics or HTTP endpoints it listens on. Core methods such as sendMessage are defined using JSON‑RPC over HTTP, and agents stream status updates back to the caller.

Limitations of the Original A2A Protocol

Static service discovery : Agents are discovered only via a fixed URL (e.g.,

https://{agent‑server‑domain}/.well-known/agent‑card.json

), requiring prior knowledge of every agent.

Strong upstream/downstream coupling : Direct HTTP/gRPC connections assume a stable network path; failures break the workflow.

No built‑in state management : HTTP is stateless, so callers must implement their own tracking of task progress.

Limited security model : Authentication is out‑of‑band only; flow control and fine‑grained permissions are absent.

A2A over MQTT – Design Benefits

Dynamic service discovery : Agents publish their AgentCard as retained messages on a discovery topic. New agents are automatically visible, and offline agents are removed via last‑will messages.

Broker‑level load balancing : Shared subscriptions distribute incoming tasks across multiple agent instances without external load balancers.

Loose coupling : Publish‑subscribe decouples callers from executors; agents only need to maintain a connection to the MQTT broker.

Built‑in state management : Persistent messages and QoS ensure that tasks are not lost if an agent disconnects, enabling checkpoint‑style processing.

Enhanced security : TLS encryption, client‑certificate authentication, and ACLs are provided by the MQTT broker.

Typical A2A over MQTT Workflow (Code‑Generation Agent Example)

Service discovery : The client resolves the agent’s AgentCard via MQTT (e.g., using a resolver that subscribes to the discovery topic).

Task submission : The client publishes a request on the agent’s task topic. The agent streams TaskStatusUpdateEvent messages and finally a completion message.

{
  "id": "12345",
  "final": false,
  "status": {"state": "submitted", "message": "Task has been accepted and is being processed."}
}

During execution the agent may emit an artifact update:

{
  "taskId": "12345",
  "artifact": {
    "id": "artifact-1",
    "name": "TODO List",
    "parts": [{"kind": "text", "text": "1. Analyze the existing thread pool implementation.
2. Design the coroutine‑based equivalent.
3. Implement the coroutine version step by step.
4. Test the new implementation."}]
  }
}

When the task finishes a final status is sent:

{
  "id": "12345",
  "final": true,
  "status": {"state": "completed", "message": "Task has been completed successfully."}
}

Python SDK Example

The following snippet shows how to discover an AgentCard via MQTT, create an A2A client, and send a message.

# MQTT broker URL (example)
mqtt_broker_url = "mqtt://user0:[email protected]:1883/default-org"

# Resolve AgentCard by agent name
resolver = AgentCardResolver(mqtt_broker_url)
agent_card = await resolver.discover_agent("code-generator-agent")

# Configure client to use MQTT transport
config = ClientConfig()
config.supported_transports = ["MQTT"]
factory = ClientFactory(config)
factory.register(
    "MQTT",
    lambda card, url, cfg, interceptors: MqttTransport(mqtt_broker_url, card)
)
client = factory.create(agent_card)

# Build and send a message
message = Message(
    message_id=str(uuid.uuid4()),
    role=Role.user,
    parts=[TextPart(text="将线程池改写成协程")]
)
response = client.send_message(message)

The code mirrors the usage pattern of the open‑source A2A SDK; only the transport layer is swapped to MQTT.

Real‑World Deployment Scenarios

Message‑Queue Diagnostic Agent : Registers its AgentCard as a retained message, uses a last‑will to clear stale registrations, and receives long‑running diagnostic tasks via a dedicated topic. Asynchronous MQTT communication avoids HTTP timeout issues.

Distributed AI‑Ops Platform (Cloud Mate) : Agents are discovered through shared subscriptions; the broker balances tasks across a cluster. Wildcard task topics allow a single server to serve many agents, and QoS guarantees reliable delivery even under network interruptions.

Future Enhancements

Large‑file transfer optimization : Combine object storage with MQTT to efficiently transmit images, audio, or other binary artifacts.

Observability enhancements : Build a distributed tracing system based on MQTT message chains to visualize call graphs and latency.

Ecosystem integration : Provide MQTT transport adapters for frameworks such as LangChain and AutoGen, lowering integration barriers.

distributed-systemsAI agentsMQTTcloud middlewareA2A protocol
Tencent Cloud Middleware
Written by

Tencent Cloud Middleware

Official account of Tencent Cloud Middleware. Focuses on microservices, messaging middleware and other cloud‑native technology trends, publishing product updates, case studies, and technical insights. Regularly hosts tech salons to share effective solutions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.