> ## Documentation Index
> Fetch the complete documentation index at: https://docs.galileo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Add Galileo to a CrewAI Application

> Learn how to add logging and evaluations with Galileo to an existing CrewAI application

{/*<!-- markdownlint-enable MD044 -->*/}

## 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](#install-dependencies)
2. [Load environment variables if necessary](#load-environment-variables-if-necessary)
3. [Add the Galileo event listener](#add-the-galileo-event-listener)
4. [Run your crew](#run-your-crew)

## Before you start

To complete this how-to, you will need:

* An agentic application built with [CrewAI](https://www.crewai.com). This guide assumes you have a `run()` function as your entry point.
  > If you don't have a CrewAI application, you can follow the [**Build your first Crew** guide from the CrewAI documentation](https://docs.crewai.com/en/guides/crews/first-crew).
* A [Galileo project](/concepts/projects) configured, with [relevant metrics configured](/concepts/metrics/overview)
* Your [Galileo API key](https://app.galileo.ai/settings/api-keys)

## Install dependencies

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

<Steps>
  <Step title="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:

    <CodeGroup>
      ```bash Pip theme={null}
      pip install galileo
      ```

      ```bash uv theme={null}
      uv pip install galileo
      ```

      ```bash Poetry theme={null}
      poetry add galileo
      ```
    </CodeGroup>

    Install `python-dotenv` if you don't already have this installed.

    <CodeGroup>
      ```bash Pip theme={null}
      pip install python-dotenv
      ```

      ```bash uv theme={null}
      uv pip install python-dotenv
      ```

      ```bash Poetry theme={null}
      poetry add python-dotenv
      ```
    </CodeGroup>
  </Step>

  <Step title="Create a .env file if you don't have one already, and add the following values">
    <CodeGroup>
      ```ini .env theme={null}
      # 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"
      ```
    </CodeGroup>

    <Note>
      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:

      ```ini .env theme={null}
      GALILEO_CONSOLE_URL=your-Galileo-console-URL
      ```
    </Note>
  </Step>
</Steps>

## 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.

<Note>
  You can skip this step if you are already loading the `.env` file.
</Note>

<Steps>
  <Step title="Import the dotenv package">
    Add the following code at the top of your `main.py` file to import `dotenv` and load the `.env` file.

    <CodeGroup>
      ```python Python theme={null}
      from dotenv import load_dotenv
      load_dotenv()
      ```
    </CodeGroup>

    <Note>
      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.
    </Note>
  </Step>
</Steps>

## Add the Galileo event listener

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

<Steps>
  <Step title="Import the Galileo CrewAI handler package">
    Add the following code at the top of your `main.py` file:

    <CodeGroup>
      ```python Python theme={null}
      from galileo.handlers.crewai.handler import CrewAIEventListener
      ```
    </CodeGroup>

    <Note>
      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.
    </Note>
  </Step>

  <Step title="Create the event listener">
    At the start of your `run` function, create the event listener:

    <CodeGroup>
      ```python Python theme={null}
      def run():
          # Create the event listener
          CrewAIEventListener()

          # The rest of your existing code goes here
      ```
    </CodeGroup>

    When you create the listener instance, it is automatically registered with CrewAI.
  </Step>
</Steps>

## Run your crew

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

<Steps>
  <Step title="Run your crew">
    Run your crew with the CrewAI CLI:

    <CodeGroup>
      ```bash Terminal theme={null}
      crewai run
      ```
    </CodeGroup>
  </Step>

  <Step title="View the traces in Galileo">
    Once your crew has finished, the traces will be flushed an appear in Galileo.

    <img src="https://mintcdn.com/v2galileo/FQjmOk8BWj4bvBe1/how-to-guides/third-party-integrations/add-galileo-to-crewai/logged-trace.webp?fit=max&auto=format&n=FQjmOk8BWj4bvBe1&q=85&s=3ca22d869fcf6dbcdbec56cd7d695293" alt="THe Galileo console showing a CrewAI trace with metrics" width="1791" height="718" data-path="how-to-guides/third-party-integrations/add-galileo-to-crewai/logged-trace.webp" />
  </Step>
</Steps>

## See also

* [Galileo CrewAI event listener](/sdk-api/third-party-integrations/crewai/crewai)
* [`CrewAIEventListener` Python SDK reference](/sdk-api/python/reference/handlers/crewai/handler)
