# smolagents

> Canonical: https://skillalmanac.com/glossary/smolagents | Verification status: pending | Index status: not offered to search engines

smolagents is an open-source Python library from Hugging Face for building and running AI agents in a few lines of code. Its CodeAgent writes its actions as Python code instead of JSON tool calls.

Also called: smol agents, hugging face smolagents, smolagents library, smolagents Python.

## In plain language

smolagents is a small Python toolkit, published by Hugging Face, for building AI agents: programs where a language model decides what to do next, such as searching the web or running a calculation. Its main idea is to let the model write its steps as short Python code rather than filling in a form for each tool. It works with many models, hosted or run locally. Its limitation is that code written by a model is code you did not review, so running it safely takes care. The documentation describes running it in a sandbox (an isolated environment) for that reason.

## Technical definition

smolagents is an Apache-2.0 Python library. Its CodeAgent has the model write each action as a Python snippet that calls tools, which the library executes, so loops, conditionals and nested calls can sit inside one action; a ToolCallingAgent offers the usual JSON or text tool-calling instead. The docs describe sandboxed execution through Modal, Blaxel, E2B or Docker. Models are pluggable: Inference providers on the Hub, API models through LiteLLM, or local models through Transformers or Ollama. Tools can come from an MCP server, from LangChain, or from a Hub Space. The code-action idea relates to the CodeAct paper (arXiv 2402.01030), which proposes executable Python code as a unified action space.

## How it shows up when you use agents

smolagents is a library you import in Python, not an application you open. It sits in the same place as other [agent frameworks](/glossary/ai-agent-framework): you give it a model and a list of tools, call run with a task, and it loops until the agent has an answer. The Hugging Face blog defines agents as programs where language model output controls the workflow, and describes agency as a spectrum.

Its distinctive choice is the code agent. Instead of emitting a JSON blob per [tool call](/glossary/tool-calling), the model writes a Python snippet, and the library runs it. The documentation notes this is agents that write their actions in code, not agents used to write code. The docs also offer a ToolCallingAgent for the usual JSON style, and a command-line tool for running agents without boilerplate.

What breaks when this is misunderstood: model-written code runs on your machine unless you isolate it. The documentation points to sandboxed execution through Modal, Blaxel, E2B or Docker. Before you run a code agent against real files or credentials, set that up, and keep secrets out of the environment it can reach.

Tools can come from an [MCP server](/glossary/mcp-server), from LangChain or from a Hub Space, so existing connectors may be reusable. Next action: run the quickstart with no tools, read what the agent wrote, then add one tool.

## Common confusions

- **smolagents versus a coding agent.** smolagents is a library for building agents. A coding agent such as Claude Code is a finished tool that edits your repository.
- **Code agent versus agent that writes code.** In smolagents a code agent writes its own actions as code. That differs from an agent whose task is to write software.
- **smolagents versus the Transformers library.** The blog describes smolagents as the successor to transformers.agents. They are separate packages.
- **Myth: model-agnostic means model-free.** The library works with many models, but an agent still needs one, hosted or local, and its quality depends on that model.

## Worked examples in this catalogue

### [How to Build an AI Agent: A Minimal Tool Loop](https://skillalmanac.com/learn/build-an-ai-agent)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A minimal agent built in Python around a tool-use loop, using Claude's Messages API documentation, with a check that it works and notes on where it breaks.

Why it exercises the concept: A library such as smolagents wraps this loop. Building the loop by hand first shows what the library does for you.

### [Open-source AI agents: criteria for comparing them](https://skillalmanac.com/learn/open-source-ai-agents-what-to-compare)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Criteria for comparing open-source AI agents on licence, permissions, tool connections and maintenance, with a test to run for each before installing.

Why it exercises the concept: smolagents is published under an open-source licence and can run code. Those are the licence and permission questions this guide asks of any open-source agent.

### [mcp-server-builder](https://skillalmanac.com/skills/skill-almanac/mcp-server-builder)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Helps an agent design a Model Context Protocol server correctly and validates its tool manifest.

Why it exercises the concept: The smolagents documentation says tools can come from any MCP server. A well-designed server is one source of tools for such an agent.

### [subagent-design](https://skillalmanac.com/skills/skill-almanac/subagent-design)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Decides what to delegate, then writes subagent definitions and briefs that work without the conversation.

Why it exercises the concept: smolagents documents multi-agent systems among its tutorials. Deciding which work to hand to a second agent is the design question this skill covers.

## Related terms

- [AI agent framework](https://skillalmanac.com/glossary/ai-agent-framework.md)
- [AI agent](https://skillalmanac.com/glossary/ai-agent.md)
- [Tool calling (function calling)](https://skillalmanac.com/glossary/tool-calling.md)
- [Model Context Protocol (MCP)](https://skillalmanac.com/glossary/model-context-protocol.md)
- [Hugging Face](https://skillalmanac.com/glossary/hugging-face.md)
- [LangChain](https://skillalmanac.com/glossary/langchain.md)

## Sources

- [smolagents documentation](https://huggingface.co/docs/smolagents/index), Hugging Face (accessed 2026-11-24)
- [huggingface/smolagents (GitHub repository)](https://github.com/huggingface/smolagents), Hugging Face (GitHub) (accessed 2026-11-24)
- [Introducing smolagents, a simple library to build agents](https://huggingface.co/blog/smolagents), Hugging Face (accessed 2026-11-24)
- [Executable Code Actions Elicit Better LLM Agents](https://arxiv.org/abs/2402.01030), arXiv (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above. Independent source and example-target verification is pending. [Glossary index](https://skillalmanac.com/glossary.md).
