Sending traces to an agent applies only to agent-based workspaces. It is supported in:
- The Python SDK from
langsmith>=0.14.9 - The TypeScript SDK from
langsmith>=0.10.9 - The Go SDK from
github.com/langchain-ai/langsmith-go@v0.28.0 - The Java SDK from
com.langchain.smith:langsmith-java:0.1.0-beta.26
Prerequisites
- An agent-based workspace. Agent-based workspaces are available on LangSmith Cloud. They are not available on self-hosted LangSmith. In an agent-based workspace, sending traces to an agent is already on, and you have no setting to change. To check which kind of workspace you have, look at the control at the top left. In an agent-based workspace, it names your workspace. In a project-based workspace, it shows the LangSmith logo, and sending traces to an agent is off.
- An API key from that workspace. See create an API key.
-
The SDK. Sending traces to an agent needs
langsmith>=0.14.9in Python,langsmith@>=0.10.9in TypeScript, v0.28.0 or later ofgithub.com/langchain-ai/langsmith-goin Go, or 0.1.0-beta.26 or later ofcom.langchain.smith:langsmith-javain Java:
Send traces to an agent
Name the agent and the environment together, in code or as environment variables. An agent in code takes precedence over the variables. The SDK reads the variables only when nothing in code names a destination, and then it needs both.- Agent ID: The agent’s identifier, which the browser address bar carries and the ID field on the agent’s Overview copies. It is not the display name. A display name is a separate, editable value that does not have to match the identifier, so read the identifier from the agent rather than deriving it from what the agent is called. For the rules an identifier must follow, see Identifier rules. If no agent in the workspace uses the identifier you send, LangSmith creates that agent the first time you send a trace to it, so you do not have to create it in advance. Creating an agent this way requires the
projects:createpermission. Without it, LangSmith rejects the run with a403. An archived agent still holds its identifier, so LangSmith rejects a run sent to it with a409instead of creating a new agent. Send that agent’s traces to a different identifier. The Overview of an agent created this way does not show deployment details. - Environment: The environment the run belongs to, and one of
local,development,staging, orproduction. Environment names are not case-sensitive, and they map to the Local, Development, Staging, and Production labels in the UI. There is no default, because neither the agent nor the environment names a destination alone.
Using environment variables
Set both variables:Using code
Pass an agent address.- Python
- TypeScript
- Java
- Go
Pass
ls.agent_address("checkout", "production") as the address argument of @traceable, or of tracing_context for everything traced inside a block:Using OpenTelemetry
To send OTLP traces to an agent, set theLangsmith-Agent-Id and Langsmith-Agent-Environment headers instead of Langsmith-Project. With langsmith>=0.14.9, the Python SDK’s OpenTelemetry exporter sets both headers from the agent variables when OTEL_EXPORTER_OTLP_HEADERS is unset. For the header rules and the errors LangSmith returns, see Trace with OpenTelemetry.
Send your first trace
Run your application so it sends at least one trace. In LangSmith, select the agent in the top bar, go to Tracing, and set the environment control to the one you sent the trace to. The trace appears there.Find an agent’s project
To query the traces of an agent, first resolve the agent to its project ID, then use the endpoints as before, passing that ID.Send to an agent or a project, not both
Sending traces to an agent and to a project do not combine. What happens depends on where each is set:- An agent and a project together: Not allowed. If you set the agent variables and also
LANGSMITH_PROJECT,LANGCHAIN_PROJECT, orLANGCHAIN_SESSION, the trace has two destinations, and the SDK does not pick one. It logs a warning when the client starts, and it does not trace a call unless code names the destination. If you pass bothaddressandproject_namein one call, the SDK raises an error and sends nothing:LangSmithUserErrorfrom@traceableortracing_context()in Python, or anErrorfromtraceablein TypeScript. If a run that names both an agent and a project reaches LangSmith, LangSmith rejects it. - A project named in code: Overrides the agent variables. Passing
project_nameto@traceableortracing_context()in Python, or in thetraceableconfig in TypeScript, traces the run to that project and ignores the agent variables, without an error. This is what lets an evaluation set its own project while the agent variables stay set for the rest of the process.
Troubleshooting
On self-hosted LangSmith, where agent-based workspaces are not available, LangSmith rejects runs sent to an agent with a403 and the message agent addressing is not enabled for this workspace. It rejects the whole request that carries them, so it records none of the runs in that request. See Prerequisites.
See also
- Agents
- Agent environments
- Log traces to a specific project
- Find an agent’s project
- Trace with OpenTelemetry
- Observability concepts
Connect these docs to your agent of choice via MCP for real-time answers.

