Skip to content

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

python
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
agent = Agent(tool_executor=ConcurrentToolExecutor())

SequentialToolExecutor

Executes tool calls one at a time in order.

python
agent = Agent(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.tool_provider import ToolProvider
from elsai.types.tools import AgentTool

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.