smolagents is a Hugging Face library for building agents whose core logic fits in roughly 1,000 lines of code. Its distinguishing agent type, CodeAgent, follows a ReAct-style loop but writes each action as a Python code snippet rather than a JSON tool-call blob, so several tool calls can be combined in one step. Cited results report that code actions use about 30% fewer steps than JSON tool calling and score higher on difficult benchmarks. A conventional ToolCallingAgent that emits JSON actions is also available.
Because agent-written code is executed, the library provides sandboxed execution through E2B, Blaxel, Modal, or Docker; the built-in LocalPythonExecutor applies restrictions but is not a security boundary. Models are pluggable: InferenceClientModel routes to Hugging Face inference providers, LiteLLMModel covers 100+ hosted models, OpenAIModel targets any OpenAI-compatible server, and TransformersModel, AzureOpenAIModel, and AmazonBedrockModel cover local and cloud alternatives.
Tools can come from MCP servers, LangChain, or Hugging Face Spaces, and agents and tools can be pushed to or pulled from the Hub. Agents accept text, vision, video, and audio inputs, and multi-agent hierarchies are supported. Two CLI entry points exist: smolagent runs a multi-step CodeAgent with an interactive setup wizard, and webagent drives a browser through helium.
Features
- CodeAgent: writes actions as Python snippets executed in a ReAct loop until final_answer is called
- ToolCallingAgent: standard JSON tool-calling alternative
- Sandboxed execution: E2B, Blaxel, Modal, or Docker isolate agent-generated code
- Model classes: InferenceClientModel, LiteLLMModel, OpenAIModel, TransformersModel, AzureOpenAIModel, and AmazonBedrockModel
- Tool sources: MCP servers, LangChain tools, Hub Spaces, and a default toolkit including WebSearchTool
- Hub integration: pushtohub and from_hub share agents and tools as Hub repositories
- Multimodal inputs: text, vision, video, and audio
- Multi-agent hierarchies: agents can manage other agents
- CLI: smolagent for general tasks and webagent for browser automation
- Benchmarking: an included benchmark script compares open and closed models as code agents
Integrates with
E2B
Runs AI-generated code in isolated cloud sandboxes controlled from JavaScript or Python SDKs
LangChain
Framework for building LLM applications and agents from interoperable components and a large integrations library
LiteLLM
Open-source AI gateway exposing 100+ LLM providers through one OpenAI-compatible interface, as a Python SDK or self-hosted proxy
-
Ollama
Runs open large language models locally without an API key
Integrated by
OpenInference
OpenTelemetry auto-instrumentation that converts agent traces to OpenInference for Arize Phoenix / AX.
Phoenix
Open-source AI observability platform for tracing, evaluating, and troubleshooting LLM and agent applications
Tinyagentos
Self-hosted, framework-agnostic AI agent platform that runs on your own hardware with a browser desktop