CrewAI
CrewAI
AgentOps와 CrewAI가 함께 협력해 Crew 에이전트 모니터링을 아주 간단하게 만든 방법을 소개해요. 설치, API 키 설정, 그리고 기본 설정 예제까지 알아볼게요.
출처: 문서
본문
영상 튜토리얼 (Video Tutorial)
CrewAI는 멀티 에이전트 애플리케이션을 쉽게 구축하기 위한 프레임워크예요. AgentOps는 CrewAI와 통합되어 에이전트 워크플로우에 대한 관측성을 제공합니다. Crew는 포괄적인 문서와 훌륭한 퀵스타트 가이드도 갖추고 있어요.
설치 (Installation)
AgentOps와 CrewAI를 설치하고, API 키 관리용 python-dotenv도 함께 설치하세요.
poetry add agentops crewai python-dotenv
uv pip install agentops crewai python-dotenv
API 키 설정 (Setting Up API Keys)
AgentOps와 OpenAI에 대한 API 키가 필요해요 (CrewAI의 내장 LLM이 기본적으로 OpenAI 모델을 사용하기 때문이에요).
- OPENAI_API_KEY: OpenAI Platform에서
- AGENTOPS_API_KEY: AgentOps Dashboard에서
이것들을 환경 변수나 .env 파일로 설정하세요.
OPENAI_API_KEY="your_openai_api_key_here"
AGENTOPS_API_KEY="your_agentops_api_key_here"
그리고 Python 코드에서 로드합니다.
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)
CrewAI 애플리케이션 시작 시 AgentOps를 초기화하기만 하면 됩니다. AgentOps는 CrewAI 컴포넌트 — 그 LLM을 포함해 — 를 자동으로 계측해 에이전트 상호작용을 추적합니다.
AgentOps와 함께 기본 CrewAI 애플리케이션을 설정하는 방법은 다음과 같습니다.
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)