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:
- Positive feedback —
amplify()reinforces valuable signals - Negative feedback —
decay()evaporates stale signals - Randomness —
StochasticDecayadds noise to prevent local optima - Multiple interactions — many agents reading/writing creates emergence
Decay Strategies
ExponentialDecay— signals lose half intensity every N seconds (default)LinearDecay— fixed rate reduction per secondStepDecay— full intensity until TTL, then instant evaporationStochasticDecay— exponential with random noise
Backends
InMemoryFieldBackend— for testing and single-process deploymentsRedisFieldBackend— 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.
- GitHub: warwickmcintosh
- X: @warwickmcintosh
- Email: contact@productiongrade.tech
- Blog: blog.productiongrade.tech
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stigmergy_scheduler-0.1.1.tar.gz.
File metadata
- Download URL: stigmergy_scheduler-0.1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a81a0ea08ee618c25ebbab5dedbfa372e5e0011a69dfacc6758a9afc64a787a6
|
|
| MD5 |
1ee438c7d7e0a1304a3e50ee2d7546cc
|
|
| BLAKE2b-256 |
63e5c3d045908dd01845159ffd7dd9ed21fc132c92e3d955aabc6f1508d0c147
|
File details
Details for the file stigmergy_scheduler-0.1.1-py3-none-any.whl.
File metadata
- Download URL: stigmergy_scheduler-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0030aad472c7874583a99fd5937e6d5e467a57bf948bdd76c1fc9c3b7deffa1
|
|
| MD5 |
bce6789153b30c04d0f684e952091713
|
|
| BLAKE2b-256 |
5680cad303fabba2fc8b5ce0d362d17cc17f1a668d4d0d1359008484e94f6890
|