Overview
This tutorial will guide you through creating and using a Session in Galileo, using a simple LLM-driven example that you can expand to multiple agents and data sources. It is a quick way to introduce you to logging sessions. By the end of this guide, you will know how to:- Initialize a logging session
- Add events to your session
- Inspect the Session in the Galileo Console to see all related Traces and Spans.
Prerequisites
-
Galileo Account: Ensure you have signed up for a Galileo account. This should provide you with the following values:
GALILEO_API_KEY: Your API keyGALILEO_PROJECT: The name of your Galileo ProjectGALILEO_LOG_STREAM: The Log stream where you will save your sessionsGALILEO_CONSOLE_URL: Optional. The URL of your Galileo console for custom deployments. If you are usingapp.galileo.ai, you don’t need to set this.
- OpenAI API Key: This example will use OpenAI as the underlying LLM, so you will need an API key from them.
- Simple LLM Apps, and making simple OpenAI completion calls using Python or TypeScript
- The
GalileoLoggerclass from the Python or TypeScript SDK
Project setup
Let’s take a moment to prepare the development environment. If you already have a project setup withGalileo, LangChain, and LangGraph, you can skip right to Manage a Session. If not, here’s an abbreviated quickstart:
Install dependencies
dotenv to pull in variables from your .env file. Let’s start by installing them:Create a .env file
.env file and add in the following variables:Create your application logic file
main.py or main.ts) where you’ll add and run your application logic.Manage a session
Recall our objectives from earlier? We’ll build a simple application and use it to work through each step. If you’re in a hurry, you jump to the full code sample here, then return to see how it was put together.Steps
Create a simple agent
GalileoCallback and RunnableConfig in action later. For now, let’s move on to the next step.Create a Logger Instance
GalileoLogger to manage our logging session. Let’s create one next:Optional arguments for GalileoLogger
Optional arguments for GalileoLogger
GalileoLogger takes some optional arguments: you don’t have to provide any of them, but they are listed below so that you can see what is available.Start a logging session
main function where everything happens. The first thing we will do in this function is start up a logging session. This will prepare the logger to group all captured events under a single session.Below, we give the session a unique name and external id. The name helps us find the session more easily in the Galileo Console. The external id is to link this session to external tracing: for example, linking to a conversation ID in your chatbot app by an ID created inside that app.You can also pass an optional metadata dictionary of string key-value pairs to attach structured information to the session, such as customer IDs, environment names, or application versions. Metadata keys appear as filterable columns in the Sessions table in the Galileo Console.logger.start_session like a lifecycle event, and call it before any code you want to monitor. The name, external id, and metadata arguments are all optional; name and external id are recommended.Add your LLM logic
Trace with child spans in our session. We will also pass a callback handler, which will be called by LangChain after each LLM invocation.Here’s our full main function: you can make this part as complex as you like!The GalileoCallback handler
GalileoCallback is a callback handler specifically for LangChain. It sends the most-recent captured traces to Galileo Console when it is called behind the scenes: your LLM logic determines what traces are generated and/or captured.
GalileoCallback optional parameters (click to expand)
GalileoCallback optional parameters (click to expand)
GalileoCallback has a few optional parameters:Full code sample
Here’s everything we have done so far:Full code sample (click to expand)
Full code sample (click to expand)
Run your script
That’s all the code: we have now learned to uselogger.start_session before starting LLM chat session, and supply GalileoCallback to ensure your traces get sent to the Galileo Console.
Now let’s run the script:
View your session
Now that you’ve logged a session, it’s time to view results.Log in to the Galileo Console and select your Log Stream

Select your session

View your session

Optional: View individual Spans

Additional considerations
Remember to always use the sameGalileoLogger instance across your project. This ensures that all captured events are placed in the same session. You can achieve this in a few ways:
-
Export your
loggerinstance from a separate module, so that your application uses a singleton instance. -
Use the TypeScript SDK’s
getLoggerfunction, or the Python SDK’sgalileo_contextcontext manager for a consistent reference: -
You can also add
Traceswherever you see fit. ATracemight represent a question asked to your LLM, and the response generated for it — as well as any tools used! Galileo will generate traces for you, but you can also create new ones by using your logger instance:You can learn more about traces and how to use them in our logging guide.
Conclusion
In this tutorial, you learned how to:- Create a logging session with the
GalileoLoggerclass - Manually start your own session with the
logger.start_session()method - View your sessions in the Galileo Console.
Next steps
For a more detailed walkthrough of a multi-agent application, take a look at Monitoring LangChain Agents with Galileo. You can also learn more about using Galileo’s metrics to gain more insight about your AI application.Related resources
- Sessions - An overview of sessions
- Galileo Context - Learn about the Galileo Context Manager
- Monitoring LangChain Agents with Galileo - Follow this cookbook recipe to create and evaluate a multi-agent application.