Appearance
Multi-Agent Systems
Elsai provides several patterns for orchestrating multiple agents:
| Pattern | Use when |
|---|---|
| Graph | You know the execution order ahead of time (deterministic pipeline) |
| Swarm | Agents should self-organise and decide who does what (autonomous) |
| Workflow | Complex sequential stages with conditional logic or step-level error recovery |
| Agent as Tool | Simplest form — one agent calls another like any other tool |
| A2A | Agents live in separate services and communicate over the network |
Why multi-agent?
- Parallelism — run independent tasks concurrently
- Specialisation — each agent has a focused role, tools, and system prompt
- Context management — distribute work across smaller context windows
- Scalability — compose complex workflows from simple building blocks
Graph (deterministic)
Agents are nodes in a directed graph. Edges define dependencies and data flow.
python
from elsai import Agent
from elsai.multiagent import Graph
researcher = Agent(name="researcher", description="Searches and summarises information")
writer = Agent(name="writer", description="Writes polished articles based on research")
editor = Agent(name="editor", description="Reviews and improves written content")
graph = Graph()
graph.add_node(researcher)
graph.add_node(writer)
graph.add_node(editor)
# writer receives researcher's output; editor receives writer's output
graph.add_edge(researcher, writer)
graph.add_edge(writer, editor)
result = graph("Write an article about the future of AI")
print(result)Swarm (autonomous)
Agents collaborate as a team. A coordinator decides which specialist handles each part.
python
from elsai import Agent
from elsai.multiagent import Swarm
coordinator = Agent(
name="coordinator",
description="Routes tasks to the right specialist"
)
coder = Agent(name="coder", description="Writes Python code")
reviewer = Agent(name="reviewer", description="Reviews code for bugs and style")
swarm = Swarm(agents=[coordinator, coder, reviewer])
result = swarm("Write and review a Python function that sorts a list of dicts by a key")
print(result)Agent as tool
The simplest form of multi-agent: wrap an agent as a tool for another agent.
python
from elsai import Agent
researcher = Agent(
name="researcher",
description="Searches for information on any topic and returns a summary"
)
writer = Agent(
name="writer",
tools=[researcher.as_tool()]
)
result = writer("Write a blog post about quantum computing")Related
- Graph — deterministic pipeline with declared dependencies
- Swarm — autonomous agent collaboration
- Workflow — imperative sequential/parallel pipelines
- Agent as Tool — the simplest multi-agent pattern
- Agent-to-Agent (A2A) — cross-service agent communication