Skip to main content
LangSmith gives you end-to-end visibility into your agent by capturing traces; a complete record of every step that ran during a request, from the inputs passed in to the final output returned. In this quickstart, you will add tracing to an AI assistant and view the results in LangSmith. Traces belong to an agent and one of its environments within a workspace. This quickstart creates the agent in LangSmith, then configures your code to send traces to its identifier and environment.
If you’re building with LangChain or LangGraph, you can enable LangSmith tracing with a single environment variable. Refer to trace with LangChain or trace with LangGraph.

Prerequisites

Before you begin, make sure you have: Select your provider in the tabs on each step. The Anthropic and Gemini examples are in Python and TypeScript only, because the LangSmith Java SDK wraps only the OpenAI client.
Using an AI coding assistant? Install LangSmith skills so your agent can add LangSmith tracing to your application.

Install LangChain Skills

1. Set up your environment

  1. Create a directory for your agent code, install the dependencies, and configure the required environment variables:
  2. Export your environment variables in your shell:
    Before sending traces, create the agent in LangSmith. Creating an agent requires the projects:create permission.
    1. Open the new agent menu, either from + Agent with All agents selected, or from the + button beside the search box in the agent switcher.
    2. Select Connect > Connect an existing agent.
    3. In the Connect an agent dialog, enter an Agent name and Agent ID.
    4. Copy the Agent ID and choose an environment: local, development, staging, or production.
    5. Configure agent addressing before running the agent:
    Create the agent once, not for every trace. Then remove LANGSMITH_PROJECT, LANGCHAIN_PROJECT, and LANGCHAIN_SESSION from the environment where your code runs, because they conflict with agent addressing. To create the agent with the SDK or API instead, see Create an agent programmatically.
    If your account is in a region other than US (the default), also set LANGSMITH_ENDPOINT to the API URL for your region. Without this, your API key won’t be recognized and requests will fail to authenticate.
    LangSmith region
    GCP US
    GCP EU
    GCP APAC
    AWS US
    For example, EU accounts: export LANGSMITH_ENDPOINT="https://eu.api.smith.langchain.com".
    For other providers, use the @traceable decorator to trace calls manually.

2. Build the app

The following app uses two LangSmith tools to add tracing:
  • Provider wrapper: wraps the OpenAI, Anthropic, or Gemini client so every LLM call is automatically logged as a nested span. The Gemini wrapper is in beta.
  • Traceable wrapper: wraps a function so its inputs, outputs, and any nested spans appear as a single trace in LangSmith. Use @traceable in Python, traceable in TypeScript and Kotlin, and Tracing.traceFunction in Java.
The assistant function calls a tool (get_context) to retrieve relevant context, then passes that context to the model. Using the traceable wrapper on both functions captures the full pipeline in one trace, with the tool call and LLM call as nested spans. Create a file called app.py, index.ts, App.java, or App.kt with the following code:

3. Run the app

4. View your trace

In the LangSmith UI, select your agent, go to Tracing, and select the environment configured during setup. For more information, see Navigate agents. Click the assistant row to open the trace. The Trajectory tab shows the conversation as it was sent to the model. Select the Details tab to see the full run tree, including the assistant function with the get_context tool call and the model call nested inside it. LangSmith UI showing a trace with an outer agent span and a nested LLM call span. LangSmith UI showing a trace with an outer agent span and a nested LLM call span. The outer span captures your assistant function’s inputs and outputs. The nested get_context span (getContext in TypeScript) records the tool call, and the model span (ChatOpenAI, ChatAnthropic, or ChatGoogleGenerativeAI) records the exact prompt sent to the model and the response returned.
You can also inspect traces from the terminal using the LangSmith CLI.

Next steps

After logging traces, use Chat to analyze them and get AI-powered insights into your agent’s performance.