The distributed runtime implements the same
AgentRuntime protocol as SingleThreadedAgentRuntime, making it easy to scale from development to production.Architecture Overview
The distributed runtime uses a message broker to route messages between agent instances running in different processes or on different machines. Key features:- Process isolation: Agents run in separate processes for fault tolerance
- Horizontal scaling: Add more agent instances to handle load
- Cross-language: Python agents can communicate with .NET agents
- Location transparency: Agents don’t know or care where other agents are running
Core Concepts
Message Broker
The distributed runtime uses a message broker (like gRPC, Redis, or RabbitMQ) to route messages between agent processes.Agent Registration
Each agent process registers its agent types and subscriptions with the runtime. The runtime coordinates with the broker to route messages correctly.Serialization
Messages are serialized when sent across process boundaries. AutoGen Core supports JSON and Protocol Buffers.Setting Up Distributed Runtime
The exact distributed runtime implementation may vary based on your deployment. This section covers general patterns. Refer to the AutoGen distributed runtime documentation for specific implementation details.
Example: Multi-Process Setup
Process 1: Worker Agent
Process 2: Coordinator Agent
Cross-Language Communication
The distributed runtime supports agents written in different languages communicating through the message broker.Python to .NET Example
Python Agent
C# (.NET) Agent
Message types must be compatible across languages. Use simple types (strings, numbers, lists, dictionaries) or shared Protocol Buffer definitions.
Message Serialization
Custom Serializers for Distributed Runtime
Protocol Buffers
For efficient binary serialization:Fault Tolerance
Agent Restart Handling
Agents in different processes can fail and restart independently:Timeout Handling
Distributed Subscriptions
Subscriptions work the same in distributed runtime:Load Balancing
Multiple Worker Instances
The distributed runtime can load-balance messages across multiple instances of the same agent type running in different processes.
Monitoring and Observability
OpenTelemetry Integration
Best Practices
Design for failure
Design for failure
Assume agents can fail and restart. Use state persistence and idempotent message handlers.
Use timeouts
Use timeouts
Always use timeouts for cross-process RPC calls to prevent indefinite blocking.
Version messages
Version messages
Include version information in message serialization to support rolling updates.
Monitor message queues
Monitor message queues
Track message queue depths and processing latencies to detect bottlenecks.
Keep messages small
Keep messages small
Large messages increase serialization overhead and network latency. Pass references instead of large data.
Use Protocol Buffers for performance
Use Protocol Buffers for performance
For high-throughput scenarios, Protocol Buffers provide better performance than JSON.
Deployment Patterns
Docker Compose Example
Kubernetes Example
Limitations and Considerations
Next Steps
Core Overview
Return to Core API overview
Agent Runtime
Learn about runtime operations
Message Passing
Understand message contexts and subscriptions
Event-Driven Architecture
Master event handlers and routing