Skip to main content
Microsoft Agent Framework is a .NET framework for building AI agents. Braintrust traces agent runs end-to-end, covering agent invocations, the underlying LLM calls, and tool executions.

Setup

Install the Braintrust SDK and the Agent Framework integration, then set your API keys. The examples below use OpenAI.
1

Install packages

2

Set environment variables

.env

Manual instrumentation

To trace the Agent Framework, add Braintrust’s middleware to your chat client and wrap your agent. UseBraintrustTracing instruments both the LLM calls and the tool invocations on the ChatClientBuilder, and WithBraintrustAgentTracing wraps the agent so each run is captured as a span.
#skip-compile
UseBraintrustTracing combines UseBraintrustLLMTracing (LLM calls) and UseBraintrustFunctionTracing (tool calls). Call a single method instead to trace only that layer. Each method accepts a captureMessageContent flag, and function tracing accepts a captureToolArguments flag, to turn off capturing message or argument content.

What Braintrust traces

Braintrust captures a span at each level of the Agent Framework pipeline:
  • Agent run spans (agent:<name>), with input and output messages, agent name and ID, token usage (prompt, completion, and total), and time to first token.
  • Chat completion spans (Chat Completion and Chat Completion Stream), with input and output messages, request and response model, and token usage (prompt, completion, and total). Streamed responses are aggregated and tagged with stream.
  • Function call spans (function:<name>), with the function name, arguments, result, call iteration and index, and duration.
  • Errors on any span, including the exception message and details.
Set captureMessageContent: false to omit message content, or captureToolArguments: false to omit function arguments and results.

Resources