Prerequisites
Before you begin, make sure you have:- A LangSmith account: Sign up or log in at smith.langchain.com.
- A LangSmith API key: Follow the Create an API key guide.
- A model provider API key: Generate one from the OpenAI dashboard, the Claude Console, or Google AI Studio for Gemini.
1. Set up your environment
-
Create a directory for your agent code, install the dependencies, and configure the required environment variables:
- OpenAI
- Anthropic
- Gemini
-
Export your environment variables in your shell:
Before sending traces, create the agent in LangSmith:
- OpenAI
- Anthropic
- Gemini
-
In an agent-based workspace, open + Agent, choose Observability, and create an agent with an Agent name and Agent ID. This requires the
projects:createpermission. If the agent already exists, reuse it. -
Copy the Agent ID and choose an environment:
local,development,staging, orproduction. -
Configure agent addressing before running the agent:
LANGSMITH_PROJECT,LANGCHAIN_PROJECT, andLANGCHAIN_SESSIONfrom the environment where your code runs. Do not combine legacy destination settings with agent addressing. To create the agent with an SDK call or API request, see Create an agent programmatically.Project-based workspaces and self-hosted LangSmith
Agent addressing is available in agent-based workspaces on LangSmith Cloud. In a project-based workspace, including self-hosted LangSmith, setLANGSMITH_PROJECTto your tracing project name instead of setting the two agent variables.For other providers, use theIf your account is in a region other than US (the default), also setLANGSMITH_ENDPOINTto the API URL for your region. Without this, your API key won’t be recognized and requests will fail to authenticate.
For example, EU accounts:Region GCP US GCP EU GCP APAC AWS US export LANGSMITH_ENDPOINT="https://eu.api.smith.langchain.com".@traceabledecorator 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
@traceablein Python,traceablein TypeScript and Kotlin, andTracing.traceFunctionin Java.
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:
- OpenAI
- Anthropic
- Gemini
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. In a project-based workspace, open the project named byLANGSMITH_PROJECT. 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.


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.
Next steps
- Tracing integrations: LangChain, LangGraph, Anthropic, and other providers.
- Trace an agent: a full lifecycle tutorial, from prototyping through production.
- Filter traces: search the traces in an agent environment.
- Log traces to an agent: configure the agent and environment in code or with environment variables.
- Agent Registry: how workspaces organize agents and their environments.
After logging traces, use Chat to analyze them and get AI-powered insights into your agent’s performance.
Connect these docs to your agent of choice via MCP for real-time answers.

