liveBook · Manning

Smolagents

As explained in Domain-Specific Small Language Models

A Hugging Face library for building AI agents with code-based or tool-calling workflows.

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

How Domain-Specific Small Language Models covers it

How deep it goes
Explains agent types, execution safety, tool definition, model backends, and multistep workflows, but does not detail framework internals.
Examples
Demonstrates travel planning, flight search, seat selection, mocked booking, Hugging Face models, and a local Ollama model.
What you can do after
Builds a working CodeAgent with custom tools and runs multistep tasks against hosted or locally served language models.
How it connects
Connects CodeAgent with ReAct, Python tools, Transformers, LangChain, LangGraph, MCP, LiteLLM, Ollama, and model endpoints.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.