Skip to main content
Weave for Agents is in public preview. Features, APIs, and the Agents view UI may change before general availability.
The Claude Agent SDK is a Python SDK for building agent applications with Claude. Weave automatically traces Claude Agent SDK calls, including agent queries, model responses, tool use, and multi-turn conversations. Weave displays the captured data in the Agents view of your project.

Trace Claude Agent SDK agents with Weave

The Weave SDK autopatches the Claude Agent SDK, letting you capture traces from your Claude agents with minimal setup. This doc shows how to initialize Weave and run a Claude agent with MCP tools through ClaudeSDKClient. Weave automatically traces the conversation, model calls, and tool calls end-to-end. When you’re done, you can view a complete trace of the agent’s query, model responses, and tool invocations in the Agents view of your project.

Prerequisites

  • A W&B account and API key set as a WANDB_API_KEY environment variable.
  • An Anthropic API key set as an ANTHROPIC_API_KEY environment variable.
  • Python 3.10+.

Install packages

Install the following packages in your developer environment. The weave package captures traces, and claude-agent-sdk provides the agent runtime.
pip install weave claude-agent-sdk

Initialize Weave in your code

Add weave.init to the project, update your W&B team and project names, and then build an agent the way you normally would. weave.init enables the autopatching that captures traces from the Claude Agent SDK. The following code creates a Claude agent with two MCP math tools and runs it while Weave captures the traces.
import anyio
import weave

from claude_agent_sdk import (
    ClaudeAgentOptions,
    ClaudeSDKClient,
    create_sdk_mcp_server,
    tool,
)

weave.init("[YOUR-TEAM]/[YOUR-PROJECT]")


@tool("add", "Add two numbers", {"a": float, "b": float})
async def add(args: dict) -> dict:
    return {"content": [{"type": "text", "text": str(args["a"] + args["b"])}]}


@tool("multiply", "Multiply two numbers", {"a": float, "b": float})
async def multiply(args: dict) -> dict:
    return {"content": [{"type": "text", "text": str(args["a"] * args["b"])}]}


math_server = create_sdk_mcp_server(
    name="math",
    version="1.0.0",
    tools=[add, multiply],
)


async def main():
    options = ClaudeAgentOptions(
        mcp_servers={"math": math_server},
        allowed_tools=["mcp__math__add", "mcp__math__multiply"],
    )

    async with ClaudeSDKClient(options=options) as client:
        await client.query("Using the math tools, compute (3 + 7) * 2.")

        async for message in client.receive_response():
            print(message)


anyio.run(main) 
When the script runs, weave.init() prints a link to your project. Open the link to inspect the captured traces for the agent’s query, model responses, and tool calls. For details about viewing Agents data in Weave, see View agent activity.