Skip to main content
Inferix

Tools

A tool is a function the agent can call. The simplest way to make one is the @tool decorator — the docstring and type hints become the tool's schema that the LLM sees.

from smolagents import tool

@tool
def get_travel_duration(start: str, destination: str) -> str:
    """Returns the driving time between two locations.

    Args:
        start: The starting location.
        destination: The destination location.
    """
    import requests
    ...
    return "1 hour 20 minutes"

Write clear docstrings and precise type hints — they are literally the interface the model reasons over.

The Tool class

For stateful or more complex tools, subclass Tool:

from smolagents import Tool

class ModelDownloadsTool(Tool):
    name = "model_download_counter"
    description = "Returns the most downloaded model for a given task."
    inputs = {"task": {"type": "string", "description": "The pipeline task."}}
    output_type = "string"

    def forward(self, task: str) -> str:
        ...
        return "meta-llama/Llama-3.3-70B-Instruct"

Importing tools

  • From the Hub: Tool.from_hub("username/tool-name")
  • From LangChain: Tool.from_langchain(langchain_tool)
  • From an MCP server: ToolCollection.from_mcp(server_params) — connect to any MCP server and expose its tools to the agent.

    We use cookies for essential functionality and analytics. You can accept or reject analytics cookies.Cookie policy