Skip to content

Async Actor-Model Architecture for Swarm Agents #58

@galic1987

Description

@galic1987

Summary

Refactor the multi-agent swarm to use a strict actor-model architecture with message-passing for complex asynchronous negotiations between specialized agents.

Problem

The current swarm implementation dispatches tasks to agents but lacks structured inter-agent communication. Agents can't negotiate, argue, or collaborate in real-time — for example, a "Cargo Test" agent can't communicate lifetime error context back to a "Code Writer" agent mid-task.

Proposal

Implement an actor-model architecture using message-passing (via tokio::sync::mpsc channels or an actor framework like actix) that enables:

  • Inter-agent messaging: Agents send typed messages to each other (e.g., CompileError, ReviewFeedback, ArchitectureProposal)
  • Negotiation protocols: Structured back-and-forth between agents to resolve conflicts (e.g., Tester reports failing test → Coder proposes fix → Reviewer evaluates → consensus)
  • Supervision trees: Parent agents supervise children, restart failed agents, escalate unresolvable conflicts
  • Backpressure: Slow agents don't block the swarm; mailboxes buffer messages with configurable limits
  • Observable state: Each agent's mailbox and state is visible in the swarm visualization

Implementation Ideas

  • Define AgentMessage enum with variants for each interaction type
  • Each agent gets an AgentMailbox (tokio mpsc sender/receiver pair)
  • SwarmSupervisor routes messages and monitors agent health
  • Implement negotiation as a state machine: Propose → Counter → Accept/Reject
  • Use the existing SwarmDispatchTool as the entry point, extend with message routing
  • Integrate with src/ui/swarm_viz.rs to show message flow in real-time

Example Agent Interaction

Architect → Coder: "Implement UserService with these 4 methods"
Coder → Tester: "UserService ready at src/user.rs, please write tests"
Tester → Coder: "test_create_user fails: lifetime error on line 42"
Coder → Tester: "Fixed, retry"
Tester → Reviewer: "All 8 tests pass, ready for review"
Reviewer → Architect: "Approved with minor style suggestions"
Architect → Supervisor: "Task complete, 4/4 methods implemented and tested"

Relevant Code

  • src/tools/swarm_tool.rs — current swarm dispatch
  • src/orchestration/ — multi-agent orchestration
  • src/ui/swarm_viz.rs — swarm visualization (would show message flow)
  • src/supervision/ — existing circuit breaker and health monitoring

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions