CrewAI는 복잡한 목표를 달성하기 위해 협업하는 자율 AI 에이전트를 조정하기 위한 프레임워크입니다. 역할을 지정하고, 목표를 지정하고, 배경 스토리를 지정하여 에이전트를 정의한 다음 에이전트의 작업을 정의할 수 있습니다.
이 예에서는 Gemini 3 Flash를 사용하여 고객 지원 데이터를 분석하여 문제를 식별하고 프로세스 개선사항을 제안하는 다중 에이전트 시스템을 빌드하는 방법을 보여줍니다. 이 시스템은 최고 운영 책임자 (COO)가 읽을 보고서를 생성합니다.
이 가이드에서는 다음 작업을 실행할 수 있는 AI 에이전트 '크루'를 만드는 방법을 보여줍니다.
- 고객 지원 데이터 가져오기 및 분석 (이 예에서 시뮬레이션됨)
- 반복되는 문제 및 프로세스 병목 현상 식별
- 실행 가능한 개선사항 제안
- COO에게 적합한 간결한 보고서로 발견 항목 컴파일
Gemini API 키가 필요합니다. 아직 키가 없으면 Google AI Studio에서 키를 가져올 수 있습니다.
pip install "crewai[tools]"Gemini API 키를 GEMINI_API_KEY라는 환경 변수로 설정한 다음 Gemini 모델을 사용하도록 CrewAI를 구성합니다.
import os
from crewai import LLM
gemini_api_key = os.getenv("GEMINI_API_KEY")
gemini_llm = LLM(
model='gemini/gemini-3.5-flash',
api_key=gemini_api_key,
temperature=1.0 # Use the Gemini 3 recommended temperature
)
구성요소 정의
도구, 에이전트, 태스크, 그리고 크루 자체를 사용하여 CrewAI 애플리케이션을 빌드합니다. 다음 섹션에서는 이러한 각 구성요소를 설명합니다.
도구
도구는 에이전트가 외부 세계와 상호작용하거나 특정 작업을 실행하는 데 사용할 수 있는 기능입니다. 여기서는 고객 지원 데이터 가져오기를 시뮬레이션하기 위해 자리표시자 도구를 정의합니다. 실제 애플리케이션에서는 데이터베이스, API 또는 파일 시스템에 연결합니다. 도구에 대한 자세한 내용은 CrewAI 도구 가이드를 참고하세요.
from crewai.tools import BaseTool
# Placeholder tool for fetching customer support data
class CustomerSupportDataTool(BaseTool):
name: str = "Customer Support Data Fetcher"
description: str = (
"Fetches recent customer support interactions, tickets, and feedback. "
"Returns a summary string.")
def _run(self, argument: str) -> str:
# In a real scenario, this would query a database or API.
# For this example, return simulated data.
print(f"--- Fetching data for query: {argument} ---")
return (
"""Recent Support Data Summary:
- 50 tickets related to 'login issues'. High resolution time (avg 48h).
- 30 tickets about 'billing discrepancies'. Mostly resolved within 12h.
- 20 tickets on 'feature requests'. Often closed without resolution.
- Frequent feedback mentions 'confusing user interface' for password reset.
- High volume of calls related to 'account verification process'.
- Sentiment analysis shows growing frustration with 'login issues' resolution time.
- Support agent notes indicate difficulty reproducing 'login issues'."""
)
support_data_tool = CustomerSupportDataTool()
에이전트
에이전트는 크루의 개별 AI 작업자입니다. 각 에이전트에는 특정 role, goal, backstory, 할당된 llm, 선택적 tools가 있습니다. 에이전트에 대한 자세한 내용은 CrewAI 에이전트
가이드를 참고하세요.
from crewai import Agent
# Agent 1: Data analyst
data_analyst = Agent(
role='Customer Support Data Analyst',
goal='Analyze customer support data to identify trends, recurring issues, and key pain points.',
backstory=(
"""You are an expert data analyst specializing in customer support operations.
Your strength lies in identifying patterns and quantifying problems from raw support data."""
),
verbose=True,
allow_delegation=False, # This agent focuses on its specific task
tools=[support_data_tool], # Assign the data fetching tool
llm=gemini_llm # Use the configured Gemini LLM
)
# Agent 2: Process optimizer
process_optimizer = Agent(
role='Process Optimization Specialist',
goal='Identify bottlenecks and inefficiencies in current support processes based on the data analysis. Propose actionable improvements.',
backstory=(
"""You are a specialist in optimizing business processes, particularly in customer support.
You excel at pinpointing root causes of delays and inefficiencies and suggesting concrete solutions."""
),
verbose=True,
allow_delegation=False,
# No tools needed, this agent relies on the context provided by data_analyst.
llm=gemini_llm
)
# Agent 3: Report writer
report_writer = Agent(
role='Executive Report Writer',
goal='Compile the analysis and improvement suggestions into a concise, clear, and actionable report for the COO.',
backstory=(
"""You are a skilled writer adept at creating executive summaries and reports.
You focus on clarity, conciseness, and highlighting the most critical information and recommendations for senior leadership."""
),
verbose=True,
allow_delegation=False,
llm=gemini_llm
)
작업
작업은 에이전트의 특정 할당을 정의합니다. 각 작업에는 description, expected_output이 있으며 agent에 할당됩니다. 작업은 기본적으로 순차적으로 실행되며 이전 작업의 컨텍스트를 포함합니다. 작업에 대한 자세한 내용은 CrewAI 작업
가이드를 참고하세요.
from