smolagents
Trace Hugging Face smolagents runs with cetra from Python: agent steps, model calls and tools.
Install
Section titled “Install”pip install "cetra-sdk[smolagents]" "smolagents[openai]"Set up
Section titled “Set up”import os
import cetrafrom smolagents import CodeAgent, OpenAIServerModel, tool
cetra.init(instrument=["smolagents"])
@tooldef get_weather(city: str) -> str: """Look up the weather for a city.
Args: city: the city name """ return f"sunny in {city}"
model = OpenAIServerModel(model_id="gpt-4o-mini", api_key=os.environ["OPENAI_API_KEY"])agent = CodeAgent(tools=[get_weather], model=model, name="weather_agent")agent.run("What is the weather in Paris?")
cetra.flush()What you get
Section titled “What you get”- The run is an
agentspan named after the agent, with achainspan per step (Step 1,Step 2). - Each model call is an
llmspan with the messages, the token counts and the cost, computed from the built-in prices. - Each tool run is a
toolspan named after the tool’s class (SimpleTool,FinalAnswerTool); the tool’s own name stays in the span’s attributes.
Limits
Section titled “Limits”- Do not also enable
openai: each model call would be recorded twice and counted twice. - The agent span repeats the run’s total tokens; cetra counts tokens on model calls only, so nothing is counted twice.
- The fixture was captured with smolagents 1.26.0 and openinference-instrumentation-smolagents 0.1.50.
- If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.
- Online rules: score these traces automatically.