Architecture - micgo/maf-standalone GitHub Wiki

Architecture Overview

The Multi-Agent Framework uses a sophisticated event-driven architecture to coordinate multiple AI agents working collaboratively on software development tasks.

Table of Contents

Core Concepts

Multi-Agent System

MAF orchestrates specialized AI agents, each with specific expertise:

  • Each agent focuses on a specific domain (frontend, backend, database, etc.)
  • Agents work independently but coordinate through events
  • The orchestrator agent manages task distribution and workflow

Event-Driven Architecture

  • Agents communicate asynchronously via events
  • Events carry task assignments, completions, and updates
  • Loose coupling allows agents to work in parallel

Intelligent Integration

  • Smart file placement reduces code duplication
  • Cross-agent validation ensures compatibility
  • Automatic conflict resolution

System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        User Interface                        β”‚
β”‚                    (CLI / API / WebUI)                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Orchestrator Agent                        β”‚
β”‚              (Task Planning & Distribution)                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Event Bus System                        β”‚
β”‚                  (Publish / Subscribe)                       β”‚
β””β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
   β”‚    β”‚    β”‚    β”‚    β”‚    β”‚    β”‚    β”‚    β”‚
β”Œβ”€β”€β–Όβ”€β”β”Œβ”€β–Όβ”€β”β”Œβ”€β–Όβ”€β”β”Œβ”€β–Όβ”€β”β”Œβ”€β–Όβ”€β”β”Œβ”€β–Όβ”€β”β”Œβ”€β–Όβ”€β”β”Œβ”€β–Όβ”€β”β”Œβ”€β–Όβ”€β”€β”
β”‚FE  β”‚β”‚BE β”‚β”‚DB β”‚β”‚QA β”‚β”‚Secβ”‚β”‚Devβ”‚β”‚Docβ”‚β”‚UX β”‚β”‚... β”‚
β”‚Agt β”‚β”‚Agtβ”‚β”‚Agtβ”‚β”‚Agtβ”‚β”‚Agtβ”‚β”‚Opsβ”‚β”‚Agtβ”‚β”‚UI β”‚β”‚    β”‚
β””β”€β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”˜β””β”€β”€β”€β”€β”˜
   β”‚    β”‚    β”‚    β”‚    β”‚    β”‚    β”‚    β”‚    β”‚
β”Œβ”€β”€β–Όβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    File Integration Layer                    β”‚
β”‚                 (Smart Code Consolidation)                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Component Descriptions

CLI/API Layer

  • Handles user interactions
  • Triggers framework operations
  • Displays progress and results

Orchestrator Agent

  • Breaks down high-level requests into tasks
  • Assigns tasks to appropriate agents
  • Monitors progress and handles failures
  • Ensures task dependencies are met

Event Bus

  • Central communication hub
  • Supports both in-memory and Kafka backends
  • Handles event routing and delivery
  • Maintains event history for debugging

Specialized Agents

  • Frontend (FE): UI components, styling, user interactions
  • Backend (BE): API endpoints, business logic, integrations
  • Database (DB): Schema design, queries, migrations
  • QA: Testing, code review, quality assurance
  • Security (Sec): Vulnerability scanning, security implementations
  • DevOps: CI/CD, Docker, deployment configurations
  • Documentation (Doc): API docs, READMEs, guides
  • UX/UI: Design systems, mockups, accessibility
  • Each agent:
    • Receives tasks via events
    • Processes tasks using configured LLMs
    • Publishes results back to event bus
    • Handles domain-specific logic

File Integration Layer

  • Consolidates agent outputs
  • Prevents file conflicts
  • Maintains code quality
  • Handles merge operations

Agent Communication

Event Types

class EventType(Enum):
    TASK_CREATED = "task_created"
    TASK_ASSIGNED = "task_assigned" 
    TASK_STARTED = "task_started"
    TASK_COMPLETED = "task_completed"
    TASK_FAILED = "task_failed"
    CODE_GENERATED = "code_generated"
    REVIEW_REQUESTED = "review_requested"
    INTEGRATION_NEEDED = "integration_needed"

Message Format

{
  "event_type": "task_created",
  "source_agent": "orchestrator",
  "target_agent": "frontend_agent",
  "timestamp": "2024-01-01T12:00:00Z",
  "task_id": "task_123",
  "payload": {
    "task_description": "Create user login form",
    "requirements": [...],
    "dependencies": [...]
  }
}

Communication Flow

  1. Task Creation

    • User triggers a feature request
    • Orchestrator creates and publishes tasks
  2. Task Assignment

    • Agents subscribe to relevant events
    • Tasks are claimed by appropriate agents
  3. Task Execution

    • Agents process tasks independently
    • Progress updates published to event bus
  4. Result Integration

    • Completed code published as events
    • Integration layer consolidates outputs

Event-Driven Design

Benefits

  1. Scalability

    • Agents work in parallel
    • Easy to add/remove agents
    • No bottlenecks from synchronous calls
  2. Resilience

    • Failed tasks can be retried
    • System continues despite agent failures
    • Event history enables recovery
  3. Flexibility

    • Loose coupling between agents
    • Easy to modify agent behavior
    • Support for different LLM providers

Event Bus Implementation

# Simplified event bus interface
class EventBus:
    async def publish(self, event: Event) -> None:
        """Publish event to all subscribers"""
        
    async def subscribe(self, event_types: List[EventType], 
                       callback: Callable) -> None:
        """Subscribe to specific event types"""
        
    async def get_history(self, filters: Dict) -> List[Event]:
        """Retrieve event history"""

File Integration

Smart Integration Process

  1. Analysis Phase

    • Detect file types and structure
    • Identify integration points
    • Check for conflicts
  2. Merge Strategy

    • Import consolidation
    • Function deduplication
    • Style normalization
  3. Validation

    • Syntax checking
    • Import verification
    • Test compatibility

Example Integration

# Agent 1 output
def login_user(username, password):
    # Basic implementation
    pass

# Agent 2 output  
def login_user(username, password):
    # Enhanced implementation
    pass

# Integrated result
def login_user(username: str, password: str) -> Dict[str, Any]:
    """
    Unified login function combining both implementations
    """
    # Best of both implementations
    pass

State Management

Framework State

{
  "project_info": {
    "name": "my-app",
    "type": "nextjs",
    "root_path": "/path/to/project"
  },
  "active_tasks": {
    "task_123": {
      "status": "in_progress",
      "assigned_to": "frontend_agent",
      "started_at": "2024-01-01T12:00:00Z"
    }
  },
  "agent_states": {
    "frontend_agent": "active",
    "backend_agent": "idle"
  }
}

Persistence

  • State saved to .maf/state.json
  • Event history in .maf/message_queues/
  • Logs in .maf_logs/

Extensibility

Adding Custom Agents

  1. Create Agent Class
from multi_agent_framework.agents import EventDrivenBaseAgent

class CustomAgent(EventDrivenBaseAgent):
    def __init__(self, config):
        super().__init__("custom_agent", config)
        
    async def process_task(self, task):
        # Custom processing logic
        pass
  1. Register Agent
# In agent factory
agent_registry["custom_agent"] = CustomAgent
  1. Configure in Project
{
  "enabled_agents": ["orchestrator", "custom_agent"]
}

Custom Event Types

# Define new event type
class CustomEventType(Enum):
    CUSTOM_ACTION = "custom_action"

# Use in agent
await self.event_bus.publish(Event(
    event_type=CustomEventType.CUSTOM_ACTION,
    payload={"data": "value"}
))

Performance Considerations

Optimization Strategies

  • Event batching for high-throughput scenarios
  • Caching of frequently accessed data
  • Parallel task processing
  • Efficient file I/O operations

Monitoring

  • Event processing metrics
  • Agent response times
  • Task completion rates
  • Resource utilization

Security

API Key Management

  • Keys stored in environment variables
  • Never logged or transmitted
  • Per-agent key configuration

Code Validation

  • Generated code scanned for issues
  • Dependency verification
  • Security best practices enforced

Next Steps