30,295
stars
+96+104+608
3,208
forks
–
watchers
–
prs
–
issues
–
releases
–
discussions

README

--
    
    
    
    
    



  
    
    Agents that think in code!
  


smolagents is a library that enables you to run powerful agents in a few lines of code. It offers:

✨ Simplicity: the logic for agents fits in ~1,000 lines of code (see agents.py). We kept abstractions to their minimal shape above raw code!

🧑‍💻 First-class support for Code Agents. Our CodeAgent writes its actions in code (as opposed to "agents being used to write code"). To make it secure, we support executing in sandboxed environments via Blaxel, E2B, Modal, or Docker.

🤗 Hub integrations: you can share/pull tools or agents to/from the Hub for instant sharing of the most efficient agents!

🌐 Model-agnostic: smolagents supports any LLM. It can be a local transformers or ollama model, one of many providers on the Hub, or any model from OpenAI, Anthropic and many others via our LiteLLM integration.

👁️ Modality-agnostic: Agents support text, vision, video, even audio inputs! Cf this tutorial for vision.

🛠️ Tool-agnostic: you can use tools from any MCP server, from LangChain, you can even use a Hub Space as a tool.

Full documentation can be found here.

 [!NOTE]
 Check out our launch blog post to learn more about smolagents!

 Quick demo

First install the package with a default set of tools:
bash
pip install "smolagents[toolkit]"

Then define your agent, give it the tools it needs and run it!
py
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?")


https://github.com/user-attachments/assets/84b149b4-246c-40c9-a48d-ba013b08e600

You can even share your agent to the Hub, as a Space repository:
py
agent.push_to_hub("m-ric/my_agent")

 agent.from_hub("m-ric/my_agent") to load an agent from Hub


Our library is LLM-agnostic: you could switch the example above to any inference provider.


 InferenceClientModel, gateway for all inference providers supported on HF

py
from smolagents import InferenceClientModel

model = InferenceClientModel(
    model_id="deepseek-ai/DeepSeek-R1",
    provider="together",
)



 LiteLLM to access 100+ LLMs

py
from smolagents import LiteLLMModel

model = LiteLLMModel(
    model_id="anthropic/claude-4-sonnet-latest",
    temperature=0.2,
    api_key=os.environ["ANTHROPIC_API_KEY"]
)



 OpenAI-compatible servers: Together AI

py
import os
from smolagents import OpenAIModel

model = OpenAIModel(
    model_id="deepseek-ai/DeepSeek-R1",
    api_base="https://api.together.xyz/v1/",  Leave this blank to query OpenAI servers.
    api_key=os.environ["TOGETHER_API_KEY"],  Switch to the API key for the server you're targeting.
)



 OpenAI-compatible servers: OpenRouter

py
import os
from smolagents import OpenAIModel

model = OpenAIModel(
    model_id="openai/gpt-4o",
    api_base="https://openrouter.ai/api/v1",  Leave this blank 

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON