I built a 17-agent AI swarm on my phone — here's how
Okay, buckle up. This isn’t your average “hello world” project. I’ve spent the last few weeks obsessed with something pretty wild: running a swarm of 17 independent AI agents, all coordinating on my phone. And not just running, but actually communicating and working towards a defined goal.
It sounds like science fiction, and honestly, it feels a little bit like it. But it's entirely possible with some clever tooling, a little bit of Python, and a surprisingly robust phone. Here's a breakdown of how I did it, the challenges I faced, and what I learned.
The Goal: Decentralized Information Gathering & Synthesis
I wanted to see if I could create a system that could autonomously gather information on a complex topic – let’s say, the current state of research on synthetic biology – and synthesize that information into a coherent summary. The key was to not rely on a single, monolithic AI model. Instead, I envisioned a swarm of specialized agents, each responsible for a specific task, communicating with each other to achieve a larger goal.
The Tech Stack: A Surprisingly Mobile-Friendly Combination
The biggest hurdle wasn’t the AI itself, but the environment. Running 17 agents requires processing power and ideally, a decent amount of RAM. My phone is a mid-range Android, not a supercomputer. Here’s what I ended up using:
- Python: The backbone. I’m most comfortable with Python for prototyping and AI work.
- LangChain: This was critical. LangChain provides the framework for building applications powered by language models, and its agent tooling made the orchestration manageable.
-
Ollama: This is the hero of the story. Ollama allows you to run large language models locally, even on resource-constrained devices. I chose smaller models like
mistralandllama2to ensure reasonable performance on my phone. (More on model selection later.) - Termux: This is the Android terminal emulator. It provides a Linux-like environment where I could install Python and all the necessary dependencies.
- SQLite: For persistent storage of agent memory and communication logs.
- A whole lot of patience.
Building the Agents: Specialization is Key
Each agent has a specific role. Here's a simplified overview of my 17 agents:
-
3 x Web Scrapers: These agents use
requestsandBeautifulSoup(via LangChain tools) to fetch content from relevant websites (ArXiv, Nature, scientific journals). - 2 x Summarizers: These agents take the scraped text and generate concise summaries using the LLM.
- 2 x Keyword Extractors: They identify key themes and concepts from the summaries.
- 2 x Contextualizers: These agents take the keywords and summaries and search for related information to provide context.
- 3 x Researchers: These agents are tasked with looking for contradictory information or gaps in the existing knowledge base.
- 2 x Fact Checkers: Using tools like SerpAPI, they attempt to verify information from multiple sources.
- 2 x Synthesis Agents: These agents are the core – they take the output from all the other agents and attempt to synthesize a coherent summary report.
- 1 x Report Generator: This agent formats the final synthesized report in a human-readable format.
Code Snippet: A Simple Agent Definition
Here's a snippet of how I defined one of the Summarizer agents using LangChain:
from langchain.agents import initialize_agent, AgentType
from langchain.llms import Ollama
from langchain.tools import Tool
# Initialize the LLM
llm = Ollama(model='mistral', temperature=0.7) # Smaller model for phone
# Define a tool for summarizing text
def summarize_text(text):
"""Summarizes the provided text using the LLM."""
return llm(f"Summarize the following text:\n{text}")
summarize_tool = Tool(
name="Summarizer",
func=summarize_text,
description="Useful for summarizing long passages of text."
)
# Initialize the agent
agent = initialize_agent([summarize_tool],
llm,
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
verbose=True)
Communication & Orchestration: The Heart of the Swarm
The real magic happens in how these agents communicate. I used a combination of:
- LangChain’s Agent Executor: This handles the looping and decision-making process for each agent.
- SQLite Database: This is where agents store their working memory, intermediate results, and communication logs. Agents can query the database to see what others have found.
- Simple Text-Based Messaging: Agents “talk” to each other by writing messages to specific tables in the SQLite database. For example, a Web Scraper might write a message: "Found article: [URL] - Summary: [Short Summary]" to the 'articles' table. A Summarizer then reads the 'articles' table for new entries.
This system is admittedly rudimentary, but it's surprisingly effective.
Challenges and Optimizations: Squeezing Performance Out of a Phone
Running 17 agents on a phone wasn’t without its hurdles:
-
Model Size: Large language models are…large. I had to experiment with different models available through Ollama.
mistralandllama2performed best, but even then, inference times could be slow. I found reducing themax_tokensparameter in the LLM configuration helped significantly. - RAM Management: My phone has limited RAM. I implemented a system to periodically clear agent memory (data from the SQLite database) that wasn't actively being used.
- Battery Drain: This is a huge issue. Running multiple LLMs constantly drains the battery incredibly quickly. I had to run the swarm in controlled bursts and optimize the communication frequency to minimize activity.
- Termux limitations: Termux is powerful, but it's not a full-fledged Linux distribution. Getting certain dependencies installed could be tricky.
- Agent "Hallucinations": Even with fact-checking agents, LLMs can still generate inaccurate or misleading information. Constant monitoring and refining of agent prompts are crucial.
The Results: A Surprisingly Coherent Summary
After about 3 hours of running on my phone, the swarm produced a surprisingly coherent summary report on the state of synthetic biology research. It identified key trends, highlighted ongoing debates, and even pointed out potential ethical concerns.
While the report wasn't perfect (it still required human review), it demonstrated the potential of this decentralized approach. The individual agents, while limited in their capabilities, collectively produced a more nuanced and comprehensive summary than I could have expected from a single LLM.
**
Top comments (0)