Learn to create and use Sessions in Galileo
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 using app.galileo.ai
, you don’t need to set this.GalileoLogger
class from the Python or TypeScript SDKGalileo
, LangChain
, and LangGraph
, you can skip right to Manage a Session. If not, here’s an abbreviated quickstart:
Install dependences
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.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
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.logger.start_session
like a lifecycle event, and call it before any code you want to monitor. The name
and external id
arguments are optional but 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!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
has a few optional parameters:Full code sample (click to expand)
logger.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:
Log in to the Galileo Console and select your Log Stream
Select your session
View your session
Optional: View individual Spans
GalileoLogger
instance across your project. This ensures that all captured events are placed in the same session. You can achieve this in a few ways:
logger
instance from a separate module, so that your application uses a singleton instance.
getLogger
function, or the Python SDK’s galileo_context
context manager for a consistent reference:
Traces
wherever you see fit. A Trace
might 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:
GalileoLogger
classlogger.start_session()
method