Message Types
Any Python object can be a message. Common patterns:Dataclass Messages
Pydantic Models
MessageContext
Every message handler receives aMessageContext with metadata about the message:
Using MessageContext
MessageHandlerContext
MessageHandlerContext provides access to the current agent’s ID from within a message handler:
Topics and Publishing
TopicId
TopicId identifies a publish-subscribe topic:
string
required
Event type following CloudEvents spec. Must match pattern:
^[\w\-\.\:\=]+$Examples: task.completed, user.login, system.errorstring
required
Context where the event happened. Can be any string.Examples:
worker-1, api-gateway, user-123DefaultTopicId
DefaultTopicId is a predefined topic for simple pub-sub:
Publishing Messages
From an agent:Subscriptions
Subscriptions define which agents receive messages published to topics.Subscription Protocol
TypeSubscription
TypeSubscription matches topics by type and creates agent instances per source:
TypeSubscription creates separate agent instances for each source. Use when you want per-source state isolation.DefaultSubscription
DefaultSubscription subscribes an agent to the default topic:
TypePrefixSubscription
TypePrefixSubscription matches topics by type prefix (internal use):
TypePrefixSubscription is mainly used internally for direct message routing. For application-level subscriptions, use TypeSubscription or DefaultSubscription.Subscription Decorators
Message Routing Patterns
Pattern 1: Direct RPC
Pattern 2: Broadcast Events
Pattern 3: Per-Source Routing
Cancellation
Checking Cancellation in Handler
Message Serialization
Messages must be serializable for distributed runtime:Custom Serializer
Known Serializers
Complete Example
Next Steps
Event-Driven Architecture
Learn about event handlers and message routing
Distributed Runtime
Scale message passing across processes
Agent Runtime
Understand runtime operations
Core Overview
Return to Core API overview