SmoLagents

SmoLagents

SmoLagents is a minimalist yet powerful framework for building AI agents. It's designed to be simple, with the core logic fitting in ~1,000 lines of code, while supporting code-based agents, multiple LLM providers, and versatile tool integration.

What is SmoLagents

SmoLagents is a minimalist library designed to build powerful AI agents with minimal complexity. The name 'Smol' (small) emphasizes its lightweight nature - the core agent logic fits in approximately 1,000 lines of code. Despite its simplicity, SmoLagents enables developers to create sophisticated AI agents that can solve complex tasks by writing and executing code, using tools, and orchestrating multi-agent systems. The framework is built with flexibility in mind, supporting any large language model (LLM) including DeepSeek models, and allowing integration with various tools and modalities including text, vision, and audio inputs.

Core Features

Simplicity First

Minimal abstractions with core logic contained in ~1,000 lines of code, making it easy to understand and customize.

Code-Centric Agents

First-class support for Code Agents that write their actions as Python code rather than structured text, improving efficiency by up to 30%.

Model Agnostic

Works with any LLM, whether it's a local transformers model, Ollama, DeepSeek models via providers, or APIs from OpenAI, Anthropic, and others.

Multi-modal Support

Handles text, vision, video, and audio inputs, enabling agents to process and respond to different types of data.

Secure Code Execution

Provides options for secure code execution including sandboxed environments via E2B or Docker to mitigate security risks.

Hugging Face Hub Integration

Share and reuse tools, agents, and other components through the Hugging Face Hub ecosystem.

How to Use

SmoLagents also offers convenient command-line interfaces (CLI) for running agents directly from the terminal. The 'smolagent' command runs a generalist CodeAgent that can be equipped with various tools, while 'webagent' is specifically designed for web browsing tasks with visual capabilities.

Step 1: Installation

Install the package via pip with 'pip install smolagents' to get started quickly.

Step 2: Define Your Agent

Create an agent instance by specifying the model and tools it should use (e.g., 'CodeAgent(tools=[DuckDuckGoSearchTool()], model=model)').

Step 3: Run Tasks

Execute tasks by calling the run method with your prompt (e.g., 'agent.run("How many seconds would it take for a leopard to run through Pont des Arts?")').

Integration with DeepSeek Models

Here's a simple example of using a DeepSeek model with SmoLagents: ```python from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel model = HfApiModel( model_id="deepseek-ai/DeepSeek-R1", provider="together", ) agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=model) agent.run("Research the latest advancements in quantum computing and summarize them.") ```

Direct DeepSeek Model Support

SmoLagents easily integrates with DeepSeek models through various providers like Together AI and other inference endpoints.

Performance on Agent Benchmarks

DeepSeek models have demonstrated strong performance in agentic workflows, competing with leading closed-source models.

Flexible Configuration

Configure DeepSeek models with different parameters like temperature and max tokens to optimize agent performance for specific tasks.

Advanced Capabilities

Multi-Agent Systems

Create and orchestrate multiple agents working together on complex tasks, with different roles and responsibilities.

Agentic RAG

Combine Retrieval-Augmented Generation with agent capabilities to build more sophisticated knowledge systems.

Web Browser Automation

Use vision-enabled agents to navigate and interact with web pages, extracting information and performing actions.

Self-correcting Text-to-SQL

Build agents that can generate, test, and refine SQL queries automatically based on natural language requests.

Memory Management

Implement sophisticated memory systems for agents to retain and utilize information across multiple interactions.

Technical Architecture

SmoLagents implements a ReAct (Reasoning and Acting) loop at its core. For CodeAgents, this involves generating Python code snippets that call tools as functions, executing the code securely, and using the results to inform the next steps. This approach has been shown to be more efficient than traditional tool-calling methods, using 30% fewer steps and achieving higher performance on challenging benchmarks. The library also supports the more conventional ToolCallingAgent that uses structured text/JSON for tool calls, though CodeAgent is generally recommended for most use cases.

FAQ

Q: How does SmoLagents compare to other agent frameworks?

A: SmoLagents prioritizes simplicity and minimalism while still offering powerful capabilities. With core logic in just ~1,000 lines of code, it's more transparent and hackable than many alternatives, while still supporting advanced features like code execution and multi-agent systems.

Q: Is code execution secure in SmoLagents?

A: SmoLagents provides multiple options for secure code execution. You can use a secure Python interpreter for basic protection, or leverage sandboxed environments through E2B or Docker for more robust isolation from your system.

Q: Which language models work best with SmoLagents?

A: SmoLagents is designed to work with any LLM. Benchmark testing shows that modern open-source models like DeepSeek can now compete with closed-source alternatives in agentic workflows, particularly when using the CodeAgent approach.

Q: Can I extend SmoLagents with custom tools?

A: Yes, SmoLagents makes it easy to create and integrate custom tools. You can define your own tools as Python functions and provide them to the agent during initialization.

Q: How do I share my SmoLagents creations?

A: SmoLagents integrates with the Hugging Face Hub, allowing you to easily share and reuse agents, tools, and other components with the 'push_to_hub' method (e.g., 'agent.push_to_hub("username/my_agent")').

Repository Data

Stars
14,322
Forks
1,254
Watchers
108
Latest Commit
unknown
Repository Age
unknown
License
Apache-2.0

Language Distribution

Python
99.9%
Makefile
0.1%

Based on repository file analysis