Choose a setup method
Start with one method for a call path. Combining SDK tracking with framework
OpenTelemetry on the same call can create duplicate interactions.
Recommended: Agnost AI skill
Recommended. Choose this path when you want your coding agent to inspect the
project, select a supported transport, make the smallest instrumentation change,
send a test event, and verify that it reached Agnost AI.
Manual setup: Agnost AI SDK
agnost.shutdown() once when the application exits, not after each request.
Manual setup: OpenTelemetry
smolagents uses the OpenInference instrumentoropeninference-instrumentation-smolagents for OpenTelemetry tracing. It traces each agent run, each step, each model call, and each tool call. Send those spans to Agnost AI with a standard OTLP exporter.
Install
litellm extra provides LiteLLMModel, which this example uses to call Claude. Any smolagents model class works the same way.
Setup
using_attributes puts session.id and user.id on every span created inside the block. Agnost AI groups all runs with the same session.id into one conversation and attributes it to user.id. Wrap each request in its own using_attributes block with that request’s session and user. Pass reset=False to keep the agent’s memory between turns of the same session.
CodeAgent is traced the same way. Call SmolagentsInstrumentor().instrument() once at startup, before any agent runs.
What appears in Agnost AI
- Conversations: one per
session_id. The raw value is kept asoriginal_conversation_idin the conversation metadata. - Users: the
user_idfromusing_attributes. - Messages: one turn per
agent.run(...)call, from the root<agent name>.runspan. The answer is the agent’s final answer. The user side shows smolagents’ run arguments as JSON, with your prompt in thetaskfield. - Events: the agent run,
Step Nspans, model calls such asLiteLLMModel.generatewith token counts, and tool calls with arguments and results.
Verify
Run oneagent.run call, wait about 30 seconds, then open Conversations in Agnost AI. Confirm the conversation shows your user_id, the task and the final answer, and a tool event for get_weather with arguments and a result.
Troubleshooting
- Nothing arrives: confirm the exporter header is
X-Agnost-Org-IDand the endpoint ends in/v1/traces. Short scripts must callprovider.force_flush()before they exit. - Each run is its own conversation, or the user is empty: the run happened outside a
using_attributes(session_id=..., user_id=...)block. - Tool events are named
SimpleTool: OpenInference names tool spans after the tool’s Python class, and every function decorated with@toolis aSimpleTool. The real tool name is in the event metadata astool.name. SubclassToolwith a descriptive class name if you need distinct names in the events list. - No spans at all: call
SmolagentsInstrumentor().instrument()before you create or run agents.
References
- smolagents: Inspecting runs with OpenTelemetry
- smolagents models
- OpenInference smolagents instrumentor
Next steps
- Conversations: review the complete smolagents session.
- Events: inspect agent steps, model calls, and tool calls.
- Patterns: organize production conversations by what users wanted.