CrewAI is a framework for easily building multi-agent applications. AgentOps integrates with CrewAI to provide observability into your agent workflows. Crew has comprehensive documentation available as well as a great quickstart guide.

Installation

Install AgentOps and CrewAI, along with python-dotenv for managing API keys:

pip install agentops crewai python-dotenv

Setting Up API Keys

You’ll need API keys for AgentOps and OpenAI (since CrewAI’s built-in LLM uses OpenAI models by default):

Set these as environment variables or in a .env file.

export OPENAI_API_KEY="your_openai_api_key_here"
export AGENTOPS_API_KEY="your_agentops_api_key_here"

Then load them in your Python code:

from dotenv import load_dotenv
import os

load_dotenv()

AGENTOPS_API_KEY = os.getenv("AGENTOPS_API_KEY")
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

Usage

Simply initialize AgentOps at the beginning of your CrewAI application. AgentOps automatically instruments CrewAI components—including its LLM—to track your agent interactions.

Here’s how to set up a basic CrewAI application with AgentOps:

import agentops
from crewai import Agent, Task, Crew, LLM

# Initialize AgentOps client
agentops.init()

# Define the LLM to use with CrewAI
llm = LLM(
    model="openai/gpt-4o",  # Or your preferred model
    temperature=0.7,
)

# Create an agent
researcher = Agent(
    role='Researcher',
    goal='Research and provide accurate information about cities and their history',
    backstory='You are an expert researcher with vast knowledge of world geography and history.',
    llm=llm,
    verbose=True
)

# Create a task
research_task = Task(
    description='What is the capital of France? Provide a detailed answer about its history, culture, and significance.',
    expected_output='A comprehensive response about Paris, including its status as the capital of France, historical significance, cultural importance, and key landmarks.',
    agent=researcher
)

# Create a crew with the researcher
crew = Crew(
    agents=[researcher],
    tasks=[research_task],
    verbose=True
)

# Execute the task
result = crew.kickoff()

print("\nCrew Research Results:")
print(result)

Examples