aioagent
Lightweight async multi-agent framework for Python.
Build multi-agent systems using pure asyncio — no external infrastructure, no XMPP servers, no heavy dependencies.
Why aioagent?
| SPADE | aioagent | |
|---|---|---|
| Infrastructure | XMPP server (Prosody) | None |
| Deploy | Complex | Single process |
| Distributed agents | Yes | No (in-process) |
| Dependencies | slixmpp, aioxmpp | stdlib only |
| Best for | Distributed systems | Simulations, pipelines, prototypes |
Installation
pip install aioagent
Quick start
import asyncio
from aioagent import AgentMessage, BaseAgent, CyclicBehaviour, MessageBus
class PingBehaviour(CyclicBehaviour):
async def run(self):
await self.send(AgentMessage(to="pong", body="ping"))
reply = await self.receive(timeout=2.0)
if reply:
print(f"Got: {reply.body}")
self.kill()
class PongBehaviour(CyclicBehaviour):
async def run(self):
msg = await self.receive(timeout=2.0)
if msg:
await self.send(msg.make_reply(body="pong"))
self.kill()
class PingAgent(BaseAgent):
async def setup(self):
self.add_behaviour(PingBehaviour())
class PongAgent(BaseAgent):
async def setup(self):
self.add_behaviour(PongBehaviour())
async def main():
bus = MessageBus()
async with PongAgent("pong", bus=bus), PingAgent("ping", bus=bus):
await asyncio.sleep(1)
asyncio.run(main())
Core concepts
Agents
Subclass BaseAgent and override setup() to register behaviours:
class MyAgent(BaseAgent):
async def setup(self):
self.add_behaviour(MyBehaviour())
Agents support async with for automatic start/stop.
Behaviours
| Class | Description |
|---|---|
OneShotBehaviour |
Runs run() once and stops |
CyclicBehaviour |
Runs run() in a loop until killed |
PeriodicBehaviour |
Runs run() every N seconds |
FSMBehaviour |
Finite-state machine with transitions |
Each behaviour has on_start() and on_end() lifecycle hooks.
FSMBehaviour
Model complex protocols as state machines:
from aioagent import FSMBehaviour
class NegotiationFSM(FSMBehaviour):
async def setup_fsm(self):
self.add_state("PROPOSE", self.propose, initial=True)
self.add_state("EVALUATE", self.evaluate)
self.add_state("DONE", self.finish, final=True)
self.add_transition("PROPOSE", "EVALUATE")
self.add_transition("EVALUATE", "PROPOSE")
self.add_transition("EVALUATE", "DONE")
async def propose(self):
# ... send proposal ...
self.set_next_state("EVALUATE")
async def evaluate(self):
# ... check reply ...
self.set_next_state("DONE")
async def finish(self):
pass
Messages
msg = AgentMessage(
to="recipient",
body="hello",
performative="INFORM", # FIPA-style (optional)
metadata={"protocol": "cnp", "priority": 1},
thread="conversation-1",
)
reply = msg.make_reply(body="acknowledged")
Interaction patterns
Convenience functions for common FIPA performatives:
from aioagent import request, agree, refuse, inform
msg = request("worker", body="compute fibonacci(10)")
await self.send(msg)
reply = await self.receive(timeout=5.0)
# reply with: agree(msg, body="ok") or refuse(msg, body="busy")
Templates
Filter incoming messages by sender, performative, or metadata:
from aioagent import MessageTemplate
template = MessageTemplate(sender="agent_a", performative="REQUEST")
agent.add_behaviour(handler, template=template)
MessageBus
The bus routes messages between agents via per-agent asyncio.Queue instances:
bus = MessageBus()
agent_a = BaseAgent("a", bus=bus)
agent_b = BaseAgent("b", bus=bus)
# Broadcast to all agents
msg = AgentMessage(to="", sender="coordinator", body="start")
await bus.broadcast(msg, exclude="coordinator")
Custom exceptions
All framework errors inherit from AioagentError:
from aioagent import AgentNotFoundError, AgentAlreadyRegisteredError, BehaviourNotBoundError
Examples
See the examples/ directory:
- ping_pong.py — Basic message exchange
- fsm_negotiation.py — Price negotiation with FSM
- broadcast.py — Coordinator notifies all workers
- pipeline.py — Data processing pipeline
- request_reply.py — Request/reply with agree/refuse
Development
git clone https://github.com/mariotrerotola/aioagent.git
cd aioagent
pip install -e ".[dev]"
pytest
pytest --cov=aioagent # with coverage
mypy src/aioagent/ # type checking
ruff check src/ tests/ # linting
License
Release files for aioagent 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aioagent-0.1.0.tar.gz | 20.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aioagent-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.3 kB
Release files / aioagent-0.1.0.tar.gz
| Download URL | aioagent-0.1.0.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cba46922fa40b1e66ab88507f5d439b0a7140b1818afc98a1c1fdc3fe12ffb64
|
|
BLAKE2b-256 checksum How to use checksums |
f9069d4825629fcc935b911454b24ba2345a717ba778fba6fa4fc55af8a6659d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 3, 2026.
Transparency logRelease files / aioagent-0.1.0-py3-none-any.whl
| Download URL | aioagent-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
da64ffbc78c7d8e00c9a7196e7fb5461129afb064171a8f4a43cf8a6872911c6
|
|
BLAKE2b-256 checksum How to use checksums |
5d4d6e9128457a8fa61b33f5db9b9e81145bf7175a2faf114de39f628f324c50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 3, 2026.
Transparency log