Skip to main content
Python의 wrap_anthropic 메서드를 사용하면 데코레이터나 함수 래핑 없이도 Anthropic 클라이언트를 래핑하여 자동으로 트레이스를 기록할 수 있습니다! 래퍼를 사용하면 도구 호출 및 멀티모달 콘텐츠 블록을 포함한 메시지가 LangSmith에서 깔끔하게 렌더링됩니다. 래퍼는 @traceable 데코레이터 또는 traceable 함수와 원활하게 작동하며, 동일한 애플리케이션에서 두 가지 모두를 사용할 수 있습니다.
wrap_anthropic을 사용하는 경우에도 트레이스를 LangSmith에 기록하려면 LANGSMITH_TRACING 환경 변수를 'true'로 설정해야 합니다. 이를 통해 코드를 변경하지 않고도 트레이싱을 켜고 끌 수 있습니다.또한 LANGSMITH_API_KEY 환경 변수를 API 키로 설정해야 합니다(자세한 내용은 설정을 참조하세요).LangSmith API 키가 여러 워크스페이스에 연결된 경우, LANGSMITH_WORKSPACE_ID 환경 변수를 설정하여 사용할 워크스페이스를 지정하세요.기본적으로 트레이스는 default라는 이름의 프로젝트에 기록됩니다. 다른 프로젝트에 트레이스를 기록하려면 이 섹션을 참조하세요.
import anthropic
from langsmith import traceable
from langsmith.wrappers import wrap_anthropic

client = wrap_anthropic(anthropic.Anthropic())

# You can also wrap the async client as well
# async_client = wrap_anthropic(anthropic.AsyncAnthropic())

@traceable(run_type="tool", name="Retrieve Context")
def my_tool(question: str) -> str:
    return "During this morning's meeting, we solved all world conflict."

@traceable(name="Chat Pipeline")
def chat_pipeline(question: str):
    context = my_tool(question)
    messages = [
        { "role": "user", "content": f"Question: {question}\nContext: {context}"}
    ]
    messages = client.messages.create(
      model="claude-sonnet-4-20250514",
      messages=messages,
      max_tokens=1024,
      system="You are a helpful assistant. Please respond to the user's request only based on the given context."
    )
    return messages

chat_pipeline("Can you summarize this morning's meetings?")

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I