Observability Traces Tracing your agent

Tracing your agent

Forgebench records every model call. Add a few lines to your agent and each run becomes one trace. It shows the agent, the tools it called, and each model call under the step that made it.

The example below, as one trace in the console.
The example below, as one trace in the console.

You need an API key and the SDK installed. See the Quickstart.

1. Mark the agent and its tools

Wrap your agent's entry point and each tool with observe. Each call records its input, output, duration and any error. Model calls made inside the agent nest under it on their own.

from forgebench import Forgebench, observe

fb = Forgebench()  # reads FORGEBENCH_API_KEY and FORGEBENCH_BASE_URL

@observe(as_type="tool")
def get_weather(city: str) -> dict:
  return {"city": city, "temp_c": 18}

@observe(as_type="agent", name="support-agent")
def answer(question: str) -> str:
  weather = get_weather("San Francisco")
  reply = fb.chat.completions.create(
      model="mock-gpt",
      messages=[{"role": "user", "content": f"{question} Weather: {weather}"}],
  )
  return reply.choices[0].message.content

print(answer("Do I need an umbrella today?"))
fb.flush()  # send before a short script exits

2. Run it

Run the program as usual. The SDK sends steps in the background with your existing API key; there's nothing else to install or grant. In a short script, flush makes sure everything is sent before it exits.

3. Open the trace

In the console, open Traces and select the newest support-agent trace. You'll see:

  • support-agent, the agent's run, at the top
  • get_weather under it, with its input and output
  • the mock-gpt model call under it, with tokens and cost

Opening Traces needs the admin role or the View observability permission. See Who sees which traces.

Next

Cookie settings

Our Cookie Policy lists every cookie and what it does.