Framework · Orchestration Frameworks

smolagents

Provide a barebones (~1k LoC) Python library for multi-step ReAct agents whose default action format is executable Python code rather than JSON tool calls, with first-class sandboxed execution and Hugging Face Hub sharing.

Description

smolagents is Hugging Face's Apache-2.0 Python library for 'agents that think in code'. Its distinguishing design choice is CodeAgent: the LLM writes each action as a Python code snippet that is parsed and executed by a custom AST-walking interpreter (LocalPythonExecutor) or a remote sandbox (e2b, blaxel, modal, docker, wasm), with the print output returned as the observation for the next ReAct step. Alongside CodeAgent it also ships ToolCallingAgent for the conventional JSON tool-calling shape. The framework deliberately keeps abstractions minimal — the docs claim 'The logic for agents fits in ~thousand lines of code' — and integrates with the Hugging Face Hub for sharing agents and tools.

Solution

MultiStepAgent runs a textbook ReAct loop: SystemPromptStep + TaskStep go to memory, then while budget allows the agent serialises memory to chat messages, calls the Model, parses the completion into an action (Python code for CodeAgent, JSON tool call for ToolCallingAgent), executes the action (LocalPythonExecutor or remote sandbox), and records the result as an ActionStep observation. Iteration stops on final_answer or max_steps (default 20). An optional planning_interval inserts PlanningStep revisions without performing a tool call.

Primary use cases

  • code-as-action agents that emit Python instead of JSON tool calls
  • ReAct agents with sandboxed execution (local or e2b/modal/docker)
  • Hub-shareable agents and tools
  • minimal-footprint replacements for larger frameworks

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.