What Is smolagents?

Most agent frameworks have the model call tools by emitting JSON. smolagents, Hugging Face's deliberately tiny library, makes the model write Python code instead — "agents that think in code." That one design choice, plus a ruthless commitment to minimalism, is what the whole library is about, and it turns out to matter more than it sounds.

smolagents is a minimal agent library from Hugging Face, and its tagline says it plainly: a barebones library for agents that think in code. Two things define it — an extreme commitment to minimalism (its core is only around a thousand lines), and a distinctive code-first approach where agents express their actions as executable Python rather than structured JSON tool calls. This series covers it concept by concept; this first post establishes what it is, the minimalism, and the code-agent idea that sets it apart.

What smolagents is

smolagents is a small, open-source Python library for building agents. You give an agent a model and some tools, and it runs the agent loop — but its defining characteristic is how the agent takes actions: by writing and executing code. It’s deliberately minimal (the core logic is tiny), model-agnostic (works with Hugging Face models, and others via integrations), and it emphasizes the code agent as its primary abstraction, while also supporting traditional tool-calling agents.

The two things to hold from the start: minimalism (it’s small, simple, and easy to understand — you can read the whole core) and code-first (agents act by writing code, which is the library’s signature idea and the reason it exists). Everything else follows from these.

The minimalism

smolagents’s first defining trait is how small it is. Where some agent frameworks are sprawling toolkits, smolagents’s core is on the order of a thousand lines — small enough to read and understand in full. This minimalism is a deliberate philosophy, and it has real consequences:

This is a different value proposition from the batteries-included frameworks (LangChain) or the philosophy-heavy ones — smolagents’s pitch is “small, simple, readable, does the essential thing well.” If you value understanding your tools and minimal overhead, the minimalism itself is a reason to reach for it. It reflects a real design stance: an agent doesn’t need a huge framework; it needs a model, tools, and a loop — kept small.

The code-agent idea

smolagents’s second and more distinctive trait is the code agent — the idea that an agent should express its actions as executable code rather than as structured (JSON) tool calls. This is the library’s signature, so it’s worth stating clearly up front (the next posts go deep):

“Agents that think in code” means exactly this: the agent reasons and acts by writing code. Instead of “I want to call the search tool with this query” as JSON, the agent writes results = search("query") as code — and can then loop over results, store them in variables, call another tool with them, and do real logic, all in one action. This turns out to be more powerful than it sounds, and the reasons (efficiency, expressiveness, composability) are the subject of the next posts. For now, the key point: smolagents’s identity is that agents act by writing code, and that choice ripples through everything.

Why code agents matter (the preview)

The code-agent approach isn’t a quirk — Hugging Face’s argument (with supporting evidence) is that it’s genuinely better for many tasks, which the next post details. In brief:

The trade-off, also covered ahead, is security — executing model-written code is dangerous and must be sandboxed (its own post). But the core claim is that letting agents act in code is a powerful default, and smolagents is built around it. This is why smolagents is more than “a small library” — it’s a small library making a specific, evidence-backed bet about how agents should act.

When to use smolagents

Like any framework, it fits some situations (the agent-framework comparison covers the broader choice):

The through-line: smolagents is Hugging Face’s minimal, code-first agent library — small enough to understand fully, built on the powerful idea that agents should think and act in code. The next post goes deep on that code-agent idea, the heart of the library.

Key takeaways

Further reading

Sources & References

Official smolagents docs
The smolagents library