Skip to main content

Multi-agent coordination through stigmergy - agents coordinate via environmental traces, not explicit messaging

Project description

Anthills ๐Ÿœ

Stigmergy-based AI agent orchestration. Agents coordinate through a shared environment โ€” not a central planner.

PyPI version License: MIT Python 3.11+


What is Anthills?

Most agent frameworks orchestrate through a central controller โ€” a graph, a DAG, a router that decides who does what next.

Anthills is different. It borrows from nature.

In an ant colony, no single ant knows the plan. Instead, ants deposit pheromones โ€” signals in the environment โ€” and other ants respond to those signals. Complex, adaptive behavior emerges from simple local rules. No orchestrator required.

Anthills brings this model to AI agents:

  • Agents read from and write to a shared Pheromone Board โ€” a persistent, observable environment
  • Coordination is emergent, not prescribed
  • Any agent can react to any signal โ€” enabling flexible, parallel, self-organizing workflows
  • The full history of signals is captured as a ledger โ€” making agent behavior auditable and replayable

Core Concepts

Concept Description
Pheromone Board The shared environment all agents read from and write to
Pheromone A signal deposited by an agent โ€” carries type, intensity, payload, and TTL
Worker An agent that reacts to pheromones and may deposit new ones
Trail A sequence of pheromone deposits that form an emergent task path
Colony A named group of workers sharing a pheromone board
Ledger Append-only log of all pheromone events โ€” the source of truth for tracing

Installation

pip install anthills

For Claude integration:

pip install anthills[claude]

Quick Start

from anthills import Colony, Pheromone

# Define a colony (shared environment)
colony = Colony(name="research-pipeline")

# Define workers that react to signals
@colony.worker(reacts_to="task.created")
async def researcher(pheromone, board):
    # Process the pheromone
    result = f"Researched: {pheromone.payload['topic']}"
    # Deposit a new signal for other workers
    board.deposit(Pheromone(
        type="research.complete",
        payload={"findings": result},
        deposited_by="researcher",
    ))

@colony.worker(reacts_to="research.complete")
async def summarizer(pheromone, board):
    summary = f"Summary of: {pheromone.payload['findings']}"
    board.deposit(Pheromone(
        type="summary.ready",
        payload={"summary": summary},
        deposited_by="summarizer",
    ))

# Kick off the colony with an initial signal
colony.deposit(type="task.created", payload={"topic": "quantum computing"})
colony.run()

No graph definition. No router. Workers emerge into action as signals appear.


With Claude (LLM Integration)

from anthills import Colony
from anthills.integrations.claude import ClaudeWorker

colony = Colony(name="research")

@colony.worker(reacts_to="topic.queued")
class Researcher(ClaudeWorker):
    system_prompt = "You are a research assistant."
    output_pheromone_type = "research.complete"

    async def build_messages(self, pheromone):
        return [{"role": "user", "content": f"Summarize: {pheromone.payload['topic']}"}]

colony.deposit(type="topic.queued", payload={"topic": "stigmergy"})
colony.run()

Why Stigmergy?

Traditional agent orchestration is choreography โ€” someone writes the script.

Stigmergy is emergence โ€” the environment carries the coordination logic.

This makes Anthills particularly well-suited for:

  • Long-running, async workflows where tasks arrive unpredictably
  • Parallel multi-agent pipelines where bottlenecks are hard to predict upfront
  • Adaptive systems that need to self-organize around failures or new inputs
  • Observable AI workflows where you need to understand why agents did what they did

Examples

See the examples/ directory:

  • research_agents.py โ€” Multi-agent research pipeline
  • t1d_simulation.py โ€” Type 1 Diabetes pathophysiology model (stigmergy in biology!)

Development

git clone https://github.com/t1dm-ai/anthills
cd anthills
pip install -e ".[dev,claude]"
pytest

Connectors

Connectors provide external tool integrations for your workers:

from anthills import Colony
from anthills.connectors import ConnectorRegistry, requires
from anthills.connectors.gmail import GmailConnector
from anthills.connectors.slack import SlackConnector

# Create registry with configured connectors
registry = ConnectorRegistry()
registry.register(GmailConnector(credentials_path="/path/to/creds.json"))
registry.register(SlackConnector(bot_token="xoxb-..."))

# Create colony with connectors
colony = Colony(name="notifications", connectors=registry)

# Workers declare their connector requirements
@colony.worker(reacts_to="alert.triggered", requires=["gmail", "slack"])
async def notify(ctx):
    gmail = ctx.connectors["gmail"]
    slack = ctx.connectors["slack"]
    
    await gmail.send_email(to="team@example.com", subject="Alert", body="...")
    await slack.send_message(channel="#alerts", text="...")

Built-in Connectors

Connector Install Description
GmailConnector pip install anthills[gmail] Send emails via Gmail API
SlackConnector pip install anthills[slack] Post messages to Slack

Custom Connectors

from anthills.connectors import Connector, ConnectorConfig

class MyConnector(Connector):
    name = "my_service"
    
    async def connect(self) -> None:
        # Initialize connection
        pass
    
    async def disconnect(self) -> None:
        # Cleanup
        pass

Colony Templates

Templates provide declarative, reusable colony configurations:

from anthills.templates import TemplateCatalog, TemplateInstantiator

# Discover built-in templates
catalog = TemplateCatalog()
catalog.register_builtins()

# List available templates
for template in catalog.list():
    print(f"{template.name}: {template.description}")

# Instantiate a template with parameters
instantiator = TemplateInstantiator(catalog)
colony = instantiator.instantiate(
    "research_assistant",
    parameters={
        "research_depth": "comprehensive",
        "output_format": "markdown"
    }
)

colony.run()

Built-in Templates

Template Description
customer_inquiry_responder Auto-respond to customer questions
weekly_sales_summary Aggregate and report weekly sales data
research_assistant Multi-step research with Claude

Custom Templates

from anthills.templates import ColonyTemplate, WorkerSpec, TriggerSpec

template = ColonyTemplate(
    name="my_pipeline",
    description="Custom processing pipeline",
    workers=[
        WorkerSpec(
            name="processor",
            reacts_to="input.received",
            handler="my_module:process_handler",
            emits=["output.ready"]
        )
    ],
    triggers=[
        TriggerSpec(type="input.received", payload={"source": "api"})
    ]
)

Project Structure

anthills/
โ”œโ”€โ”€ board.py              # Event-sourced PheromoneBoard with wildcard patterns
โ”œโ”€โ”€ worker.py             # Worker base class with retry & concurrency control
โ”œโ”€โ”€ colony.py             # Colony runner (async event loop, auto-halt)
โ”œโ”€โ”€ connectors/           # External tool integrations
โ”‚   โ”œโ”€โ”€ base.py           # Connector, ConnectorConfig, ConnectorRegistry
โ”‚   โ”œโ”€โ”€ registry.py       # Registry and requires() helper
โ”‚   โ”œโ”€โ”€ gmail/            # Gmail connector (optional)
โ”‚   โ””โ”€โ”€ slack/            # Slack connector (optional)
โ”œโ”€โ”€ templates/            # Declarative colony configurations
โ”‚   โ”œโ”€โ”€ base.py           # ColonyTemplate, WorkerSpec, TriggerSpec
โ”‚   โ”œโ”€โ”€ catalog.py        # TemplateCatalog for discovery
โ”‚   โ”œโ”€โ”€ instantiator.py   # Convert templates to runnable colonies
โ”‚   โ””โ”€โ”€ builtins.py       # Built-in template definitions
โ””โ”€โ”€ integrations/
    โ””โ”€โ”€ claude.py         # ClaudeWorker, LLMWorker, ClaudeToolWorker

Philosophy

This is not a general-purpose agent framework. It's a specific take: agents coordinating through environmental traces, not explicit messaging.

Use it when you want:

  • Multiple agents collaborating on complex tasks
  • Self-organization without central orchestration
  • Transparent, auditable agent behavior
  • Resilience to individual agent failures

Roadmap

  • Event-sourced pheromone board with ledger
  • Wildcard pattern matching for pheromone types
  • Parallel agent execution with concurrency control
  • Connector abstraction for external tools
  • Colony templates for reusable configurations
  • Claude/LLM integration
  • Real-time dashboard (visualize pheromone board)
  • Agent profiler (performance metrics)
  • Trace debugger (replay decisions step-by-step)
  • Redis-backed board for distributed colonies
  • More connectors (GitHub, Jira, databases)
  • Webhooks / external event triggers

Building This in Public

This project is being built on Twitter: @braz_builds

Daily updates on architecture, insights, and use cases.


Built with Claude + Python. Inspired by ant colonies. ๐Ÿœ

Read the full documentation | View on PyPI

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anthills-0.1.1.tar.gz (64.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anthills-0.1.1-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

File details

Details for the file anthills-0.1.1.tar.gz.

File metadata

  • Download URL: anthills-0.1.1.tar.gz
  • Upload date:
  • Size: 64.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anthills-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ee6028be495e28e758cf9a0266367d0ae007167692aa506bcd5a0507a2c73af1
MD5 858c36bedf59b8f3a3834fa515661972
BLAKE2b-256 85d748b80dd1a1f975677fe98298456d46ae1c85a2d7951efd33ffdba512ee2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for anthills-0.1.1.tar.gz:

Publisher: publish.yml on t1dm-ai/anthills

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file anthills-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: anthills-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 37.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anthills-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f5b4502111b850b83c9bfad5539ce1abca1eb5e928dc7ea7380ea624f0ce1fa4
MD5 9d7ec76f5e78b8dd0c572e8ff7f45bbe
BLAKE2b-256 f5bf656bb7bf1181b77b70bc5acdcf824abad52bf903381ab7f0304c538cf55b

See more details on using hashes here.

Provenance

The following attestation bundles were made for anthills-0.1.1-py3-none-any.whl:

Publisher: publish.yml on t1dm-ai/anthills

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page