SmolAgents
SmolAgents is Hugging Face's minimalist agent framework — the entire core is under 1,000 lines of Python. Instead of generating JSON tool calls, agents write and execute Python code that calls tools. This code-based reasoning lets agents use loops, conditionals, and composition naturally. MCP tools become callable Python functions in this code execution context.
Code-Based Reasoning with MCP Tools
Most agent frameworks have the LLM generate JSON tool calls. SmolAgents takes a different approach: the LLM generates Python code that gets executed. This is more expressive — the agent can write loops that call a tool multiple times, use conditionals to decide between tools, and compose results using standard Python.
MCP tools appear as Python functions in the execution sandbox. The agent writes result = mcp_tool("query") and it executes.
Features:
- Code agents — LLM generates executable Python instead of JSON tool calls
- Under 1,000 lines — entire framework is auditable and understandable
- Hugging Face Hub — share tools and agents on the Hub
- Sandboxed execution — code runs in a controlled environment
- Multi-model — any model on HF Hub, OpenAI, Anthropic
- Tool sharing — push/pull tools from the Hugging Face Hub
- Gradio UI — built-in web interface for agent interaction
Python Setup
1. Create a Token
In Vinkius Cloud, go to your server → Connection Tokens → Create. Copy the URL.
2. Add MCP Tools
from smolagents import CodeAgent, MCPClient
mcp = MCPClient(url="https://edge.vinkius.com/{TOKEN}/mcp")
agent = CodeAgent(tools=mcp.get_tools(), model=...)
agent.run("analyze the production metrics")3. Code-Based Execution
The agent writes Python code that calls MCP tools through natural code patterns.
FAQ
How is code-based reasoning different from JSON tool calls? The LLM writes Python that gets executed. It can use loops, conditionals, and composition — more expressive than single JSON tool calls.
Is the code execution safe? Yes. SmolAgents runs generated code in a sandboxed environment with configurable restrictions.
Can I share MCP tools on Hugging Face Hub? Yes. Tools can be pushed to and pulled from the Hub for community sharing.
Is SmolAgents free? Open-source under Apache 2.0. Free to use.