Skip to main content

Overview

This guide explains how to add logging and evaluations with Galileo to an existing CrewAI application. In this guide you will:
  1. Set up a project with Galileo
  2. Load environment variables if necessary
  3. Add the Galileo event listener
  4. Run your crew

Before you start

To complete this how-to, you will need:

Install dependencies

To use Galileo, you need to install some package dependencies, and configure environment variables.
1

Install Required Dependencies

Install the required dependencies for your app. Create a virtual environment using your preferred method, then install dependencies inside that environment using your preferred tool:
pip install galileo
Install python-dotenv if you don’t already have this installed.
pip install python-dotenv
2

Create a .env file if you don't have one already, and add the following values

# Your Galileo API key
GALILEO_API_KEY="your-galileo-api-key"

# Your Galileo project name
GALILEO_PROJECT="your-galileo-project-name"

# The name of the Log stream you want to use for logging
GALILEO_LOG_STREAM="your-galileo-log-stream "

# Provide the console url below if you are using a
# custom deployment, and not using the free tier, or app.galileo.ai.
# This will look something like “console.galileo.yourcompany.com”.
# GALILEO_CONSOLE_URL="your-galileo-console-url"
This assumes you are using a free Galileo account. If you are using a custom deployment, then you will also need to add the URL of your Galileo Console:
.env
GALILEO_CONSOLE_URL=your-Galileo-console-URL

Load environment variables if necessary

Galileo needs values like the API key and project name set as environment variables. If you are not already loading a .env file, then you need to do so.
You can skip this step if you are already loading the .env file.
1

Import the dotenv package

Add the following code at the top of your main.py file to import dotenv and load the .env file.
from dotenv import load_dotenv
load_dotenv()
This assumes you are following the same structure as the sample CrewAI applications. If you are not, add this to the top of the file that contains the entry point of your application.

Add the Galileo event listener

To enable logging with Galileo, you need to create an instance of the CrewAIEventListener.
1

Import the Galileo CrewAI handler package

Add the following code at the top of your main.py file:
from galileo.handlers.crewai.handler import CrewAIEventListener
This assumes you are following the same structure as the sample CrewAI applications. If you are not, add this to the top of the file that contains the entry point of your application.
2

Create the event listener

At the start of your run function, create the event listener:
def run():
    # Create the event listener
    CrewAIEventListener()

    # The rest of your existing code goes here
When you create the listener instance, it is automatically registered with CrewAI.

Run your crew

You are now ready to run your crew, and see the logged traces in Galileo.
1

Run your crew

Run your crew with the CrewAI CLI:
crewai run
2

View the traces in Galileo

Once your crew has finished, the traces will be flushed an appear in Galileo.THe Galileo console showing a CrewAI trace with metrics

See also

I