I built a 17-agent AI swarm on my phone — here's how
Description and use
A 17‑agent AI swarm runs entirely on a Pixel 6 phone, achieving near real‑time reporting through threading, NumPy, and code optimizations.
Problem
Running a distributed, multi‑agent AI system entirely on a mobile device without cloud offloading.
Outcome
The swarm runs smoothly on a Pixel 6, with agents reporting in near real‑time and a responsive UI, proving complex on‑device AI is achievable with careful optimization.
Workflow
- Define Agent base class and Coordinator class
- Implement 17 agent subclasses (e.g., SpikeDetectorAgent, TrendDetectorAgent)
- Simulate sensor data stream
- Use threading instead of multiprocessing to run agents
- Replace Python lists with NumPy arrays for speed
- Profile with cProfile and optimize string formatting
- Simplify agent algorithms to reduce computation
- Tune BeeWare build with compiler flags
- Collect reports in Coordinator and generate summary
- Display summary via BeeWare Toga UI
Evidence
I initially tried using multiprocessing to run each agent in a separate process. While theoretically good for CPU‑bound tasks, the overhead of inter‑process communication was massive on the phone.
Threading instead of multiprocessing drastically improved performance.
NumPy arrays became my best friend. While Python lists are convenient, NumPy arrays are significantly faster for numerical operations.
- Record date: 2026-10-11T21:41:02.291Z