How to use the SmolagentsInstrumentor to trace smolagents by Hugging Face
smolagents is a minimalist AI agent framework developed by Hugging Face, designed to simplify the creation and deployment of powerful agents with just a few lines of code. It focuses on simplicity and efficiency, making it easy for developers to leverage large language models (LLMs) for various applications.Phoenix provides auto-instrumentation, allowing you to track and visualize every step and call made by your agent.
Add your OpenAI API key as an environment variable:
export OPENAI_API_KEY=[your_key_here]
Connect your application to Phoenix with the register function:
Create & Run an Agent
Create your Hugging Face Model, and at every run, traces will be sent to Phoenix.
from smolagents import CodeAgent, OpenAIServerModelmodel = OpenAIServerModel(model_id="gpt-4o-mini")agent = CodeAgent(tools=[], model=model)print(agent.run("Why is the ocean salty? Answer in two sentences."))
Observe
Now that you have tracing setup, all invocations and steps of your Agent will be streamed to your running Phoenix for observability and evaluation.