gitmyhub

smolagents

Python ★ 28k updated 4d ago

🤗 smolagents: a barebones library for agents that think in code.

Lightweight Python library for building AI agents that reason about tasks and execute them by writing and running code, with support for custom tools and any language model.

PythonLanguage ModelsOpenAI APIsetup: moderatecomplexity 3/5

smolagents is a small Python library from Hugging Face for building "agents" — programs that use a large language model to plan and act step by step, calling tools and reading their results. Its central idea, stated in the project's tagline, is "agents that think in code": instead of producing structured tool-call commands, the agent writes short snippets of code that perform the actions, and that code is what gets executed. Because letting a language model run arbitrary code is risky, smolagents supports running the generated code inside sandboxed environments such as Blaxel, E2B, Modal, Docker, or a Pyodide and Deno WebAssembly sandbox. The library keeps its abstractions deliberately thin — the core agent logic is described as fitting in roughly a thousand lines of code — which makes it easier to read and adapt. It is model-agnostic: you can plug in a local model through transformers or ollama, use providers from the Hugging Face Hub, or reach OpenAI, Anthropic and many others through a LiteLLM integration. It is also modality-agnostic, supporting text, vision, video and audio inputs, and tool-agnostic, so tools can come from an MCP server, from LangChain, or from a Hugging Face Hub Space. You would reach for smolagents when you want to prototype or run an LLM-driven assistant that has to use external tools — searching the web, calling APIs, browsing pages — without committing to a heavy framework. The package ships with a default toolkit, a quick example built around a web search tool, and two command-line entry points, "smolagent" for a general code-writing agent and "webagent" for browsing the web.

Where it fits