picoclaw/pkg/swarm
Danieldd28 52e3470e06 feat: implement swarm agents with hierarchical collaboration and vector memory
This commit introduces a multi-agent Swarm Engine to PicoClaw,
enabling complex task orchestration through autonomous collaboration and long-term
semantic memory.

Key Features:
- Actor Model Architecture: Every agent (node) runs in an isolated goroutine,
  communicating via a lightweight internal Event Bus.
- Hierarchical Delegation: Manager nodes can dynamically spawn specialized
  worker nodes (Researchers, Analysts, etc.) to perform sub-tasks in parallel.
- Hybrid Memory System: Combined SQLite for state persistence and Chromem-go
  for a persistent, cross-swarm Vector Knowledge Base.
- Progressive Summarization: Implemented an intelligent memory pruning mechanism
  that summarizes older context before truncation to preserve findings without
  exceeding token limits.
- Role-Based Access Control (RBAC): Configurable tool policies per role
  (e.g., Researchers can browse but not execute shell commands).

Performance & Scaling:
- Low Footprint: Idle memory usage is ~7-8 MB RSS.
- Efficient Scaling: During a stress test with 10 concurrent agents performing
  intensive research, memory usage peaked at only 27 MB.
- Per-Node Cost: Each active agent consumes approximately 0.6 MB to 2 MB of
  physical RAM depending on conversation length and summarization state.
- Stability: Successfully handled 10 parallel LLM requests with zero race
  conditions, showcasing the robustness of the Go-based Actor model.

Integration:
- Native CLI Support: Added /swarm spawn, /swarm list, and /swarm status commands.
- Mermaid Visualization: Support for /swarm viz <id> to generate organizational
  charts of active agent hierarchies.
- Configurable: Roles, models, and security policies are fully customizable
  via config.json.
2026-02-10 21:53:43 +07:00
..
adapters feat: implement swarm agents with hierarchical collaboration and vector memory 2026-02-10 21:53:43 +07:00
bus feat: implement swarm agents with hierarchical collaboration and vector memory 2026-02-10 21:53:43 +07:00
config feat: implement swarm agents with hierarchical collaboration and vector memory 2026-02-10 21:53:43 +07:00
core feat: implement swarm agents with hierarchical collaboration and vector memory 2026-02-10 21:53:43 +07:00
memory feat: implement swarm agents with hierarchical collaboration and vector memory 2026-02-10 21:53:43 +07:00
prompt feat: implement swarm agents with hierarchical collaboration and vector memory 2026-02-10 21:53:43 +07:00
runtime feat: implement swarm agents with hierarchical collaboration and vector memory 2026-02-10 21:53:43 +07:00
README.md feat: implement swarm agents with hierarchical collaboration and vector memory 2026-02-10 21:53:43 +07:00
service.go feat: implement swarm agents with hierarchical collaboration and vector memory 2026-02-10 21:53:43 +07:00

PicoClaw Swarm Engine

This package implements the Swarm Agents architecture: a lightweight, hierarchical, multi-agent system designed for the edge.

For a detailed deep-dive into the architecture, workflow, and components, please read SWARM_ARCHITECTURE.md.

Features

  • Hierarchical Swarms: Manager nodes can delegate tasks to specialized workers (Researchers, Writers, etc.).
  • Vector Memory: Integrated Chromem-go vector database for long-term semantic memory.
  • Resilient: Built-in retry mechanisms, context pruning, and crash recovery via SQLite checkpoints.
  • Secure: Configurable Role-Based Access Control (RBAC) for tools.
  • Lightweight: Built on Go Goroutines (Actor Model) and Channels, efficient enough for small VPS or local devices.

Usage

The Swarm Engine is integrated into the PicoClaw CLI.

Basic Commands

# Spawn a new swarm to perform a task
/swarm spawn "Analyze the latest trends in Rust vs Go performance"

# List active swarms
/swarm list

# Check detailed status of a specific swarm (including node progress)
/swarm status <swarm_id>

# Visualize the swarm topology (Mermaid diagram)
/swarm viz <swarm_id>

# Stop a running swarm
/swarm stop <swarm_id>

Configuration

You can configure the Swarm behavior, Roles, and Policies in your config.json.

{
  "swarm": {
    "limits": {
      "max_nodes": 10,
      "global_timeout": 600000000000, 
      "max_iterations": 15
    },
    "roles": {
      "Manager": {
        "description": "Orchestrates tasks",
        "system_prompt": "You are a Manager...",
        "tools": ["delegate_task", "save_memory", "search_memory"]
      }
    },
    "policies": [
      {
        "role": "Manager",
        "allowed": ["*"]
      }
    ]
  }
}

Architecture Overview

graph TD
    Service --> Orchestrator
    Orchestrator --> Manager[Manager Node]
    Manager -->|Delegates| Worker[Worker Node]
    Manager <-->|Memory| VectorDB[(Vector DB)]
    Manager <-->|State| SQLite[(SQLite)]