CrewAI is a framework for easily building multi-agent applications. Crew has comprehensive documentation available as well as a great quickstart guide.

1

Install the AgentOps SDK

pip install agentops crewai
2

Add AgentOps to your code

Make sure to call agentops.init before calling any openai, cohere, crew, etc models.

import os
from dotenv import load_dotenv
import agentops
from crewai import Agent, Task, Crew
from langchain_openai import ChatOpenAI

# Load environment variables
load_dotenv()

# Initialize AgentOps
agentops.init(os.getenv("AGENTOPS_API_KEY"))

# Create LLM
llm = ChatOpenAI(
	model="gpt-4",
	temperature=0.7,
	api_key=os.getenv("OPENAI_API_KEY")
)

# 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 - AgentOps will automatically track all LLM calls
result = crew.kickoff()

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

Set your API key as an .env variable for easy access.

AGENTOPS_API_KEY=<YOUR API KEY>
OPENAI_API_KEY=<YOUR OPENAI API KEY>

Read more about environment variables in Advanced Configuration

3

Run your crew

Execute your program and visit app.agentops.ai/traces to observe your Crew! 🕵️

After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard

Clickable link to session

Important Notes

  1. The Task class requires an expected_output field that describes what the task should produce
  2. Setting verbose=True on both the agent and crew provides better visibility into the execution process
  3. Tasks should have clear, detailed descriptions to guide the agent effectively

Crew + AgentOps Examples