Integrations / smolagents

Trace Hugging Face smolagents

To trace smolagents with Tracify, wrap the call to agent.run with trace_agent and add a step to each tool. You get one trace per task, with every tool call in the order the agent made it.

Your code

smolagents

Tracify

One run.

  • 01One trace per agent.run task
  • 02Each tool call with input and output
  • 03Failures and retries
  • 04Total time for the task

Setup

5 steps.

  1. 01

    Install

    smolagents and the Tracify SDK.

    bash
    pip install tracify-sdk smolagents
  2. 02

    Set your project key

    Create a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.

    bash
    export TRACIFY_API_KEY="tracify_sk_live_..."
  3. 03

    Wrap agent.run

    Each task becomes one run. Everything recorded inside while the agent works joins it.

    python
    import tracify
    
    @tracify.trace_agent(name="smolagent")
    def run(task: str):
        return agent.run(task)
  4. 04

    Put a step in each tool

    The agent decides which tools to call. A step in each tool function shows exactly which ones it called, with what, and what came back.

    python
    from smolagents import tool
    
    @tool
    def get_weather(city: str) -> str:
        """Return the weather for a city.
    
        Args:
            city: Name of the city.
        """
        with tracify.span("get_weather", type="tool", input=city) as step:
            forecast = f"Sunny in {city}"
            step.set_output(forecast)
            return forecast
  5. 05

    Run it once and look

    Run your code one time, then open the Tracing page of your project. Your agent task shows up as a run with its steps in order, plus the tokens, time and any error for each call.

Good to know

Code agents write code

A CodeAgent runs Python it writes itself. The tool calls it makes still go through your tool functions, so they are recorded. The code the model wrote is not captured by these steps.

Good to know

Model calls

smolagents has its own model classes, so those requests are not wrapped automatically. If your model class uses an OpenAI-style client that you create, wrap that client and the calls join the run.

Full details in the documentation. All integrations are listed on the integrations page.

Does it work with ToolCallingAgent too?
Yes. The same two things apply: wrap agent.run and add a step to each tool.
Can I see why an agent looped?
Yes. Repeated tool calls appear one after another in the run, so a loop is easy to spot.
Does it work with multi-agent setups?
Yes. Call the managed agents from inside the run and put a step in their entry point so each one is visible.

Send your first trace.

Free to start.