Using Opik with Smolagents
Opik integrates seamlessly with Smolagents, a framework from HuggingFace to create Agents. The integration leverages Opik’s built-in OpenTelemetry support.
Creating an account on Comet.com
Comet provides a hosted version of the Opik platform, simply create an account and grab your API Key.
You can also run the Opik platform locally, see the installation guide for more information.
Preparing our environment
The Opik integration supports all Smolagents clients, for this demo we will be using the OpenAI client and will therefore set our OpenAI API keys.
We now need to configure the OpenTelemetry environment variables:
Note 1: The projectName
and Comet-Workspace
headers are optional and can be set to Default
and default
respectively.
Note 2: If you are using the self-hosted version of Opik, you will need to update the environment variables defined above. You can learn more about this in the Opik OpenTelemetry documentation.
Setting up OpenTelemetry for SmolAgents
To set up the Telemetry, you will need to add the following to your code:
Using the Smolagents library
Now that everything is set up, we can use the Smolagents library and track the corresponding traces in Opik:
As we have configured the OpenTelemetry logging, the agent execution and all it’s intermediate steps will be logged in Opik: