Capability · Framework — agents
smolagents
smolagents is Hugging Face's compact agent library. Its main idea is CodeAgents — agents that reason by writing Python code snippets that call tools, rather than emitting JSON function calls. It's deliberately tiny (~1000 LOC), supports any LLM through Hugging Face's inference API or LiteLLM, and runs tools safely in a sandboxed Python interpreter or via E2B.
Framework facts
- Category
- agents
- Language
- Python
- License
- Apache 2.0
- Repository
- https://github.com/huggingface/smolagents
Install
pip install smolagents Quickstart
from smolagents import CodeAgent, InferenceClientModel, DuckDuckGoSearchTool
model = InferenceClientModel()
agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)
agent.run('How many seconds in a leap year?') Alternatives
- LangGraph — lower-level graph framework
- Agno — Python performance-focused alternative
- CrewAI — role-based alternative
- Pydantic AI — typed alternative
Frequently asked questions
Why write Python instead of JSON tool calls?
Code-as-action agents can compose multi-step logic in one pass — loops, conditionals, variable reuse — which JSON function-call agents can only express as separate back-and-forth turns. The smolagents/HF paper reports fewer steps and higher task success on many benchmarks.
Is it safe to run generated Python?
smolagents ships a local sandboxed Python interpreter that restricts imports and dangerous builtins, and it integrates with E2B for remote sandboxing. Still — treat it like any code execution: don't expose production secrets to untrusted prompts.
Sources
- smolagents — docs — accessed 2026-04-20
- smolagents — GitHub — accessed 2026-04-20