Under 1000 Lines, Code-As-Action, Actually Good
The agent framework space is a swamp of abstractions. LangChain has a class for everything. AutoGen has factories of factories. Then Hugging Face dropped smolagents — under a thousand lines of core code — and it's the first agent library I've used that doesn't make me want to claw my eyes out.
The Setup
Pip install, point it at any model (HF Inference, Anthropic, OpenAI, local llama.cpp), give it some tools. The killer idea is code-as-action: instead of forcing the model to emit JSON tool calls, the model writes actual Python that runs in a sandbox.
pip install smolagents
export ANTHROPIC_API_KEY=sk-...The Money Pattern
One CodeAgent, a list of tools, a run call. The model writes Python, the sandbox executes it, results loop back. This is wildly more expressive than JSON tool calling because the model can compose, branch, and transform results inline.
from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel
model = LiteLLMModel(model_id="anthropic/claude-opus-4-5")
agent = CodeAgent(
tools=[DuckDuckGoSearchTool()],
model=model,
additional_authorized_imports=["pandas", "numpy"],
)
result = agent.run(
"Find the top 3 Brisbane suburbs by hail damage claims in 2025 "
"and chart the monthly trend."
)
print(result)The Catch
Code-as-action means the model writes arbitrary Python. The default local executor is not a real sandbox. You want the E2B or Docker executor in production, not the in-process one. The library makes it easy but it's on you to flip the switch. I burned an afternoon on this — yes really.
The Verdict
smolagents is what LangChain wishes it had been. Lean, readable, single-file core. I'm using it for a marketing data agent that pulls BigQuery + Google Ads at Rebuild Relief and it took an afternoon to wire up. If you've been waiting for an agent framework you can actually read end-to-end, this is the one.