Sessions in Laminar provide a way to group related traces together. This is particularly useful for:
Grouping traces from a single user interaction
Connecting multiple API requests that form a logical sequence
Organizing conversational turns in a chatbot
Tracking complex workflows across multiple functions or services
For example, in a conversational agent, each turn in the conversation might be represented as a trace, while the entire conversation would be a session.
You can also set the session ID directly when using the observe decorator/wrapper:
Copy
import { Laminar, observe } from "@lmnr-ai/lmnr";// Set session ID in the observe functionawait observe( { name: "myFunction", sessionId: "session123" }, async () => { // Function code here });
For a chatbot, each user message and response can be a separate trace, with the entire conversation as a session:
Copy
@observe()def handle_turn(user_message, conversation_id): # Must be within span context Laminar.set_trace_session_id(session_id=conversation_id) # Process message, call LLMs, etc. return response