huggingface/smolagents
🤗 smolagents: a barebones library for agents that think in code.
What it solves
smolagents is a lightweight library designed to build powerful AI agents that can execute tasks by writing and running Python code. It simplifies the process of creating agents that are model-agnostic, tool-agnostic, and modality-agnostic, reducing the complexity of maintaining consistent formatting for code execution and system prompts.
How it works
The library provides two primary agent types: CodeAgent, which writes its actions as Python code snippets (using a ReAct loop), and ToolCallingAgent, which uses standard JSON/text blobs for actions. The CodeAgent treats tool calls as Python function calls, allowing it to perform complex operations (like loops) in a single action, which is reported to use 30% fewer LLM calls and improve performance on difficult benchmarks.
To ensure security, the library supports executing code in sandboxed environments such as E2B, Blaxel, Modal, or Docker, as the built-in local executor is not a security boundary.
Who it’s for
Developers who want a minimal, jargon-light framework for building agentic systems without heavy abstractions, as well as those who want to leverage open-source models for agentic workflows.
Highlights
- Code-First Actions: Agents can write Python code to interact with tools, increasing efficiency and performance.
- Model Agnostic: Supports any LLM via Hugging Face Hub, local
transformersorollamamodels, OpenAI, Anthropic, and others via LiteLLM. - Tool Agnostic: Integrates with MCP servers, LangChain tools, and Hugging Face Hub Spaces.
- Multimodal Support: Supports text, vision, video, and audio inputs.
- Hub Integration: Ability to share and pull tools or agents directly from the Hugging Face Hub.
- CLI Tools: Includes
smolagentfor generalist tasks andwebagentfor web-browsing tasks using Helium.
Related
- Dispatch
- Project
- Project
- Project
- Project