Smolagents

Frameworks & SDKs 💻 Python ⚖️ Apache-2.0 🟢 Actively maintained
29.2k stars

smolagents is a lightweight Python library for building AI agents that write their actions as code. It simplifies creating powerful agents with minimal abstractions, supporting any LLM and tools from various sources. It is designed for developers who want to build agentic systems quickly and flexibly.

✨ Key features

  • CodeAgent writes actions as Python code snippets
  • Model-agnostic: supports local, cloud, and OpenAI-compatible LLMs
  • Tool-agnostic: integrates MCP, LangChain, Hub Spaces
  • Sandboxed execution via E2B, Blaxel, Modal, or Docker
  • Hub integrations to share and load agents and tools
  • CLI tools: smolagent and webagent for quick usage

🎯 Use cases

  • Automate web research and data extraction tasks
  • Build multi-step reasoning agents for complex queries
  • Create agents that interact with external APIs and tools
  • Develop vision or audio capable agents with multimodal inputs

📦 Installation

🧰 Requirements: Python environment with pip; optional API keys for cloud LLMs or sandbox providers.

pip install "smolagents[toolkit]"

🚀 Usage

from smolagents import CodeAgent, WebSearchTool, InferenceClientModel

model = InferenceClientModel()
agent = CodeAgent(tools=[WebSearchTool()], model=model, stream_outputs=True)

agent.run("How many seconds would it take for a leopard at full speed to run through Pont des Arts?")

⚠️ Good to know

The built-in LocalPythonExecutor is not a security sandbox and must not be used for untrusted code; use sandboxed execution options for security.

❓ FAQ

What is the difference between CodeAgent and ToolCallingAgent?

CodeAgent writes actions as Python code snippets, while ToolCallingAgent uses JSON/text blobs for tool calls. CodeAgent is shown to be more efficient and performant.

Can I use smolagents with any LLM?

Yes, smolagents is model-agnostic. It supports local models via transformers or ollama, many providers on the Hugging Face Hub, and any model from OpenAI, Anthropic, etc., via LiteLLM integration.

How do I ensure secure execution of agent code?

You should run agent code in a sandbox. smolagents supports managed cloud sandboxes (E2B, Blaxel, Modal) and self-hosted Docker. The built-in LocalPythonExecutor is not a security boundary.

Can I share my agent with others?

Yes, you can push your agent to the Hugging Face Hub as a Space repository using agent.push_to_hub(repo_id), and load it with agent.from_hub(repo_id).

📊 Repository

Stars★ 29,170
Forks🍴 2,921
Open issues🐛 775
Last commit🕒 Aug 25, 2026
Created📅 Dec 2024
Language💻 Python
License⚖️ Apache-2.0

🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.