30.6K ·GitHub
What is this?
smolagents is a lightweight Python library for building AI agents that write their actions as Python code instead of JSON tool calls, letting you run powerful agents in just a few lines of code.
Is this a framework or a bare library?
It is a barebones library, not a heavy framework: the core agent logic fits in about 1,000 lines of code with minimal abstractions on top of raw Python.
How do I get an agent running?
Install the package with a default toolset via pip, then instantiate a CodeAgent or ToolCallingAgent with your chosen model and tools and call run(). You can also skip Python entirely and launch agents from the CLI with the 'smolagent' or 'webagent' commands.
Which LLMs can I plug in?
Any LLM works: a local transformers or ollama model, a Hugging Face Hub inference provider, or OpenAI, Anthropic and many others through the built-in LiteLLM integration.
Is it safe to let the agent execute the code it writes?
Not by default - the built-in LocalPythonExecutor only applies partial restrictions and can be bypassed, so it must not be treated as a security boundary; for real safety you need a sandbox like E2B, Blaxel, Modal, or Docker.
What's the difference between CodeAgent and ToolCallingAgent?
CodeAgent writes its actions as Python code snippets (tool calls become function calls), while ToolCallingAgent writes actions as JSON/text blobs like a classic ReAct agent - you pick whichever style fits your use case.
Can I reuse tools from other ecosystems?
Yes, smolagents is tool-agnostic: you can use tools from any MCP server, pull tools from LangChain, or even use a Hugging Face Hub Space as a tool.
Does it handle more than text?
Agents are modality-agnostic and support text, vision, video, and even audio inputs.
Why write actions as code instead of JSON tool calls?
Benchmarks cited in the README show code-based actions use about 30% fewer steps (and thus fewer LLM calls) than the industry-standard JSON tool-calling approach, while reaching higher performance on difficult tasks.
Can I share agents or tools I build?
Yes, smolagents has Hub integrations so you can push or pull tools and whole agents to/from the Hugging Face Hub as Space repositories for instant sharing.
What are similar projects?
Raven, Agentlas-OS, turnstone, DeLM, ai-agents-the-definitive-guide, open-swe, RSIGame, qwen-code
Which topics is it in?
llm-agents, transformers, langchain, autonomous-agents, multimodal, sandbox, agentic-ai, huggingface, cloud, multi-agent, agents, openai