Favicon of smolagents

smolagents

An open-source Python AI agent library with local models through Transformers or Ollama, cloud API support, and Docker sandboxing.

Screenshot of smolagents website

smolagents is an open-source Python library for developers building AI agents that carry out tasks by writing and executing Python. Its CodeAgent can combine tool calls with loops, conditionals, and calculations in one action. This approach suits tasks that need several operations, rather than a single model response.

You can run models locally through Transformers or Ollama, or connect to Hugging Face inference providers, OpenAI, Anthropic, and other services through LiteLLM. Local model inference runs on your hardware; choosing a hosted provider sends model requests to that service. Code execution has a separate choice: Docker provides self-hosted container isolation, while E2B, Blaxel, and Modal provide managed cloud sandboxes. The local Python executor isn't a security boundary for untrusted code.

The library also includes ToolCallingAgent for conventional JSON or text tool calls, plus support for multi-agent hierarchies. Agents can accept images, video, and audio as well as text. They can use tools from MCP servers or LangChain, and call Hugging Face Spaces as tools. Hugging Face Hub integration lets developers share and load agents and tools as Gradio Spaces.

The framework keeps its abstractions close to Python, which makes it a fit for developers who want to inspect or adapt the agent logic. Command-line utilities support general agent tasks and web agents. The code is available under the Apache 2.0 license.

Similar to smolagents