smolagents
Hugging Face's minimal agent library where agents act by writing and running Python code.
smolagents is a small library built on one idea: instead of emitting structured tool calls, an agent writes Python code and runs it. Expressing actions as code lets a single step do more (loops, composition, logic) than a single tool call can.
It is intentionally tiny, integrates with the Hugging Face ecosystem, and runs generated code in a sandbox.
Where it fits
A fit for tasks where actions are naturally computational and a code-writing agent expresses them more cleanly than a chain of tool calls.
Where it does not fit
Running model-written code raises a real security surface: wrong for environments that cannot accept that, even sandboxed.
Alternatives to smolagents
The closest options on the map, and where each fits instead.
-
LangGraph Graph orchestration
Reach for LangGraph when an agent needs real branching (loops, retries, human-in-the-loop pauses) and you want that control flow written down explicitly.
Unlike smolagents Maturity: established
-
Pydantic AI Type-safe agent framework
A strong fit for Python teams who want agent code that is statically typed and whose outputs are validated by construction.
Pairs with
Commonly used alongside it.