页面简介
We’re on a journey to advance and democratize artificial intelligence through open source and open science.
正文摘录
smolagents documentation Built-in Tools smolagents 🏡 View all docsAWS Trainium & InferentiaAccelerateBitsandbytesCLIChat UIDataset viewerDatasetsDeploying on AWSDiffusersGoogle CloudGoogle TPUsGradioHubHub Python LibraryHuggingface.jsInference Endpoints (dedicated)Inference ProvidersKernelsLeRobotLeaderboardsLightevalMicrosoft AzureOpenEnvOptimumPEFTReachy MiniSafetensorsSentence TransformersTRLTasksText Embeddings InferenceTokenizersTrackioTransformersTransformers.jsXetsmolagentstimm Search documentation mainv1.26.0v1.25.0v1.24.0v1.23.0v1.22.0v1.21.2v1.20.0v1.19.0v1.18.0v1.17.0v1.16.1v1.15.0v1.14.0v1.13.0v1.12.0v1.11.0v1.10.0v1.9.2v1.8.1v1.7.0v1.6.0v1.5.1v1.4.1v1.3.0v1.2.2v1.1.0v0.1.3 ENHIKOZH Join the Hugging Face community and get access to the augmented documentation experience Collaborate on models, datasets and Spaces Faster examples with accelerated inference Switch between documentation themes Sign Up to get started Copy page 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: Information Retrieval: Search and retrieve information from the web and specific knowledge sources. ApiWebSearchTool DuckDuckGoSearchTool GoogleSearchTool WebSearchTool WikipediaSearchTool Web Interaction: Fetch and process content from specific web pages. VisitWebpageTool Code Execution: Dynamic execution of Python code for computational tasks. PythonInterpreterTool User Interaction: Enable Human-in-the-Loop collaboration between agents and users. UserInputTool: Collect input from users. Speech Processing: Convert audio to textual data. SpeechToTextTool Workflow Control: Manage and direct the flow of agent operations. FinalAnswerTool: Conclude agent workflow with final response. ApiWebSearchTool class smolagents.ApiWebSearchTool < source > ( 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: Copied >>> from smolagents import ApiWebSearchTool >>> web_search_tool = ApiWebSearchTool(rate_limit=50.0) >>> results = web_search_tool("Hugging Face") >>> print(results) DuckDuckGoSearchTool class smolagents.DuckDuckGoSearchTool < source > ( 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: Copied >>> 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 < source > ( *args **kwargs ) GoogleSearchTool class smolagents.GoogleSearchTool < source > ( provider: str = 'serpapi' ) PythonInterpreterTool class smolagents.PythonInterpreterTool < source > ( *args authorized_imports = None timeout_seconds = 30 **kwargs ) SpeechToTextTool class smolagents.SpeechToTextTool < source > ( *args **kwargs ) UserInputTool class smolagents.UserInputTool < source > ( *args **kwargs ) VisitWebpageTool class smolagents.VisitWebpageTool < source > ( max_output_length: int = 40000 ) WebSearchTool class smolagents.WebSearchTool < source > ( max_results: int = 10 engine: str = 'duckduckgo' ) search_exa < source > ( query: str ) Search using the Exa API. Requires an EXA_API_KEY environment variable. WikipediaSearchTool class smolagents.WikipediaSearchTool < source > ( user_agent: str = 'Smolagents (myemail@example.com)' language: str = 'en' content_type: str = 'text' extract_format: str = 'WIKI' ) Parameters user_agent (str) — Custom user-agent string to identify the project. This is required as per Wikipedia API policies. See: https://foundation.wikimedia.org/wiki/Policy:Wikimedia_Foundation_User-Agent_Policy language (str, default "en") — Language in which to retrieve Wikipedia article. See: http://meta.wikimedia.org/wiki/List_of_Wikipedias content_type (Literal["summary", "text"], default "text") — Type of content to fetch. Can be “summary” for a short summary or “text” for the full article. extract_format (Literal["HTML", "WIKI"], default "WIKI") — Extraction format of the output. Can be "WIKI" or "HTML". Search Wikipedia and return the summary or full text of the requested article, along with the page URL. Example: Copied >>> 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 ←Tool-related objects