Source: smolagents docs: Index and Guided tour (Hugging Face)
smolagents overview and guided tour: CodeAgent vs ToolCallingAgent, model classes, tools, authorized imports, executors, final_answer_checks, managed agents, Gradio UI and Hub sharing.
Contents
- What: official documentation (index and guided tour), docs version v1.26.0
- Author: Hugging Face
- Date: read 2026-11-14 (v1.26.0 released on PyPI 2026-05-29)
- Original: https://huggingface.co/docs/smolagents/index, https://huggingface.co/docs/smolagents/guided_tour
Summary
smolagents is a minimal Python agent library whose distinctive feature is the CodeAgent, which writes its actions as Python code. A ToolCallingAgent covers conventional JSON tool calling. It is model-agnostic, tool-agnostic (MCP, LangChain, Hub Spaces) and integrates with the Hugging Face Hub for sharing tools and agents.
Key claims
- Agent logic fits in roughly a thousand lines; abstractions kept minimal.
CodeAgentstrengths: expressive control flow, composing tools, transforming results; weaknesses: syntax/runtime errors, less predictable, needs a secure executor.ToolCallingAgent: validated arguments and safer, but low expressivity. Docs suggest CodeAgent for problem-solving/chaining, ToolCallingAgent for atomic dispatch.- Model classes:
InferenceClientModel(HF Inference Providers),LiteLLMModel(100+ providers),OpenAIModel,AzureOpenAIModel,AmazonBedrockModel,TransformersModel,MLXModel; extra kwargs forwarded to the completion call;REMOVE_PARAMETERstrips defaults. - Imports in generated code are blocked unless listed in
additional_authorized_imports; submodules must be authorised explicitly (orpkg.*). executor_typecan switch execution to Blaxel, E2B, Modal or Docker.- Termination:
final_answercall ormax_steps;final_answer_checksvalidators can reject an answer and keep the run going. - Tools:
@tooldecorator (needs type hints and anArgs:docstring) orToolsubclass withname,description,inputs,output_type,forward; tool metadata is baked into the system prompt. - Multi-agent: give an agent
nameanddescriptionand pass it inmanaged_agentsof a manager agent (hierarchical). GradioUI(agent)for a chat UI;run(..., reset=False)keeps memory between tasks;agent.interrupt();push_to_hub/from_hub(..., trust_remote_code=True).- Ollama via LiteLLM needs a larger
num_ctxthan Ollama’s 2048 default.