Appearance
Tools
Tools give agents the ability to interact with the world — call APIs, run code, query databases, search the web, and more. The model decides which tools to call and in what order.
How tools work
- You register tools with the agent
- The SDK sends their schemas (name, description, parameters) to the model
- The model requests a tool call with specific arguments
- The SDK executes the tool and sends the result back to the model
- The model continues reasoning with the new information
Tool types
| Type | How to use |
|---|---|
| Python functions | Decorate with @tool |
| Prebuilt tools | Install elsai-agents-tools and register ready-made tools |
| MCP servers | Connect via MCPClient |
| Directory tools | Auto-load from ./tools/ |
| Agent as tool | Call agent.as_tool() |
Python function tools
python
from elsai import Agent, tool
@tool
def search_database(query: str, limit: int = 10) -> list[dict]:
"""Search the product database for matching items.
Args:
query: The search query string.
limit: Maximum number of results to return.
Returns:
A list of matching product dictionaries.
"""
# Your implementation here
return [{"name": f"Result for '{query}'", "id": i} for i in range(limit)]
agent = Agent(tools=[search_database])MCP server tools
python
from elsai import Agent
from elsai.tools.mcp import MCPClient
from mcp import stdio_client, StdioServerParameters
client = MCPClient(
lambda: stdio_client(StdioServerParameters(
command="uvx",
args=["mcp-server-fetch"]
))
)
with client:
agent = Agent(tools=client.list_tools_sync())
agent("Fetch the content from https://example.com")Directory hot-reload
Place tool files in ./tools/ and they load automatically:
python
agent = Agent(load_tools_from_directory=True)
# Tools in ./tools/*.py are loaded and reloaded on changeRegistering multiple tool types together
python
from elsai import Agent, tool
from elsai.tools.mcp import MCPClient
@tool
def my_custom_tool(x: str) -> str:
"""My custom tool.
Args:
x: Input string.
"""
return x.upper()
@tool
def add(a: float, b: float) -> float:
"""Add two numbers."""
return a + b
agent = Agent(tools=[
my_custom_tool,
add,
# mcp_client.list_tools_sync() # spread MCP tools
])Listing available tools
python
print(agent.tool_names)
# ['my_custom_tool', 'add', ...]Calling tools directly
You can invoke tools directly without going through the LLM:
python
result = agent.tool.add(a=2, b=2)
print(result) # 4Prebuilt tools package
For ready-made tools — file I/O, shell, web search, AWS, multi-agent orchestration, and more — install the optional elsai-agents-tools package:
bash
pip install --extra-index-url https://elsai-agents.elsai.ai/root/ elsai-agents-tools==0.3.0See Prebuilt Tools for the full tool list, optional extras, and usage examples.
Related
- Prebuilt Tools — ready-made tools package
- Function Tools — detailed guide to building tools
- MCP Tools — connecting MCP servers