Skip to main content

Pheromone-field coordination for LLM multi-agent systems

Project description

stigmergy-scheduler

Your multi-agent system doesn't need a manager. It needs a pressure field.

Most agent orchestration boils down to three bad options: polling on timers (wasteful), hardcoded if/else routing (brittle), or burning an LLM call to pick who goes next (slow and expensive). All three put coordination logic outside the system it's coordinating.

Stigmergy replaces them with a single primitive: a pressure field. Events deposit signals. Signals decay over time. When accumulated pressure crosses a threshold, the agent wakes and does the work. Dependencies resolve themselves through completion signals. Failed tasks create retry pressure automatically.

9.5x faster than LangGraph at scale. 120 tasks across 30 agents in 2.1 seconds -- same workload takes LangGraph 20 seconds. The gap widens with agent count: stigmergy dispatches all available agents per tick, graph-based frameworks batch a fixed few per step.

Scheduling overhead is sub-millisecond at 1,000 tasks. Region-indexed storage and bounded signal accumulation mean it stays flat at 10,000+. The ceiling is your LLM API, not the scheduler.

Install

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

Quick start

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

You provide a dispatch function. Stigmergy handles the tick loop, signal decay, dependency resolution, error recovery, and metrics.

Framework integrations

Already using a framework? Drop stigmergy in as a scheduling layer:

Low-level field (build your own scheduler)

The StigmergyScheduler is batteries-included, but you can use the pressure field directly for custom scheduling:

from stigmergy import PheromoneField, InMemoryFieldBackend

field = PheromoneField(InMemoryFieldBackend())

await field.deposit("agent-1", "work_claim", 0.8, {"task": "market research"})
pressure = await field.read_pressure("agent-2")
evaporated = await field.decay()

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

Core concepts

Signals are the atomic unit. Each has an agent_id, signal_type, intensity (-1.0 to 1.0), metadata, and optional target_agent_id.

PheromoneField is the shared state space implementing four self-organisation mechanisms: positive feedback (amplify), negative feedback (decay), randomness (stochastic decay), and multiple interactions (emergence from many agents).

Decay strategies: ExponentialDecay (default), LinearDecay, StepDecay, StochasticDecay.

Backends: InMemoryFieldBackend (testing/single-process), RedisFieldBackend (production/multi-process).

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.2.0.tar.gz (24.8 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.2.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stigmergy_scheduler-0.2.0.tar.gz
  • Upload date:
  • Size: 24.8 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.2.0.tar.gz
Algorithm Hash digest
SHA256 16304d1b402efe69a70d7ea11298d1b0be6c9a12f90d53a12fd7c34842944c26
MD5 542174e219eb25023e4d4fa28a69ce2e
BLAKE2b-256 cc123061b98942990e7799b62ffaf7b8636bc5d839f073472307117cea74dc3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stigmergy_scheduler-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2bcabad6508258b172b8dfc4a8f5e9ef4fb8e50c3349dbc768943c41b8ebaad
MD5 ce12e5da21eaa4385cd3fb0a60e09c71
BLAKE2b-256 42edaa269ac19cad0d345d4e39807699cf135030645a1c65c3c54e56e2560682

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