{"id":23688510,"url":"https://github.com/huggingface/smolagents","last_synced_at":"2026-01-17T00:55:12.259Z","repository":{"id":269026794,"uuid":"898968194","full_name":"huggingface/smolagents","owner":"huggingface","description":"🤗 Smolagents: a barebones library for agents. Agents just write python code to call/orchestrate tools.","archived":false,"fork":false,"pushed_at":"2024-12-26T11:10:20.000Z","size":1323,"stargazers_count":81,"open_issues_count":0,"forks_count":4,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-12-26T11:30:35.308Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huggingface.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-05T11:28:04.000Z","updated_at":"2024-12-26T11:28:15.000Z","dependencies_parsed_at":"2024-12-26T11:30:37.365Z","dependency_job_id":null,"html_url":"https://github.com/huggingface/smolagents","commit_stats":null,"previous_names":["huggingface/agents","huggingface/smolagents"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huggingface%2Fsmolagents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huggingface%2Fsmolagents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huggingface%2Fsmolagents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huggingface%2Fsmolagents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huggingface","download_url":"https://codeload.github.com/huggingface/smolagents/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231798455,"owners_count":18428167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-30T00:18:02.930Z","updated_at":"2026-01-17T00:55:12.239Z","avatar_url":"https://github.com/huggingface.png","language":"Python","readme":"\u003c!---\nCopyright 2024 The HuggingFace Team. All rights reserved.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n--\u003e\n\u003cp align=\"center\"\u003e\n    \u003c!-- Uncomment when CircleCI is set up\n    \u003ca href=\"https://circleci.com/gh/huggingface/accelerate\"\u003e\u003cimg alt=\"Build\" src=\"https://img.shields.io/circleci/build/github/huggingface/transformers/master\"\u003e\u003c/a\u003e\n    --\u003e\n    \u003ca href=\"https://github.com/huggingface/smolagents/blob/main/LICENSE\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/huggingface/smolagents.svg?color=blue\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://huggingface.co/docs/smolagents\"\u003e\u003cimg alt=\"Documentation\" src=\"https://img.shields.io/website/http/huggingface.co/docs/smolagents/index.html.svg?down_color=red\u0026down_message=offline\u0026up_message=online\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/huggingface/smolagents/releases\"\u003e\u003cimg alt=\"GitHub release\" src=\"https://img.shields.io/github/release/huggingface/smolagents.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/huggingface/smolagents/blob/main/CODE_OF_CONDUCT.md\"\u003e\u003cimg alt=\"Contributor Covenant\" src=\"https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://deepwiki.com/huggingface/smolagents\"\u003e\u003cimg src=\"https://deepwiki.com/badge.svg\" alt=\"Ask DeepWiki\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch3 align=\"center\"\u003e\n  \u003cdiv style=\"display:flex;flex-direction:row;\"\u003e\n    \u003cimg src=\"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/smolagents.png\" alt=\"Hugging Face mascot as James Bond\" width=400px\u003e\n    \u003cp\u003eAgents that think in code!\u003c/p\u003e\n  \u003c/div\u003e\n\u003c/h3\u003e\n\n`smolagents` is a library that enables you to run powerful agents in a few lines of code. It offers:\n\n✨ **Simplicity**: the logic for agents fits in ~1,000 lines of code (see [agents.py](https://github.com/huggingface/smolagents/blob/main/src/smolagents/agents.py)). We kept abstractions to their minimal shape above raw code!\n\n🧑‍💻 **First-class support for Code Agents**. Our [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent) writes its actions in code (as opposed to \"agents being used to write code\"). To make it secure, we support executing in sandboxed environments via [Blaxel](https://blaxel.ai), [E2B](https://e2b.dev/), [Modal](https://modal.com/), Docker, or Pyodide+Deno WebAssembly sandbox.\n\n🤗 **Hub integrations**: you can [share/pull tools or agents to/from the Hub](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_hub) for instant sharing of the most efficient agents!\n\n🌐 **Model-agnostic**: smolagents supports any LLM. It can be a local `transformers` or `ollama` model, one of [many providers on the Hub](https://huggingface.co/blog/inference-providers), or any model from OpenAI, Anthropic and many others via our [LiteLLM](https://www.litellm.ai/) integration.\n\n👁️ **Modality-agnostic**: Agents support text, vision, video, even audio inputs! Cf [this tutorial](https://huggingface.co/docs/smolagents/examples/web_browser) for vision.\n\n🛠️ **Tool-agnostic**: you can use tools from any [MCP server](https://huggingface.co/docs/smolagents/reference/tools#smolagents.ToolCollection.from_mcp), from [LangChain](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_langchain), you can even use a [Hub Space](https://huggingface.co/docs/smolagents/reference/tools#smolagents.Tool.from_space) as a tool.\n\nFull documentation can be found [here](https://huggingface.co/docs/smolagents/index).\n\n\u003e [!NOTE]\n\u003e Check the our [launch blog post](https://huggingface.co/blog/smolagents) to learn more about `smolagents`!\n\n## Quick demo\n\nFirst install the package with a default set of tools:\n```bash\npip install \"smolagents[toolkit]\"\n```\nThen define your agent, give it the tools it needs and run it!\n```py\nfrom smolagents import CodeAgent, WebSearchTool, InferenceClientModel\n\nmodel = InferenceClientModel()\nagent = CodeAgent(tools=[WebSearchTool()], model=model, stream_outputs=True)\n\nagent.run(\"How many seconds would it take for a leopard at full speed to run through Pont des Arts?\")\n```\n\nhttps://github.com/user-attachments/assets/84b149b4-246c-40c9-a48d-ba013b08e600\n\nYou can even share your agent to the Hub, as a Space repository:\n```py\nagent.push_to_hub(\"m-ric/my_agent\")\n\n# agent.from_hub(\"m-ric/my_agent\") to load an agent from Hub\n```\n\nOur library is LLM-agnostic: you could switch the example above to any inference provider.\n\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003eInferenceClientModel, gateway for all \u003ca href=\"https://huggingface.co/docs/inference-providers/index\"\u003einference providers\u003c/a\u003e supported on HF\u003c/b\u003e\u003c/summary\u003e\n\n```py\nfrom smolagents import InferenceClientModel\n\nmodel = InferenceClientModel(\n    model_id=\"deepseek-ai/DeepSeek-R1\",\n    provider=\"together\",\n)\n```\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003eLiteLLM to access 100+ LLMs\u003c/b\u003e\u003c/summary\u003e\n\n```py\nfrom smolagents import LiteLLMModel\n\nmodel = LiteLLMModel(\n    model_id=\"anthropic/claude-4-sonnet-latest\",\n    temperature=0.2,\n    api_key=os.environ[\"ANTHROPIC_API_KEY\"]\n)\n```\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003eOpenAI-compatible servers: Together AI\u003c/b\u003e\u003c/summary\u003e\n\n```py\nimport os\nfrom smolagents import OpenAIModel\n\nmodel = OpenAIModel(\n    model_id=\"deepseek-ai/DeepSeek-R1\",\n    api_base=\"https://api.together.xyz/v1/\", # Leave this blank to query OpenAI servers.\n    api_key=os.environ[\"TOGETHER_API_KEY\"], # Switch to the API key for the server you're targeting.\n)\n```\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003eOpenAI-compatible servers: OpenRouter\u003c/b\u003e\u003c/summary\u003e\n\n```py\nimport os\nfrom smolagents import OpenAIModel\n\nmodel = OpenAIModel(\n    model_id=\"openai/gpt-4o\",\n    api_base=\"https://openrouter.ai/api/v1\", # Leave this blank to query OpenAI servers.\n    api_key=os.environ[\"OPENROUTER_API_KEY\"], # Switch to the API key for the server you're targeting.\n)\n```\n\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003eLocal `transformers` model\u003c/b\u003e\u003c/summary\u003e\n\n```py\nfrom smolagents import TransformersModel\n\nmodel = TransformersModel(\n    model_id=\"Qwen/Qwen3-Next-80B-A3B-Thinking\",\n    max_new_tokens=4096,\n    device_map=\"auto\"\n)\n```\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003eAzure models\u003c/b\u003e\u003c/summary\u003e\n\n```py\nimport os\nfrom smolagents import AzureOpenAIModel\n\nmodel = AzureOpenAIModel(\n    model_id = os.environ.get(\"AZURE_OPENAI_MODEL\"),\n    azure_endpoint=os.environ.get(\"AZURE_OPENAI_ENDPOINT\"),\n    api_key=os.environ.get(\"AZURE_OPENAI_API_KEY\"),\n    api_version=os.environ.get(\"OPENAI_API_VERSION\")    \n)\n```\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003cb\u003eAmazon Bedrock models\u003c/b\u003e\u003c/summary\u003e\n\n```py\nimport os\nfrom smolagents import AmazonBedrockModel\n\nmodel = AmazonBedrockModel(\n    model_id = os.environ.get(\"AMAZON_BEDROCK_MODEL_ID\") \n)\n```\n\u003c/details\u003e\n\n## CLI\n\nYou can run agents from CLI using two commands: `smolagent` and `webagent`.\n\n`smolagent` is a generalist command to run a multi-step `CodeAgent` that can be equipped with various tools.\n\n```bash\n# Run with direct prompt and options\nsmolagent \"Plan a trip to Tokyo, Kyoto and Osaka between Mar 28 and Apr 7.\"  --model-type \"InferenceClientModel\" --model-id \"Qwen/Qwen3-Next-80B-A3B-Thinking\" --imports pandas numpy --tools web_search\n\n# Run in interactive mode (launches setup wizard when no prompt provided)\nsmolagent\n```\n\nInteractive mode guides you through:\n- Agent type selection (CodeAgent vs ToolCallingAgent)  \n- Tool selection from available toolbox\n- Model configuration (type, ID, API settings)\n- Advanced options like additional imports\n- Task prompt input\n\nMeanwhile `webagent` is a specific web-browsing agent using [helium](https://github.com/mherrmann/helium) (read more [here](https://github.com/huggingface/smolagents/blob/main/src/smolagents/vision_web_browser.py)).\n\nFor instance:\n```bash\nwebagent \"go to xyz.com/men, get to sale section, click the first clothing item you see. Get the product details, and the price, return them. note that I'm shopping from France\" --model-type \"LiteLLMModel\" --model-id \"gpt-5\"\n```\n\n## How do Code agents work?\n\nOur [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent) works mostly like classical ReAct agents - the exception being that the LLM engine writes its actions as Python code snippets.\n\n```mermaid\nflowchart TB\n    Task[User Task]\n    Memory[agent.memory]\n    Generate[Generate from agent.model]\n    Execute[Execute Code action - Tool calls are written as functions]\n    Answer[Return the argument given to 'final_answer']\n\n    Task --\u003e|Add task to agent.memory| Memory\n\n    subgraph ReAct[ReAct loop]\n        Memory --\u003e|Memory as chat messages| Generate\n        Generate --\u003e|Parse output to extract code action| Execute\n        Execute --\u003e|No call to 'final_answer' tool =\u003e Store execution logs in memory and keep running| Memory\n    end\n    \n    Execute --\u003e|Call to 'final_answer' tool| Answer\n\n    %% Styling\n    classDef default fill:#d4b702,stroke:#8b7701,color:#ffffff\n    classDef io fill:#4a5568,stroke:#2d3748,color:#ffffff\n    \n    class Task,Answer io\n```\n\nActions are now Python code snippets. Hence, tool calls will be performed as Python function calls. For instance, here is how the agent can perform web search over several websites in one single action:\n```py\nrequests_to_search = [\"gulf of mexico america\", \"greenland denmark\", \"tariffs\"]\nfor request in requests_to_search:\n    print(f\"Here are the search results for {request}:\", web_search(request))\n```\n\nWriting actions as code snippets is demonstrated to work better than the current industry practice of letting the LLM output a dictionary of the tools it wants to call: [uses 30% fewer steps](https://huggingface.co/papers/2402.01030) (thus 30% fewer LLM calls) and [reaches higher performance on difficult benchmarks](https://huggingface.co/papers/2411.01747). Head to [our high-level intro to agents](https://huggingface.co/docs/smolagents/conceptual_guides/intro_agents) to learn more on that.\n\nEspecially, since code execution can be a security concern (arbitrary code execution!), we provide options at runtime:\n  - a secure python interpreter to run code more safely in your environment (more secure than raw code execution but still risky)\n  - a sandboxed environment using [Blaxel](https://blaxel.ai), [E2B](https://e2b.dev/), or Docker (removes the risk to your own system).\n\nAlongside [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent), we also provide the standard [`ToolCallingAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.ToolCallingAgent) which writes actions as JSON/text blobs. You can pick whichever style best suits your use case.\n\n## How smol is this library?\n\nWe strived to keep abstractions to a strict minimum: the main code in `agents.py` has \u003c1,000 lines of code.\nStill, we implement several types of agents: `CodeAgent` writes its actions as Python code snippets, and the more classic `ToolCallingAgent` leverages built-in tool calling methods. We also have multi-agent hierarchies, import from tool collections, remote code execution, vision models...\n\nBy the way, why use a framework at all? Well, because a big part of this stuff is non-trivial. For instance, the code agent has to keep a consistent format for code throughout its system prompt, its parser, the execution. So our framework handles this complexity for you. But of course we still encourage you to hack into the source code and use only the bits that you need, to the exclusion of everything else!\n\n## How strong are open models for agentic workflows?\n\nWe've created [`CodeAgent`](https://huggingface.co/docs/smolagents/reference/agents#smolagents.CodeAgent) instances with some leading models, and compared them on [this benchmark](https://huggingface.co/datasets/m-ric/agents_medium_benchmark_2) that gathers questions from a few different benchmarks to propose a varied blend of challenges.\n\n[Find the benchmarking code here](https://github.com/huggingface/smolagents/blob/main/examples/smolagents_benchmark/run.py) for more detail on the agentic setup used, and see a comparison of using LLMs code agents compared to vanilla (spoilers: code agents works better).\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/smolagents/benchmark_code_agents.jpeg\" alt=\"benchmark of different models on agentic workflows. Open model DeepSeek-R1 beats closed-source models.\" width=60% max-width=500px\u003e\n\u003c/p\u003e\n\nThis comparison shows that open-source models can now take on the best closed models!\n\n## Security\n\nSecurity is a critical consideration when working with code-executing agents. Our library provides:\n- Sandboxed execution options using [Blaxel](https://blaxel.ai), [E2B](https://e2b.dev/), [Modal](https://modal.com/), Docker, or Pyodide+Deno WebAssembly sandbox\n- Best practices for running agent code securely\n\nFor security policies, vulnerability reporting, and more information on secure agent execution, please see our [Security Policy](SECURITY.md).\n\n## Contribute\n\nEveryone is welcome to contribute, get started with our [contribution guide](https://github.com/huggingface/smolagents/blob/main/CONTRIBUTING.md).\n\n## Cite smolagents\n\nIf you use `smolagents` in your publication, please cite it by using the following BibTeX entry.\n\n```bibtex\n@Misc{smolagents,\n  title =        {`smolagents`: a smol library to build great agentic systems.},\n  author =       {Aymeric Roucher and Albert Villanova del Moral and Thomas Wolf and Leandro von Werra and Erik Kaunismäki},\n  howpublished = {\\url{https://github.com/huggingface/smolagents}},\n  year =         {2025}\n}\n```\n","funding_links":[],"categories":["Coding Tools for Economists","AI Agent Frameworks","Agentic Frameworks","Python","Agent Development Frameworks","LLM","🕵️ 智能体（Agents）","🌟 Core Frameworks","Frameworks","🔧 Projects","A01_文本生成_文本对话","智能体 Agents","Agent Integration \u0026 Deployment Tools","others","🧱 Agent Frameworks","HarmonyOS","📋 Contents","Librerías para usar NLP en español","Agent Categories","2. Libraries \u0026 Frameworks","🤖 Agent Frameworks \u0026 Multi-Agent Systems","Frameworks \u0026 Libraries","Tools and Code","Agent Frameworks","🤖 AI Agent Frameworks","Multi-Agent Orchestration","3）参考实现与开源工具（GitHub）","Platforms \u0026 Frameworks","🧩 Agent Frameworks \u0026 Dev Libraries","LLM Frameworks"],"sub_categories":["AI Agent Frameworks","General Agent Frameworks","主流 Agent 框架","Research Assessment","大语言对话模型及数据","AI Agent Development","Lightweight / Minimalist","Windows Manager","🤖 4. Agentic AI \u0026 Multi-Agent Systems","Modelos de Embeddings para Sentence Similarity y Semantic Search","\u003ca name=\"Unclassified\"\u003e\u003c/a\u003eUnclassified","Python","Advanced Agent Orchestration","Single Agent","Agent Frameworks","Tools","教程与拆解","Self-hosted Agent Frameworks","Multi-Agent Orchestration"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuggingface%2Fsmolagents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuggingface%2Fsmolagents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuggingface%2Fsmolagents/lists"}