Message Hub
Message Hub provides reliable communication between agents. It supports both direct messaging and queue-based pub/sub patterns.
Key Features
Section titled “Key Features”- Guaranteed delivery - At-least-once, at-most-once, or exactly-once semantics
- Message persistence - Messages are stored until acknowledged
- Dead letter queues - Failed messages are preserved for debugging
- Turn-based conversations - Built-in support for structured dialogues
- Rate limiting - Protect against message floods
Messaging Patterns
Section titled “Messaging Patterns”Direct Messaging
Section titled “Direct Messaging”Send messages directly to a specific agent:
await client.messaging.send( destination="agent-b", event_name="process_document", payload={"document_id": "doc-123"})Queue-Based Messaging
Section titled “Queue-Based Messaging”Publish to a topic that multiple agents can subscribe to:
# Publisherawait client.messaging.publish( topic="documents.new", payload={"document_id": "doc-123"})
# Subscriberasync for message in client.messaging.subscribe_topic(topic="documents.new"): print(f"New document: {message.payload}")Sessions and Threads
Section titled “Sessions and Threads”Messages can be organized into sessions and threads:
- Session: A high-level conversation context
- Thread: A specific topic within a session
# Create a sessionsession = await client.messaging.create_session( name="Customer Support Case #123")
# Create a thread within the sessionthread = await client.messaging.create_thread( session_id=session.id, name="Initial Inquiry")
# Send messages in the threadawait client.messaging.send( destination="support-agent", thread_id=thread.id, event_name="inquiry", payload={"question": "How do I reset my password?"})Turn-Based Conversations
Section titled “Turn-Based Conversations”For structured dialogues, use turn mode:
# Create a thread with turn-taking enabledthread = await client.messaging.create_thread( session_id=session.id, mode="turn", turn_timeout_seconds=300 # 5 minute timeout)
# Only the agent whose turn it is can send messages# Turns automatically advance after each messageDelivery Semantics
Section titled “Delivery Semantics”Choose the appropriate delivery guarantee:
| Semantic | Description | Use Case |
|---|---|---|
at_least_once | Message delivered one or more times | Most common, idempotent operations |
at_most_once | Message delivered zero or one time | Non-critical notifications |
exactly_once | Message delivered exactly once | Financial transactions |
await client.messaging.send( destination="agent-b", event_name="transfer_funds", payload={"amount": 100}, delivery_semantic="exactly_once")Message Lifecycle
Section titled “Message Lifecycle”- Sent - Message accepted by Message Hub
- Pending - Waiting for delivery to recipient
- Delivered - Delivered to recipient’s queue
- Acknowledged - Recipient confirmed processing
- Dead Letter - Failed after max retries
Rate Limiting
Section titled “Rate Limiting”Message Hub enforces rate limits to protect the system:
- Per-agent limits - Max messages per second per agent
- Global limits - Total messages per namespace
Check rate limit status:
status = await client.messaging.rate_limit_status(agent_id="my-agent")print(f"Remaining: {status.remaining}/{status.limit}")Next Steps
Section titled “Next Steps”- Messaging Patterns Guide - Learn advanced patterns
- API Reference - Complete API documentation