feature: add swarm mode for multi-instance collaboration#117
feature: add swarm mode for multi-instance collaboration#117Zhaoyikaiii wants to merge 3 commits intosipeed:mainfrom
Conversation
Introduce a NATS-based swarm system that allows multiple PicoClaw instances to discover each other, distribute tasks by capability, and coordinate work through a coordinator/worker architecture. - Add pkg/swarm/ with 9 source files: types, nats bridge, embedded NATS server, discovery, coordinator, worker, temporal client, workflows, and manager - Add SwarmConfig to pkg/config with NATS and Temporal settings - Add `picoclaw swarm` CLI subcommands (start/status/nodes) - Add 8 test files with 32 tests and 83+ subtests (all passing) - Add swarm feature discussion document
3962d21 to
6fb2833
Compare
|
I want multiple picoclaw nodes to coordinate their work, divided into:
|
We are adhering to a minimalist implementation to ensure the swarm remains lightweight. The goal is to prove the coordination mechanism works—specifically via NATS—while leaving advanced features like dynamic load balancing or LLM-driven decomposition for subsequent iterations. |
|
Why no libp2p to do that? I was implementing it using libp2p. What do you guys think? |
- Fix race condition in worker.go using atomic operations for tasksRunning - Fix memory leak in discovery.go by GC long-dead nodes (10x timeout) - Add SwarmConfig.Validate() for configuration validation - Add input validation in handleNodeJoin to prevent nil/invalid nodes - Fix log level: discovery query failure now uses Warn instead of Debug - Update tests to match new behavior Fixes issues from review: 1. Race condition - worker.go:108 2. Memory leak - discovery.go:220 3. Config validation missing 4. Input validation missing
Resolved conflicts in: - cmd/picoclaw/main.go: kept both 'state' and 'swarm' imports - go.mod: merged dependencies (added github copilot sdk, kept temporal mocks) - go.sum: regenerated via go mod tidy - pkg/config/config.go: kept both 'Devices' and 'Swarm' config fields This merge brings in upstream changes including: - LINE channel support - OneBot channel support - GitHub Copilot provider - Device monitoring service - Hardware tools (I2C, SPI) - New workspace file structure Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@Zepan This PR addresses roadmap issue #284 (Swarm Mode — priority: medium, status: Todo). At +5473 lines, it's the largest open PR. Important consideration: The roadmap defines a clear dependency chain: #294 (Base Multi-agent Framework) should land first, then #295 (Model Routing), and finally #284 (Swarm Mode). Swarm Mode builds on top of the multi-agent foundation. PR #131 currently addresses #294 (base multi-agent framework). It would be cleaner to merge #131 first, then evolve this PR to build on that foundation rather than implementing everything from scratch. Recommendation: Defer until #294 (multi-agent base) is merged. The scope (+5473 lines) is very large and would benefit from being built on top of the base framework rather than as a standalone implementation. |
Summary
pkg/swarm/— a NATS-based multi-instance collaboration system that lets multiple PicoClaw nodes discover each other, distribute tasks by capability, and coordinate work through a coordinator/worker architectureSwarmConfiginpkg/config/with NATS and optional Temporal settings, pluspicoclaw swarmCLI subcommands (start,status,nodes)Architecture
What's in the box
types.gonats.goembedded.godiscovery.gocoordinator.goworker.gotemporal.goworkflows.gomanager.goCovers: type serialization, embedded NATS lifecycle, pub/sub mechanics, discovery registry, coordinator dispatch (direct + local fallback + timeout), worker execution, and full coordinator↔worker integration round-trips.