smolagents
Small Hugging Face library for agents that act by writing Python code, with sandboxed execution options.
About
Hugging Face designed smolagents around one idea: let the model express each step as a short Python snippet instead of a JSON tool call. Its CodeAgent runs a reason-act loop in which generated code calls your tools as ordinary functions, so loops, variables, and several tool calls fit into a single step, and a ToolCallingAgent covers providers that prefer structured calls. All agent logic lives in one readable module, yet multi-agent hierarchies, image inputs, and tools pulled from MCP servers, LangChain, or Hub Spaces are supported. Model classes cover local Transformers, vLLM, and MLX, Hugging Face Inference Providers, OpenAI-compatible servers such as Ollama, Azure OpenAI, Amazon Bedrock, and LiteLLM. Since the agent runs code it wrote, the maintainers stress that the bundled local Python executor is not a real security boundary and point users to Docker, E2B, Modal, or Blaxel sandboxes. Install from PyPI on Python 3.10 or newer; the smolagent and webagent commands provide a CLI and a browser-driving agent. Apache 2.0 permits commercial use. A good fit for Python developers who want to read and modify the whole agent loop.
Should you use smolagents?
Pick it when
Choose smolagents when you want a small, readable library where agents write their actions as Python code, run in E2B, Modal, or Docker sandboxes, and share tools through the Hugging Face Hub with any model.
Look elsewhere when
Skip it if you need production plumbing such as session persistence and human approval steps, which pydantic-ai, agno, or openai-agents-sdk include. Code agents also need a sandbox you trust, which adds setup.
Alternatives to smolagents
- OpenAI Agents SDK
JSON-style tool calls with handoffs, sessions, and tracing built in; more production features, less of the code-as-action approach.
- Pydantic AI
Type-safe agents with durable execution and evals; heavier than smolagents, better when outputs must validate against schemas.
- E2B
The sandbox smolagents can run code in; use it directly if you only need safe execution for an agent loop you wrote yourself.
- Deep Agents
Adds planning, a virtual filesystem, sub-agents, and summarization for long tasks; more scaffolding where smolagents stays minimal.
Reviews (0)
Leave a Review
No reviews yet. Be the first to review!
Details
- Category
- AI Agents & Orchestration
- Price
- Free
- Platform
- Local/Desktop
- Difficulty
- Easy (2/5)
- License
- Apache-2.0
- Added
- Apr 3, 2026