Skip to main content
The Claude Agent SDK is a Python SDK by Anthropic for building agent applications with Claude. W&B Weave automatically traces Claude Agent SDK calls when you call weave.init(), capturing queries, tool use, and multi-turn conversations.

Prerequisites

Before running the code example:
  • Update your-team-name appropriately for calling weave.init() on code line 109.
  • Set WANDB_API_KEY and ANTHROPIC_API_KEY in your environment.
    • For more information on W&B API keys, see API keys.

Installation

Install the required dependencies using pip:

Get started

Weave automatically patches the SDK and traces every query when weave.init() is called before using the Claude Agent SDK. The following example showcases three capabilities:
  • Simple one-shot queries using the query() function, including model responses and cost.
  • MCP tool use with ClaudeSDKClient. The Claude Agent SDK supports custom tools through in-process MCP servers.
    • Weave traces tool definitions, tool invocations, and results alongside the agent’s queries.
    • The MCP demo defines two MCP tools and runs a query that uses them.
  • Multi-turn conversations grouped into a single trace with weave.thread(), so you can see the full conversation flow in the Weave UI.
    • Weave captures each turn as a child of the thread, so you can see the full conversation flow in the Weave UI.

View traces

When you run the example, Weave prints links to the Weave dashboard. Follow the links to see your traces, including query inputs, model responses, tool invocations, and conversation threads.