新版文档(v1.x)
langchain
LangSmith Observability

LangSmith Observability

import ObservabilityPy from '/snippets/oss/observability-py.mdx'; import ObservabilityJs from '/snippets/oss/observability-js.mdx';

As you build and run agents with LangChain, you need visibility into how they behave: which tools (opens in a new tab) they call, what prompts they generate, and how they make decisions. LangChain agents built with @[create_agent] automatically support tracing through LangSmith, a platform for capturing, debugging, evaluating, and monitoring LLM application behavior.

Traces record every step of your agent's execution, from the initial user input to the final response, including all tool calls, model interactions, and decision points. This execution data helps you debug issues, evaluate performance across different inputs, and monitor usage patterns in production.

This guide shows you how to enable tracing for your LangChain agents and use LangSmith to analyze their execution.

Prerequisites

Before you begin, ensure you have the following:

Enable tracing

All LangChain agents automatically support LangSmith tracing. To enable it, set the following environment variables:

export LANGSMITH_TRACING=true
export LANGSMITH_API_KEY=<your-api-key>

Quickstart

No extra code is needed to log a trace to LangSmith. Just run your agent code as you normally would:

from langchain.agents import create_agent
 
 
def send_email(to: str, subject: str, body: str):
    """Send an email to a recipient."""
    # ... email sending logic
    return f"Email sent to {to}"
 
def search_web(query: str):
    """Search the web for information."""
    # ... web search logic
    return f"Search results for: {query}"
 
agent = create_agent(
    model="gpt-5.5",
    tools=[send_email, search_web],
    system_prompt="You are a helpful assistant that can send emails and search the web."
)
 
# Run the agent - all steps will be traced automatically
response = agent.invoke({
    "messages": [{"role": "user", "content": "Search for the latest AI news and email a summary to [email protected]"}]
})

By default, the trace will be logged to the project with the name default. To configure a custom project name, see Log to a project.