Overview
This example demonstrates a complete multi-agent system built on MoFA’s microkernel architecture. It showcases:- Master-worker coordination pattern
- LLM-powered intelligent task assignment
- Worker agents with different specialties (Analyst, Coder, Writer)
- Runtime agent registration and lifecycle management
- Message bus communication between agents
- Real-time workload balancing
What You’ll Learn
- Implementing
MoFAAgenttrait for custom agents - Using
SimpleRuntimefor agent lifecycle management - LLM-based decision making for task routing
- Agent capability matching and workload optimization
- Message bus pattern for inter-agent communication
Prerequisites
- Rust 1.75 or higher
- OpenAI API key
- Understanding of async patterns and message passing
Architecture
Source Code
Running the Example
Demo Scenarios
- Code Review
- Documentation
- Diagnosis
Scenario: Analyze code for security and performance issuesMaster: Assigns to Analyst worker based on capabilitiesAnalyst: Reviews code and provides detailed feedback
Expected Output
Key Concepts
Master-Worker Pattern
The Master Agent:- Receives task requests
- Analyzes worker capabilities and load
- Uses LLM to make intelligent routing decisions
- Tracks task completion and worker statistics
- Specialize in specific domains
- Process assigned tasks using LLM
- Report status back to master
- Maintain performance metrics
LLM-Based Task Routing
Runtime Management
Advanced Features
Dynamic Worker Registration
Dynamic Worker Registration
Workers can be added/removed at runtime:
Load Balancing
Load Balancing
Master tracks and balances workload:
Priority Queuing
Priority Queuing
Tasks are prioritized:
Performance Tracking
Performance Tracking
Each worker maintains metrics:
Common Use Cases
Code Analysis
Distribute code review across specialized agents
Content Pipeline
Research → Writing → Editing workflow
Customer Support
Route tickets to specialized support agents
Data Processing
Parallel data transformation and analysis
Troubleshooting
Worker Overload
Worker Overload
Problem: All tasks go to one workerSolution: Improve LLM prompt or add load balancing:
Task Timeout
Task Timeout
Problem: Tasks take too longSolution: Add timeout and retry logic:
Communication Failure
Communication Failure
Problem: Messages not reaching agentsSolution: Check runtime registration:
Next Steps
Secretary Agent
Add human-in-the-loop workflows
Workflow Orchestration
Build complex multi-stage workflows
Coordination Guide
Learn all coordination patterns
Runtime API
Runtime system reference