메인 콘텐츠로 건너뛰기
Claude Agent SDK를 사용하면 Claude를 사용해 에이전트 애플리케이션을 빠르게 구축할 수 있습니다. Weave를 Claude 에이전트에 통합하면 에이전트 쿼리, 모델 응답, 도구 사용, 멀티턴 대화를 포함한 Call을 자동으로 트레이스할 수 있습니다. Weave는 캡처한 데이터를 프로젝트의 Agents 뷰에 표시합니다.

Weave로 Claude Agent SDK 에이전트 트레이스하기

Weave SDK는 Claude Agent SDK for Python에 자동으로 패치되어, 최소한의 설정만으로 Claude 에이전트의 트레이스를 캡처할 수 있습니다.이 가이드에서는 Weave를 초기화하고 ClaudeSDKClient를 통해 MCP 도구와 함께 Claude 에이전트를 실행하는 방법을 설명합니다. Weave는 대화, 모델 Call, 도구 Call을 엔드 투 엔드로 자동 트레이스합니다.

사전 요구 사항

  • WANDB_API_KEY 환경 변수로 설정된 W&B 계정과 API 키
  • ANTHROPIC_API_KEY 환경 변수로 설정된 Anthropic API 키
  • Python 3.10+

패키지 설치

개발 환경에 다음 패키지를 설치하세요. weave 패키지는 트레이스를 캡처하고, claude-agent-sdk는 에이전트 런타임을 제공합니다.
pip install weave claude-agent-sdk

코드에서 Weave 초기화하기

프로젝트에 weave.init를 추가하고 W&B 팀 이름과 프로젝트 이름을 업데이트한 다음, 평소처럼 에이전트를 구축하세요. weave.init는 Claude Agent SDK의 트레이스를 캡처하는 오토패칭을 활성화합니다.다음 코드는 MCP 수학 도구 두 개를 사용하는 Claude 에이전트를 생성하고, Weave가 트레이스를 캡처하는 상태에서 이를 실행합니다.
import anyio
import weave

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

weave.init("<your-team>/<your-project-name>")

@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)
스크립트가 실행되면 weave.init()이 프로젝트 링크를 출력합니다. 링크를 열어 에이전트의 쿼리, 모델 응답, 도구 Call에 대해 캡처된 트레이스를 확인하세요.

Agents 뷰에서 에이전트 트레이스를 확인하세요

스크립트가 실행된 후 weave.init()가 프로젝트 링크를 출력합니다. 다음 항목을 살펴보려면 Agents 뷰를 여세요.
  • 대화의 턴이 포함된 세션.
  • chatexecute_tool 하위 span이 중첩된 invoke_agent span으로 렌더링된 각 턴.
  • 각 단계의 전체 입력, 모델, 출력, 토큰 사용량, 도구 결과.
Weave에서 Agents 데이터를 보는 방법에 대한 자세한 내용은 에이전트 활동 보기를 참조하세요.