Skip to main content
AgentScope is a framework for building multi-agent systems. Braintrust traces an AgentScope run as a single nested trace, covering agent replies, sequential and fanout pipelines, tool calls, and model requests.
Braintrust supports AgentScope 1.x and 2.x, and requires AgentScope v1.0.0 or later. AgentScope 2.x requires Python 3.11 or later.

Setup

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

Install packages

2

Set environment variables

.env

Auto-instrumentation

To trace AgentScope alongside Braintrust’s other supported libraries, call braintrust.auto_instrument() before importing AgentScope. Because AgentScope uses from agentscope... import style imports, the call must come first so the patches are in place.
To trace AgentScope without auto-instrumenting other libraries, use setup_agentscope() instead of braintrust.auto_instrument(). It initializes a Braintrust logger when one isn’t already active.

What Braintrust traces

Braintrust traces AgentScope runs as nested spans that mirror the actual execution flow. Captured spans:
  • Agent run spans (<agent>.reply, such as Friday.reply), with the call input, agent class, and response. Both the 1.x AgentBase.__call__ and 2.x Agent.reply paths are instrumented.
  • Pipeline spans (sequential_pipeline.run and fanout_pipeline.run), with the names of the participating agents. Child agent, tool, and model spans nest underneath.
  • Tool execution spans (<tool>.execute, such as execute_python_code.execute), with the tool call, toolkit class, and output, including streamed tool output.
  • Model call spans (<provider>.call, such as OpenAIChat.call), with messages, tools, and model metadata (model name, provider, and request parameters); response content and token usage (prompt, completion, and total) on completion.
  • Streaming model responses and tool outputs, aggregated into the final span output, with token metrics on model spans.
  • Errors on failed agent runs, pipelines, tool calls, and model calls.
The integration instruments AgentScope’s built-in OpenAI, DashScope, Anthropic, Ollama, Gemini, and Trinity chat models.

Resources