Threads
feature in LangSmith.
Group traces into threads
AThread
is a sequence of traces representing a single conversation. Each response is represented as its own trace, but these traces are linked together by being part of the same thread.
To associate traces together, you need to pass in a special metadata
key where the value is the unique identifier for that thread. The key name should be one of:
session_id
thread_id
conversation_id
.
f47ac10b-58cc-4372-a567-0e02b2c3d479
. Check out this guide for instructions on adding metadata to your traces.
Example
This example demonstrates how to log and retrieve conversation history using a structured message format to maintain long-running chats.get_chat_history=True,
/getChatHistory: true
,
you can continue the conversation from where it left off. This means that the LLM will receive the entire message history and respond to it,
instead of just responding to the latest message.
View threads
You can view threads by clicking on the Threads tab in any project details page. You will then see a list of all threads, sorted by the most recent activity.
View a thread
You can then click into a particular thread. This will open the history for a particular thread.
T
to toggle between the two views.
Thread overview
The thread overview page shows you a chatbot-like UI where you can see the inputs and outputs for each turn of the conversation. You can configure which fields in the inputs and outputs are displayed in the overview, or show multiple fields by clicking the Configure button. The JSON path for the inputs and outputs supports negative indexing, so you can use-1
to access the last element of an array. For example, inputs.messages[-1].content
will access the last message in the messages
array.
Trace view
The trace view here is similar to the trace view when looking at a single run, except that you have easy access to all the runs for each turn in the thread.View feedback
When viewing a thread, across the top of the page you will see a section calledFeedback
. This is where you can see the feedback for each of the runs that make up the thread. This feedback is aggregated, so if you evaluate each run of a thread for the same criteria, you will see the average score across all the runs displayed. You can also see thread level feedback left here.
Save thread level filter
Similar to saving filters at the project level, you can also save commonly used filters at the thread level. To save filters on the threads table, set a filter using the filters button and then click the Save filter button. You can open up the trace or annotate the trace in a side panel by clicking onAnnotate
and Open trace
, respectively.
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.