Skip to content

Tools

Tools are registered by name for the whole process. An agent gets a tool when you pass its ToolDesc to AgentBuilder.tool or tools, and Ailoy runs the function registered under that name. Built-in tools are registered from the start; Built-in tools lists them. For explanations and a full example, see Tools.

When a call fails, Python raises ailoy.AiloyError, Node.js throws an Error with code set to "AILOY_ERROR", and Rust returns an Err. Each entry’s Raises line says when. See Errors.

Function Does
register_tool Registers a function and returns its description.
set_tool_provider Sets or replaces the function behind a tool name.
remove_tool_provider Removes a tool’s function.
register_mcp_stdio Starts a local MCP server and registers its tools.
register_mcp_streamable_http Connects to a remote MCP server and registers its tools.
unregister_mcp Removes an MCP server’s tools and closes it.

register_tool

Registers a function as a tool and returns its description, ready to pass to AgentBuilder.tool. Node.js: registerTool. In Rust, build the description with ToolDescBuilder and register the function with set_tool_provider.

ailoy.register_tool(desc: ToolDesc, func: Callable[..., Any | Awaitable[Any]]) -> ToolDesc
Parameter Type Description
desc ToolDesc The tool’s name, description and parameters (a JSON schema).
func function Python: called with keyword arguments named as in the schema; may be async. Node.js: called with one object; may return a promise. Must return JSON-compatible data.

Returns the ToolDesc. Registering a name that already exists replaces its function for every agent built afterwards. If func raises, the model receives the error as the tool result.

Example

from ailoy import register_tool
def order_status(order_id: str) -> dict:
return {"status": "shipped"}
desc = register_tool(
{
"name": "order_status",
"description": "Look up an order's status by its id.",
"parameters": {
"type": "object",
"properties": {"order_id": {"type": "string"}},
"required": ["order_id"],
},
},
order_status,
)
agent = await AgentBuilder("anthropic/claude-haiku-5-5").tool(desc).build()

set_tool_provider

Sets the function for a tool name without returning a description. Use it when a saved spec already has the description, or in Rust. Node.js: setToolProvider.

ailoy.set_tool_provider(name: str, func: Callable[..., Any | Awaitable[Any]]) -> None

Write the function

A function, or an async function, called with the arguments as keyword arguments. Return JSON-compatible data.

async def order_status(order_id: str):
return {"status": "shipped"}

Use the agent’s sandbox

A Python tool isn’t passed the sandbox. To work in it, call the virtx Sandbox you gave the agent from your function, with virtx’s own methods.

remove_tool_provider

Removes a tool’s function. Node.js: removeToolProvider.

ailoy.remove_tool_provider(name: str) -> bool

Returns whether the name was registered (Rust: the removed provider).

register_mcp_stdio

Starts an MCP server as a process on this machine and registers each of its tools as <prefix>__<name>. Node.js: registerMcpStdio. See Use MCP servers.

async def register_mcp_stdio(prefix: str, command: str, args: list[str] = []) -> list[ToolDesc]
Parameter Type Description
prefix string Added to each tool’s name, so tools from different servers don’t clash.
command string The program that starts the server, such as "uvx" or "npx".
args list of strings Arguments to the command, such as ["mcp-server-fetch"].

Returns the descriptions of the server’s tools, to pass to AgentBuilder.tools. The server runs with your program’s access, so only register servers you trust.

Raises if the command isn’t installed or the server exits at startup. See MCP troubleshooting.

Example

from ailoy import register_mcp_stdio
tools = await register_mcp_stdio("fetch", "uvx", ["mcp-server-fetch"])
agent = await AgentBuilder("anthropic/claude-haiku-5-5").tools(tools).build()

register_mcp_streamable_http

Connects to a remote MCP server over Streamable HTTP and registers each of its tools as <prefix>__<name>. Node.js: registerMcpStreamableHttp.

async def register_mcp_streamable_http(prefix: str, url: str) -> list[ToolDesc]
Parameter Type Description
prefix string Added to each tool’s name, so tools from different servers don’t clash.
url string The server’s Streamable HTTP endpoint.

Returns the descriptions of the server’s tools, to pass to AgentBuilder.tools.

Raises if the server can’t be reached.

Example

from ailoy import register_mcp_streamable_http
tools = await register_mcp_streamable_http("deepwiki", "https://mcp.deepwiki.com/mcp")

unregister_mcp

Removes all the tools registered with a prefix and closes the connection to the server. Registered servers otherwise stay connected until your program exits. Node.js: unregisterMcp.

ailoy.unregister_mcp(prefix: str) -> int

Returns how many tools were removed. An unknown prefix removes nothing.