smolagents

smolagents

By Hugging Face

Hugging Face's minimal library for agents that act by writing and running code

v1.26.02026-05-29PythonApache-2.0
28.5k Completely free Open source

Doc version 1.0 · Updated

Related tools

Overview

smolagents is a deliberately tiny library from Hugging Face — the agent logic fits in roughly a thousand lines — built around code agents that take actions by writing and running Python.
It is model-agnostic: local transformers, Hugging Face Hub models, or any provider through LiteLLM.

flowchart LR
  task[task] --> agent[CodeAgent]
  agent --> code[writes Python]
  code --> run[executes]
  run --> agent
  agent --> out[answer]

The Code samples tab shows a code agent backed by LiteLLM.

When to use it

Reach for smolagents when you want a minimal, hackable agent loop, or when code-writing actions suit the task (math, data wrangling, multi-step tool use) better than JSON function calls.