Skip to content

Tools API

The Tools API covers SDK primitives for defining, registering, and executing agent tools: @tool, MCPClient, tool executors, and ToolProvider.

For the separate elsai-agents-tools package (file I/O, shell, web search, AWS, multi-agent, and more), see the dedicated Prebuilt Tools API.


@tool

python
from elsai import tool

@tool
def function_name(param: type) -> return_type:
    """Tool description.

    Args:
        param: Parameter description.
    """
    ...

Decorator that converts a Python function into an agent tool.

  • Name: taken from the function name
  • Description: taken from the first line of the docstring
  • Parameters: derived from type hints and Args docstring section
  • Supports sync and async functions
  • Supports optional parameters with default values
  • Injects agent parameter automatically if present in the signature

MCPClient

python
from elsai.tools.mcp import MCPClient

Connects to an MCP server and exposes its tools to an agent.

MCPClient.__init__

python
MCPClient(client_factory)
ParameterTypeDescription
client_factoryCallableA zero-argument lambda that returns an MCP client context manager

MCPClient.list_tools_sync

python
tools = client.list_tools_sync()  # list[AgentTool]

Synchronously list all tools from the MCP server.

MCPClient.list_tools

python
tools = await client.list_tools()  # list[AgentTool]

Async version of list_tools_sync.

Context manager

python
# Sync context manager
with MCPClient(factory) as client:
    tools = client.list_tools_sync()

# Async context manager
async with MCPClient(factory) as client:
    tools = await client.list_tools()

ToolRegistry

Internal API

ToolRegistry is an internal implementation module (elsai.tools.registry). Prefer agent.tool_registry at runtime rather than importing it directly in application code.

python
# Internal — accessed via agent.tool_registry, not typically imported directly
from elsai.tools.registry import ToolRegistry

Internal registry that manages all tools registered to an agent. Accessed via agent.tool_registry.

python
# Get all registered tools
tools = agent.tool_registry.get_all_tools_config()

# Clean up (closes MCP connections etc.)
agent.tool_registry.cleanup()

Tool executors

python
from elsai.tools.executors import ConcurrentToolExecutor, SequentialToolExecutor

ConcurrentToolExecutor (default)

Executes multiple tool calls from the same model response concurrently using asyncio.

python
from elsai.agent import AgentConfig

agent = Agent(config=AgentConfig(tool_executor=ConcurrentToolExecutor()))

SequentialToolExecutor

Executes tool calls one at a time in order.

python
agent = Agent(config=AgentConfig(tool_executor=SequentialToolExecutor()))

Direct tool invocation

Call tools directly (bypasses LLM):

python
result = agent.tool.tool_name(param1="value", param2=42)

The agent.tool property returns a _ToolCaller that dispatches to registered tools by name.


ToolProvider

Implement ToolProvider to create managed tool collections:

python
from elsai.tools import AgentTool, ToolProvider

class MyToolProvider(ToolProvider):
    def get_tools(self) -> list[AgentTool]:
        return [my_tool_1, my_tool_2]

    def cleanup(self) -> None:
        pass  # Release any resources

agent = Agent(tools=[MyToolProvider()])

Copyright © 2026 elsai foundry.