Smolagents tracing with Future AGI

Trace a Smolagents agent run and tool calls with traceAI-smolagents.

Trace a Smolagents tool-calling agent in Future AGI using traceAI-smolagents.

1. Install

Use Python 3.11–3.13. This example uses Smolagents 1.12.0 and its OpenAIServerModel API; it does not use the newer OpenAIModel API.

pip install 'traceAI-smolagents==0.1.5' 'smolagents[openai]==1.12.0'

The instrumentor package requires Smolagents 1.12.0 or later. Keep the exact framework version above for the model API used here.

2. Set environment variables

Set OPENAI_MODEL to a chat model available to your account that supports tool calling.

export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
export OPENAI_MODEL="YOUR_MODEL_ID"
export FI_API_KEY="YOUR_FI_API_KEY"
export FI_SECRET_KEY="YOUR_FI_SECRET_KEY"

Agent tasks, model messages, tool arguments, results and error details can be captured by default. To hide input and output content, set these TraceConfig controls before initialization:

export FI_HIDE_INPUTS=true FI_HIDE_OUTPUTS=true
export FI_HIDE_INPUT_MESSAGES=true FI_HIDE_OUTPUT_MESSAGES=true

Model metadata and custom attributes can still be exported. Error text may contain request data or credentials; input/output hiding is not a guarantee that every error or custom field is redacted. Review the controls supported by your installed core version before tracing sensitive workloads.

3. Initialize tracing

Keep the following Python snippets in one file. Instrument before creating or running the agent.

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
from traceai_smolagents import SmolagentsInstrumentor

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="smolagents",
)
SmolagentsInstrumentor().instrument(tracer_provider=trace_provider)

4. Run an agent

The tool below performs local arithmetic without network access. The example makes model requests and exports traces, but does not search the web or execute model-generated Python code.

import os
from smolagents import OpenAIServerModel, ToolCallingAgent, tool


@tool
def add(a: int, b: int) -> int:
    """Add two integers.

    Args:
        a: The first integer.
        b: The second integer.
    """
    return a + b


try:
    model = OpenAIServerModel(
        model_id=os.environ["OPENAI_MODEL"],
        api_key=os.environ["OPENAI_API_KEY"],
    )
    agent = ToolCallingAgent(tools=[add], model=model, max_steps=3)
    print(agent.run("Use the add tool to calculate 17 + 25, then return the result."))
finally:
    trace_provider.shutdown()

Shutdown flushes pending spans before this short script exits. In a long-running service, shut down the provider when the service stops rather than after each request.

View the trace

Open Observe in Future AGI and select smolagents. Open the agent trace to inspect its model calls and any tools the model invoked. Message and tool payload visibility depends on your capture controls.

Was this page helpful?

Questions & Discussion