Skip to main content

Pheromone-field coordination for LLM multi-agent systems

Project description

stigmergy

Pressure-driven scheduling for multi-agent AI systems. Agents wake when there's work to do, not on fixed timers. Dependencies resolve themselves. Failed tasks retry automatically.

Add a scheduler to your agents in 6 lines. No orchestration code, no polling loops, no cron. Works standalone or drops into LangGraph, AutoGen, and CrewAI.

Based on arXiv:2601.08129 -- pheromone-inspired signal fields that outperform hierarchical control by 30x on solve rates.

Quick Start

Scheduler (batteries included)

from stigmergy import StigmergyScheduler, TaskSpec, DispatchResult

scheduler = StigmergyScheduler(wake_threshold=0.4)

async def dispatch(agent_id, task):
    result = await my_llm_call(task.description)
    return DispatchResult(success=True, output=result)

scheduler.set_dispatcher(dispatch)

await scheduler.add_task(TaskSpec(
    id="draft", description="Write first draft",
    agent_id="writer", priority=0.8,
))
await scheduler.add_task(TaskSpec(
    id="review", description="Review the draft",
    agent_id="reviewer", dependencies=["draft"], priority=0.6,
))

await scheduler.run()  # blocks until all tasks complete

The scheduler handles tick loops, signal decay, dependency resolution, error recovery, and metrics. You just provide the dispatch function.

Low-level field (build your own)

from stigmergy import PheromoneField, InMemoryFieldBackend

field = PheromoneField(InMemoryFieldBackend())

# Agent deposits a signal
await field.deposit("agent-1", "work_claim", 0.8, {"task": "market research"})

# Another agent reads aggregate pressure
pressure = await field.read_pressure("agent-2")

# Periodic decay (evaporation)
evaporated = await field.decay()

Core Concepts

Signals

The atomic unit of communication. A signal has:

  • agent_id — who deposited it
  • signal_type — category (e.g. work_claim, need_help, insight_deposit)
  • intensity — strength from -1.0 (repulsion) to 1.0 (attraction)
  • metadata — arbitrary attached data
  • target_agent_id — optional targeting for directed pressure

PheromoneField

The shared state space. Implements the four classical self-organisation mechanisms:

  1. Positive feedbackamplify() reinforces valuable signals
  2. Negative feedbackdecay() evaporates stale signals
  3. RandomnessStochasticDecay adds noise to prevent local optima
  4. Multiple interactions — many agents reading/writing creates emergence

Decay Strategies

  • ExponentialDecay — signals lose half intensity every N seconds (default)
  • LinearDecay — fixed rate reduction per second
  • StepDecay — full intensity until TTL, then instant evaporation
  • StochasticDecay — exponential with random noise

Backends

  • InMemoryFieldBackend — for testing and single-process deployments
  • RedisFieldBackend — for production multi-process setups

Scheduler API

Method Description
StigmergyScheduler(wake_threshold, tick_interval, ...) Create scheduler with tunable pressure thresholds
scheduler.set_dispatcher(fn) Set the async function called when an agent wakes
await scheduler.add_task(TaskSpec(...)) Queue a task with dependencies and priority
await scheduler.inject_urgent(TaskSpec(...)) Force-wake an agent immediately
await scheduler.run() Block until all tasks complete or stop() is called
scheduler.start() Run in background, returns asyncio.Task
scheduler.stop() Graceful shutdown after current tick
scheduler.get_metrics() Snapshot of ticks, completions, failures, pressure map

Self-Scheduling Pattern

For custom scheduling beyond what StigmergyScheduler provides, use the field directly:

# Each tick (e.g., every 30 seconds):
for agent in agents:
    pressure = await field.read_pressure(
        agent.id,
        weights={"event": 0.3, "goal": 0.25, "peer": 0.15, "time": 0.3}
    )
    if pressure > agent.wake_threshold:
        await wake_agent(agent)

# Apply decay each tick
await field.decay()

Agents wake when accumulated pressure (from events, goals, peer requests, time) exceeds their threshold — no fixed intervals needed.

Install

pip install stigmergy-scheduler              # core (in-memory backend)
pip install stigmergy-scheduler[redis]       # with Redis backend

Author

Built by Warwick McIntosh at Production Grade.

License

MIT

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

stigmergy_scheduler-0.1.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

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

stigmergy_scheduler-0.1.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file stigmergy_scheduler-0.1.0.tar.gz.

File metadata

  • Download URL: stigmergy_scheduler-0.1.0.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for stigmergy_scheduler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e79970d8a138c77dd74001deae55e1af5b44e224823478adafdef18d9a3dfb72
MD5 fa30e462b9ff97b3a2b96b350438e621
BLAKE2b-256 8fe842bce7583504ab52997ce74efd393cefe258d1804e5da4d1e77c37d14dba

See more details on using hashes here.

File details

Details for the file stigmergy_scheduler-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for stigmergy_scheduler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf35baa7e521934d30bcba9215c45e31db4db7897abaad27bccc67150140ccdb
MD5 e1975f883ce527217d570128d5964137
BLAKE2b-256 82eebb51b2b5598c1bcff9676a66575a2509433c58e31e0a7d2dc44fe1d80ce4

See more details on using hashes here.

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