smolagents
Most agent frameworks hand you a graph, a state object and a vocabulary to learn before your agent takes its first step. smolagents, from Hugging Face, makes the opposite bet: the loop that drives an agent is small, so the library around it should be small too — a working agent in a few lines, and a codebase you can read end to end in an afternoon.
The code-first twist
Its distinctive idea is the CodeAgent: instead of emitting a JSON tool call, the model writes a short snippet of Python that calls the tools directly, and the runtime executes it. One snippet can loop, branch and chain three tools together, collapsing several round trips into a single step. The trade is obvious — executing model-written code needs a sandbox, so snippets run in a restricted interpreter or a container (E2B, Docker). A conventional ToolCallingAgent is there too, for when structured calls are the safer fit.
What you get, and give up
The shape of the trade:
- Model-agnostic — a Hugging Face Inference endpoint, a local transformers model or a hosted API, behind one interface.
- Tools as plain functions — a decorated Python function is a tool; so is anything shared on the Hub.
- Almost no state machinery — no durable execution, no checkpoints, no graph to resume from after a crash.
Why it matters
smolagents is what you reach for when the framework should get out of the way: prototypes, research experiments, and agents whose control flow is genuinely simple. Once a run has to survive a restart, pause for human approval, or coordinate several agents, a heavier framework such as LangGraph starts earning its weight.
smolagents is Hugging Face's minimal agent framework: a thin wrapper around the plan–act–observe loop, with an agent defined in a handful of Python calls. Its CodeAgent has the model write Python that invokes tools directly rather than emitting structured tool calls, collapsing multi-tool work into one execution. It suits prototypes and simple control flow. Because model-written code is executed, sandboxing is mandatory, and it offers no durable state or checkpointing.
Some toolkits for building AI assistants are like a whole workshop: powerful, but you spend a week learning where everything is kept. smolagents is the pocket toolkit — a few parts, laid out plainly, enough to build something that works today.
It comes from Hugging Face, and its neat trick is to let the AI write a few lines of ordinary computer code to get a job done, instead of filling in a rigid form for every single action. That means fewer back-and-forth rounds and less fuss.
The catch is that code written by an AI has to run somewhere safe, walled off from everything else. And for long, heavy jobs that must survive a crash, you will want something sturdier.