smolagents documentation

Built-in Tools

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Built-in Tools

Ready-to-use tool implementations provided by the smolagents library.

These built-in tools are concrete implementations of the Tool base class, each designed for specific tasks such as web searching, Python code execution, webpage retrieval, and user interaction. You can use these tools directly in your agents without having to implement the underlying functionality yourself. Each tool handles a particular capability and follows a consistent interface, making it easy to compose them into powerful agent workflows.

The built-in tools can be categorized by their primary functions:

ApiWebSearchTool

class smolagents.ApiWebSearchTool

< >

( endpoint: str = '' api_key: str = '' api_key_name: str = '' headers: dict = None params: dict = None rate_limit: float | None = 1.0 )

Parameters

  • endpoint (str) — API endpoint URL. Defaults to Brave Search API.
  • api_key (str) — API key for authentication.
  • api_key_name (str) — Environment variable name containing the API key. Defaults to “BRAVE_API_KEY”.
  • headers (dict, optional) — Headers for API requests.
  • params (dict, optional) — Parameters for API requests.
  • rate_limit (float, default 1.0) — Maximum queries per second. Set to None to disable rate limiting.

Web search tool that performs API-based searches. By default, it uses the Brave Search API.

This tool implements a rate limiting mechanism to ensure compliance with API usage policies. By default, it limits requests to 1 query per second.

Examples:

>>> from smolagents import ApiWebSearchTool
>>> web_search_tool = ApiWebSearchTool(rate_limit=50.0)
>>> results = web_search_tool("Hugging Face")
>>> print(results)

DuckDuckGoSearchTool

class smolagents.DuckDuckGoSearchTool

< >

( max_results: int = 10 rate_limit: float | None = 1.0 **kwargs )

Parameters

  • max_results (int, default 10) — Maximum number of search results to return.
  • rate_limit (float, default 1.0) — Maximum queries per second. Set to None to disable rate limiting.
  • **kwargs — Additional keyword arguments for the DDGS client.

Web search tool that performs searches using the DuckDuckGo search engine.

Examples:

>>> from smolagents import DuckDuckGoSearchTool
>>> web_search_tool = DuckDuckGoSearchTool(max_results=5, rate_limit=2.0)
>>> results = web_search_tool("Hugging Face")
>>> print(results)

FinalAnswerTool

class smolagents.FinalAnswerTool

< >

( *args **kwargs )

GoogleSearchTool

class smolagents.GoogleSearchTool

< >

( provider: str = 'serpapi' )

PythonInterpreterTool

class smolagents.PythonInterpreterTool

< >

( *args authorized_imports = None **kwargs )

SpeechToTextTool

class smolagents.SpeechToTextTool

< >

( *args **kwargs )

UserInputTool

class smolagents.UserInputTool

< >

( *args **kwargs )

VisitWebpageTool

class smolagents.VisitWebpageTool

< >

( max_output_length: int = 40000 )

WebSearchTool

class smolagents.WebSearchTool

< >

( max_results: int = 10 engine: str = 'duckduckgo' )

WikipediaSearchTool

class smolagents.WikipediaSearchTool

< >

( user_agent: str = 'Smolagents (myemail@example.com)' language: str = 'en' content_type: str = 'text' extract_format: str = 'WIKI' )

Parameters

Search Wikipedia and return the summary or full text of the requested article, along with the page URL.

Example:

>>> from smolagents import CodeAgent, InferenceClientModel, WikipediaSearchTool
>>> agent = CodeAgent(
>>>     tools=[
>>>            WikipediaSearchTool(
>>>                user_agent="MyResearchBot (myemail@example.com)",
>>>                language="en",
>>>                content_type="summary",  # or "text"
>>>                extract_format="WIKI",
>>>            )
>>>        ],
>>>     model=InferenceClientModel(),
>>> )
>>> agent.run("Python_(programming_language)")
< > Update on GitHub