Appearance
Agent as Tool
The simplest multi-agent pattern: wrap a specialised agent as a tool that another agent can call. This requires no new classes — just agent.as_tool().
Basic usage
python
from elsai import Agent
# A specialised sub-agent
researcher = Agent(
name="researcher",
description="Searches the web and returns summarised findings on any topic.",
system_prompt="You are a research specialist. Find accurate, up-to-date information.",
)
# The orchestrating agent uses the researcher as a tool
orchestrator = Agent(
name="orchestrator",
system_prompt="You are a helpful assistant. Use the researcher tool when you need information.",
tools=[researcher.as_tool()],
)
result = orchestrator("What are the key differences between React and Vue?")
print(result)as_tool() parameters
python
researcher.as_tool(
name="research", # Tool name (defaults to agent.name)
description="...", # Tool description (defaults to agent.description)
preserve_context=False, # Whether to keep conversation history between calls
)| Parameter | Default | Description |
|---|---|---|
name | agent.name | Tool name the model sees |
description | agent.description | How the model decides when to call this tool |
preserve_context | False | True = keep history across calls; False = fresh start each time |
Preserve context
Set preserve_context=True when the sub-agent needs to remember earlier interactions:
python
# Stateful sub-agent — remembers context between calls
memory_agent = Agent(
name="memory",
description="Stores and retrieves information from our working memory.",
)
orchestrator = Agent(
tools=[memory_agent.as_tool(preserve_context=True)],
)Chains of agents
You can nest agents multiple levels deep:
python
# Level 3 — data retriever
data_agent = Agent(name="data", description="Retrieves raw data from databases")
# Level 2 — analyst uses data agent
analyst = Agent(
name="analyst",
description="Analyses data and produces insights",
tools=[data_agent.as_tool()],
)
# Level 1 — orchestrator uses analyst
orchestrator = Agent(
name="orchestrator",
tools=[analyst.as_tool()],
)
result = orchestrator("Analyse our top customers and explain the key trends")Passing tools
Sub-agents can have their own tools:
python
from elsai_tools import calculator, python_repl
coder = Agent(
name="coder",
description="Writes and executes Python code to solve problems",
tools=[calculator, python_repl],
)
manager = Agent(
name="manager",
tools=[coder.as_tool()],
)
result = manager("Calculate the compound interest on $10,000 at 5% for 10 years")Comparison with Graph/Swarm
as_tool() | Graph | Swarm | |
|---|---|---|---|
| Setup | Minimal | Medium | Medium |
| Orchestration | LLM decides when to call | Developer-defined order | Autonomous |
| Best for | 1–3 specialists | Multi-step pipelines | Open-ended teamwork |