Messages¶
Actively evolving interface
The Message model and MessageType vocabulary are being redesigned as part of a planned v1 architecture. Several things will change before the API locks:
Fewer, clearer message types. The current 13-type set is being consolidated into a smaller, more intuitive vocabulary. Types that map to protocol internals will be removed from the developer surface.
First-class correlation. Request/response tracking currently relies on
metadata["request_id"]/metadata["response_to"]conventions. These are moving to dedicated, typed fields onMessageitself.Typed payloads.
content(a raw string) is evolving into a structured payload that can carry strings, dicts, or lists natively.DID-based addressing.
sender_idandreceiver_idare moving from plain agent IDs to Decentralized Identifiers (DIDs) as the canonical address form.Ergonomic reply helpers. The API will gain convenience methods (e.g.,
message.reply(...)) so agents can construct responses without manually mirroring routing fields.
Current patterns remain usable but expect a migration when the new model ships. See Agent Identity for the parallel identity changes.
Message is the single envelope for all agent communication in AgentConnect - text, task delegation, errors, and control signals all travel as a Message. It carries the payload, routing addresses, a type that tells the hub and agents how to handle it, and a signature the hub verifies before delivery.
You rarely construct a Message directly. Inside a BaseAgent subclass, send_message() handles creation and signing. When building a custom response, use Message.create().
Creating a Message¶
The most common pattern is constructing a reply inside process_message():
from agentconnect.core.message import Message
from agentconnect.core.types import MessageType
async def process_message(self, message: Message) -> Message | None:
base = await super().process_message(message)
if base:
return base
return Message.create(
sender_id=self.agent_id,
receiver_id=message.sender_id,
content="Task complete.",
sender_identity=self.identity,
message_type=MessageType.COLLABORATION_RESPONSE,
metadata={"response_to": message.metadata.get("request_id")},
)
For fire-and-forget or multi-step sends, use send_message(). It calls Message.create() internally using self.identity:
await self.send_message(
receiver_id="analyst",
content="Run Q4 revenue analysis.",
message_type=MessageType.REQUEST_COLLABORATION,
metadata={"priority": "high"},
)
See BaseAgent for the full set of patterns including multi-message replies and correlation.
Signing is automatic
Every Message is signed at creation. The hub verifies the signature before delivery. No per-agent security code required. See Agent Identity for how agent keys work.
MessageType Reference¶
The type controls how the hub routes the message and what the receiving agent is expected to do.
Branch on message.message_type inside process_message().
Normal Flow
Type |
When sending |
When receiving |
|---|---|---|
|
Free-form exchange. The default. Use for conversational messages or status updates that do not need request/response tracking. |
Process |
|
Imperative instruction. Semantic signal only — no built-in enforcement. |
Execute the instruction from |
|
Reply to a prior |
Consume the result. Match to your pending request via |
Collaboration
Type |
When sending |
When receiving |
|---|---|---|
|
Delegate a task to another agent. The hub auto-appends sender to |
Execute the task. Reply with |
|
Reply to a delegation. Always include |
Result is in |
|
Delegation failed completely. Include a description in |
Log the failure. Retry with a different agent, fall back, or escalate. |
Control Signals
Type |
When sending |
When receiving |
|---|---|---|
|
End a conversation cleanly. Also triggered when the sender includes |
|
|
Return from |
Not receivable from a well-behaved agent; consumed before delivery. |
|
Auto-produced by |
Back off. Read |
|
Do not send from application code. Hub-internal only. Bypasses identity verification and signature checking. |
May appear in |
Note
VERIFICATION, CAPABILITY, and PROTOCOL are reserved for internal framework handshaking. Do not send them from application code; they may appear in message history.
Metadata Conventions¶
message.metadata is an open dict. The framework reads and writes specific keys; anything else is passed through untouched.
Key |
Set by / meaning |
|---|---|
|
Hub — identifies an outbound request for correlation |
|
Agent — points to the |
|
Hub — ordered list of agent IDs that have handled this request across hops |
|
Hub — first agent that initiated the chain; preserved across hops |
|
BaseAgent — seconds until the rate-limited agent is available again |
|
BaseAgent — |
|
BaseAgent — the true type ( |
Any other keys you add are your own — use them for priority flags, thread IDs, payment context, or application-specific data.
Next Steps¶
Agent Identity — how agent keys and DIDs power the signing behind every message
Communication Hub (Local) — how the hub uses
MessageTypeand metadata during routing and deliveryBaseAgent — full guide to building agents that send and receive messages
Agent Toolbox: Discover, Delegate, Track — end-to-end A2A patterns built on
REQUEST_COLLABORATION