smolagents is a small Hugging Face Python library for building agents that plan, reason, select tools, and act across multistep tasks. It supports code-based workflows through CodeAgent and tool-calling workflows through ToolCallingAgent, with integrations spanning Hugging Face, OpenAI-compatible, LiteLLM, Ollama, and other model endpoints. section 13.4 section 13.5
Its practical design centers on the following capabilities:
- CodeAgent writes and executes Python snippets at each step, following a ReAct-style reasoning-and-acting loop instead of generating JSON instructions. section 13.4 section 13.5
- Tool functions become agent capabilities when defined with docstrings and type hints; custom tools extend the default toolset for domain-specific automation. section 13.5
- Local execution restricts agents to configured tools and safe functions, while Docker or E2B sandboxes provide safer options beyond personal devices. section 13.4
- Agents can chain tool outputs across a task, turning planning into operational sequences such as searching, selecting, and booking. section 13.4 section 13.5
Flight search, seat selection, and booking
A CodeAgent receives a request to find a flight from Dublin to New York and select a seat. Custom tools search flights, find a seat, and mock ticket booking; the resulting workflow reports a booked flight, seat, and ticket number. section 13.4
from smolagents import CodeAgent, HfApiModel
model_id = "<model_id>"
model = HfApiModel(model_id=model_id, token="<huggingface_api_token>")
agent = CodeAgent(tools=[], model=model, add_base_tools=True)
Shows the minimal model and CodeAgent setup; related listings demonstrate installation, task execution, custom tools, and local-model configuration. section 13.4
