CrewAI הוא פריימוורק לניהול סוכני AI אוטונומיים שמשתפים פעולה כדי להשיג יעדים מורכבים. הוא מאפשר להגדיר סוכנים על ידי ציון תפקידים, יעדים וסיפורי רקע, ולאחר מכן להגדיר להם משימות.
בדוגמה הזו נסביר איך לבנות מערכת מרובת סוכנים לניתוח נתונים של תמיכת לקוחות כדי לזהות בעיות ולהציע שיפורים בתהליכים באמצעות Gemini 3 Flash. המערכת יוצרת דוח שמיועד לקריאה על ידי מנהל תפעול ראשי (COO).
במדריך הזה נסביר איך ליצור 'צוות' של סוכני AI שיכולים לבצע את המשימות הבאות:
- אחזור וניתוח של נתוני תמיכת לקוחות (סימולציה בדוגמה הזו).
- זיהוי בעיות חוזרות וצווארי בקבוק בתהליך.
- להציע שיפורים פרקטיים.
- לרכז את הממצאים בדוח תמציתי שמתאים למנהל תפעול ראשי.
אתם צריכים מפתח Gemini API. אם עדיין אין לכם חשבון, אתם יכולים ליצור חשבון ב-Google AI Studio.
pip install "crewai[tools]"מגדירים את מפתח Gemini API כמשתנה סביבה בשם GEMINI_API_KEY, ואז מגדירים את CrewAI כך שישתמש במודל Gemini.
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 באמצעות Tools, Agents, Tasks ו-Crew. בקטעים הבאים מוסבר על כל אחד מהרכיבים האלה.
כלים
כלים הם יכולות שסוכנים יכולים להשתמש בהן כדי ליצור אינטראקציה עם העולם החיצוני או לבצע פעולות ספציפיות. כאן מגדירים כלי placeholder כדי לדמות אחזור של נתוני תמיכת לקוחות. באפליקציה אמיתית, מתחברים למסד נתונים, ל-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=(