Your LLM agent, but it writes Python instead of JSON
A barebones library that makes LLM agents reason and act by writing Python code instead of JSON, claiming fewer steps and better benchmark performance.

What it does
smolagents is a stripped-down Python library for running LLM agents. Its core logic fits in about 1,000 lines, and its flagship CodeAgent makes the model write Python snippets to call tools and reason, rather than emitting JSON action blobs. It is model-agnostic—supporting local transformers, Ollama, OpenAI, Anthropic, Azure, Bedrock, and others via LiteLLM—and handles text, vision, video, and audio inputs.
The interesting bit
By treating Python as the agent’s native reasoning language, CodeAgent can loop over search results or chain tool calls in a single action block. The project cites research that this approach uses 30% fewer LLM calls and outperforms JSON-based tool calling on difficult benchmarks. The obvious catch is security: arbitrary code execution requires a real sandbox, and the built-in local executor explicitly admits it is not a security boundary.
Key highlights
- Core agent logic in roughly 1,000 lines of Python
CodeAgentwrites executable Python; a classicToolCallingAgentis available for JSON-style actions- Plugs into virtually any LLM provider, including local models and major cloud APIs
- Consumes tools from MCP servers, LangChain, or Hugging Face Hub Spaces
- Includes CLI commands for generalist agents and web browsing
Caveats
- The built-in
LocalPythonExecutorapplies restrictions but is explicitly not a sandbox and can be bypassed; safe deployment requires external isolation such as Docker, E2B, Modal, or Blaxel
Verdict Worth exploring if you want agent logic you can read and hack on, or if your tasks benefit from multi-step Python reasoning. Skip it if you need a fully managed, security-hardened platform without extra infrastructure.
Frequently asked
- What is huggingface/smolagents?
- A barebones library that makes LLM agents reason and act by writing Python code instead of JSON, claiming fewer steps and better benchmark performance.
- Is smolagents open source?
- Yes — huggingface/smolagents is open source, released under the Apache-2.0 license.
- What language is smolagents written in?
- huggingface/smolagents is primarily written in Python.
- How popular is smolagents?
- huggingface/smolagents has 28.5k stars on GitHub and is currently holding steady.
- Where can I find smolagents?
- huggingface/smolagents is on GitHub at https://github.com/huggingface/smolagents.