Skip to main content
The Galileo CrewAI integration allows you to automatically log all CrewAI interactions with LLMs, including prompts, responses, and performance metrics. The Galileo SDK has a custom event listener that listens to CrewAI events, and logs these to Galileo.

Basic usage

The integration is based on the CrewAIEventListener class, which implements CrewAI’s event listener. To use it, create an instance of the listener before you kick off your crew, for example in your run function. When this listener is created, it automatically registers event handlers to capture the relevant events.
from galileo.handlers.crewai.handler import CrewAIEventListener

def run():
    # Create the CrewAI Event Listener
    CrewAIEventListener()

    # Run the crew
    inputs = {
        'topic': 'AI Agents'
    }

    MyCrew().crew().kickoff(inputs=inputs)
The CrewAIEventListener captures various CrewAI events, including:
  • Crew Kickoff events
  • Agent events
  • Task events
  • Tool usage
  • LLM calls
For each of these events, the callback logs relevant information to Galileo, such as:
  • Input prompts and messages
  • Output responses
  • Model information
  • Timing data
  • Token usage
  • Error information (if any)
The CrewAIEventListener automatically handles nested crews and agents, creating a hierarchical trace that reflects the structure of your CrewAI application.

Use a custom logger

When initializing the CrewAIEventListener, you can optionally specify a Galileo logger instance, either by creating a new logger, or by using the current logger from the Galileo context:
from galileo.handlers.crewai.handler import CrewAIEventListener

def run():
    # Create a custom logger
    logger = GalileoLogger(project="my-project", log_stream="my-log-stream")

    # Create the CrewAI Event Listener
    CrewAIEventListener(
        galileo_logger=logger,       # Optional custom logger
        start_new_trace=True,        # Start a new trace for each crew
        flush_on_crew_completed=True # Flush traces when the crew completes
    )

    # Run the crew
    inputs = {
        'topic': 'AI Agents'
    }

    MyCrew().crew().kickoff(inputs=inputs)
This is particularly useful if you want to call your CrewAI code from inside a function decorated with the log decorator, or from inside an experiment.

Session and trace support

Every time you kick off a crew, a new session and trace is created. If you want to manually manage sessions or traces, you can do this using by passing a Galileo logger instance to the listener. To add the crew kickoff as a new trace to an existing session, create the session first using the logger instance that was used to create the listener:
from galileo.handlers.crewai.handler import CrewAIEventListener

def run():
    # Create a custom logger
    logger = GalileoLogger(project="my-project", log_stream="my-log-stream")

    # Create the CrewAI Event Listener
    CrewAIEventListener(
        galileo_logger=logger
    )

    # Create a new session
    logger.start_session(name="My new session")

    # Run the crew
    inputs = {
        'topic': 'AI Agents'
    }

    MyCrew().crew().kickoff(inputs=inputs)
To add the crew kickoff to an existing trace, ensure the trace is started, and set the start_new_trace parameter to False.
from galileo.handlers.crewai.handler import CrewAIEventListener

def run():
    # Create a custom logger
    logger = GalileoLogger(project="my-project", log_stream="my-log-stream")

    # Create the CrewAI Event Listener
    CrewAIEventListener(
        galileo_logger=logger,
        start_new_trace=False
    )

    # Create a new session
    logger.start_session(name="My new session")

    # Add a trace and a span
    logger.add_trace("My trace")
    logger.add_workflow_span("Crew workflow")

    # Run the crew
    inputs = {
        'topic': 'AI Agents'
    }

    MyCrew().crew().kickoff(inputs=inputs)

Next steps

Basic logging components

How-to guides