Smolagents

Trace Smolagents workflows with Respan.
  1. Sign up — Create an account at platform.respan.ai
  2. Create an API key — Generate one on the API keys page
  3. Add credits or a provider key — Add credits on the Credits page or connect your own provider key on the Integrations page

Add the Docs MCP to your AI coding tool to get help building with Respan. No API key needed.

1{
2 "mcpServers": {
3 "respan-docs": {
4 "url": "https://docs.respan.ai/mcp"
5 }
6 }
7}

What is Smolagents?

Smolagents is HuggingFace’s lightweight agent framework that lets you build agents with code-based actions. It focuses on simplicity and supports both code agents and tool-calling agents.

Setup

1

Install packages

$pip install respan-ai openinference-instrumentation-smolagents smolagents
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
3

Initialize and run

1import os
2from dotenv import load_dotenv
3
4load_dotenv()
5
6from respan import Respan
7from respan_instrumentation_openinference import OpenInferenceInstrumentor
8from openinference_instrumentation_smolagents import SmolagentsInstrumentor
9from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel
10
11# Initialize Respan with Smolagents instrumentation
12respan = Respan(
13 instrumentations=[
14 OpenInferenceInstrumentor(instrumentor=SmolagentsInstrumentor())
15 ]
16)
17
18# Create a model and agent with tools
19model = LiteLLMModel(model_id="gpt-4o-mini")
20agent = CodeAgent(
21 tools=[DuckDuckGoSearchTool()],
22 model=model,
23)
24
25# Run the agent
26result = agent.run("What is the latest news about AI agents?")
27print(result)
28
29respan.flush()
4

View your trace

Open the Traces page to see your Smolagents workflow with planning steps, code execution, and tool calls.

What gets traced

All Smolagents operations are auto-instrumented:

  • Agent planning and reasoning steps
  • Code generation and execution
  • Tool calls and results
  • LLM calls with model, tokens, and input/output
  • Multi-step task execution

Traces appear in the Traces dashboard.

Learn more