في هذا البرنامج التعليمي، نوضِّح كيف يمكن لفريق من وكلاء الذكاء الاصطناعي (AI) المتعددين التعاون لإكمال المهام المعقدة وتحسين سير العمل. طوَّرنا تطبيقًا بلغة Python لشرح تنسيق عمل الوكلاء المتخصصين الذين يعملون ضمن بنية متعددة الوكلاء. في النهاية، سترى وتنفِّذ مثالًا للتعاون بين عدة وكلاء داخل تطبيق الذكاء الاصطناعي الوكيل.
التطبيق الذي نعمل عليه هو طاقم لتحليل خدمة العملاء، باستخدام CrewAI كإطار متعدد الوكلاء، وIBM watsonx.ai لنشر النموذج اللغوي الكبير (LLM) الذي يشغِّله.
وكلاء الذكاء الاصطناعي هم كيانات تعتمد على نماذج LLM ويمكنها تنفيذ عمليات نيابةً عن المستخدم أو عن نظام ذكاء اصطناعي وكيل. يتم تنظيم البنية الوكيلية حول نظامين مختلفين: وكيل واحد ومتعدد الوكلاء.
تُعَد أنظمة الوكيل الفردي هي الأفضل لحل المشكلات الضيقة لأنها تعتمد على وكيل LLM واحد لأداء مهام الذكاء الاصطناعي التوليدي. على سبيل المثال، يمكن أن يركِّز وكيل روبوت المحادثة على مهام أو محادثات محددة يمكنه إكمالها في نطاق قدراته.
الأنظمة متعددة الوكلاء (MAS) هي أطر عمل تنظِّم الوظائف والتفاعلات بين وكلاء الذكاء الاصطناعي. بدلًا من محاولة احتواء جميع القدرات داخل وكيل واحد، تستخدم البنيات متعددة الوكلاء وكلاء مختلفين للعمل داخل البيئة نفسها لتحقيق هدف مشترك. تتضمن الميزة الرئيسية للأنظمة متعددة الوكلاء التعاون بين الوكلاء والقدرة على التكيف لحل المشكلات التي تتجاوز القدرات. يعتمد النهج الأفضل على مدى تعقيد مهام التعلم الآلي المطلوبة لتجميع حل أو تحقيق نتائج محددة.
crewAI هو إطار عمل وكيلي مفتوح المصدر ينظِّم أتمتة وكيل LLM من خلال تجميع أطقم قابلة للتخصيص أو فرق من وكلاء تقمُّص الأدوار. طبَّقنا حالة استخدام مبسَّطة في الصناعة لشرح كيفية تعاون الوكلاء ضمن بنية متعددة الوكلاء.
تخيَّل حالة استخدام حقيقية لمركز اتصال خدمة العملاء. يتم استخدام برامج الاتصالات لتحليل نصوص مراكز الاتصال لتحسين تجارب العملاء وتقييم جودة المكالمات. في البرامج الأكثر قوة، يمكن تحليل النصوص المكتوبة في الوقت الفعلي إلى جانب مجموعات البيانات الكبيرة بما في ذلك بيانات الاتصال. من أجل سهولة التوضيح، فإن مجموعة بيانات تطبيقنا بسيطة، وهي عبارة عن نسخة طبق الأصل من محادثة بين ممثل خدمة العملاء والعميل.
# multiagent-collaboration-cs-call-center-analysis/data/transcript.txt
Customer Service Interaction Transcript
Cynthia:
Hi, I'm calling because I received a jar of peanut butter that was open and it's
completely spilled everywhere. This is really frustrating, and I need a replacement.
Gerald (Peanut Butter Inc.):
Ugh, that sucks. But, like, how did you not notice it was open before
you bought it?
Cynthia:
Excuse me? I didn't expect the jar to be open when I received it. It was sealed
when I bought it. Can you just help me out here?
Gerald:
Yeah, whatever. But we can't control how it gets to you. I mean, it's not like
we throw the jars around or anything. You're probably being dramatic.
Cynthia:
I'm not being dramatic. The peanut butter is literally all over the box and
it's a mess. I just want a replacement or a refund, that's all.
Gerald:
Look, I guess I could send you a replacement, but it's really not our fault, you
know? Maybe next time, check the jar before you open it?
Cynthia:
Are you seriously blaming me for your company's mistake? That's not how customer
service works!
Gerald:
Well, what do you want me to do? I don't exactly have magic powers to fix your
problem instantly. Chill out, we'll send you a new jar eventually.
Cynthia:
That's not good enough! I expect better from a company that I've been buying
from for years. Can you just do the right thing and make this right?
Gerald:
Fine, fine. I'll put in a request or whatever. But seriously, this kind of thing
happens. Don't make it sound like the end of the world.
Cynthia:
Unbelievable. I'll be posting a review if this isn't fixed immediately.
Gerald:
Cool, go ahead. I'm sure we'll survive your review.
Cynthia:
I'll be contacting your supervisor if this isn't resolved soon.
Gerald:
Yeah, okay. Do what you gotta do.
يقوم فريق من الوكلاء المتعاونين بإنشاء تقرير شامل يعتمد على تحليل النص ومقاييس تقييم مركز اتصال العملاء. يساعد هذا التقرير مديري خدمة العملاء على تلخيص الأحداث الرئيسية للمكالمة وتقييم الأداء وتقديم توصيات للتحسين.
يتكون فريق تحليل مكالمات خدمة العملاء من ثلاثة وكلاء لديهم أدوار متخصصة وأهداف محددة مسبقًا. يتضمن تكوين الوكيل محللًا للنصوص ومتخصصًا في ضمان الجودة ومنشئًا للتقارير. يتم تحديد أهداف وخصائص الوكيل من خلال ثلاث سمات رئيسية، وهي الدور والهدف والقصة الخلفية.
transcript_analyzer:
role: >
Transcript Analyzer
goal: >
Analyze the provided transcripts and extract key insights and themes.
backstory: >
As the Transcript Analyzer, you are responsible for reviewing customer
service call transcripts, identifying important information, and summarizing
findings into a report to pass on to the Quality Assurance Specialist.
You have access to advanced text analysis tools that help you process and
interpret the data effectively.
quality_assurance_specialist:
role: >
Quality Assurance Specialist
goal: >
Evaluate the quality of the customer service based the Transcript Analyzer's
report, call center evaluation metrics, and business standards. Flag any
transcripts with escalation risks as high priority.
backstory: >
As the Quality Assurance Specialist, you are tasked with assessing the
quality of customer service interactions based on the Transcript Analyzer's
report, call center evaluation metrics, and industry standards used in call
centers. You review transcripts, evaluate agent performance, and provide
feedback to improve overall service quality.
report_generator:
role: >
Report Generator
goal: >
Generate reports based on the insights and findings from the transcript
analysis and quality assurance specialist.
backstory: >
As the Report Generator, you compile the key insights and findings from the
transcript analysis and quality assurance specialist into a comprehensive
report. You create an organized report that includes summaries and recommendations
based on the data to help customer service managers understand the trends
and patterns in customer interactions.
يُجري وكيل محلل النصوص تحليلًا شاملًا للنصوص لاستخراج الأفكار الرئيسية والمعلومات المهمة. ثم يلخص المحلل النتائج التي توصَّل إليها في تقرير يتم تمريره إلى الوكلاء الآخرين للمساعدة على مهامهم. يستخدم هذا الوكيل مجموعة من الأدوات المخصصة لتنفيذ تقنيات معالجة اللغة الطبيعية (NLP) مثل استخراج الكلمات الرئيسية وتحليل المشاعر.
يقوم الوكيل متخصص ضمان الجودة بتقييم جودة المكالمة بناءً على الرؤى الرئيسية من تقرير محلل النصوص وخبرته الموصوفة في تنفيذ وتقييم مقاييس تقييم مركز الاتصال. يمكن لهذا الوكيل أيضًا البحث على الإنترنت لاسترداد المقاييس والعمليات ذات الصلة لتقييم أداء الموظف وتقديم ملاحظات لتحسين جودة الخدمة بشكل عام.
يقوم وكيل إنشاء التقارير بإنشاء تقرير بناءً على المعلومات الواردة في تقرير تحليل النص والمقاييس والتعليقات المقدَّمة من خلال تقييم ضمان الجودة. يتخصص الوكيل في تنظيم البيانات في تقرير شامل. الهدف من التقرير هو تزويد مديري خدمة العملاء بتفصيل للرؤى الرئيسية من المكالمة والتوصيات لتحسين جودة خدمة العملاء.
كل وكيل لديه إمكانية الوصول إلى الأدوات والمهارات أو الوظائف التي يستخدمها الوكلاء لأداء مهام مختلفة. يوفر crewAI الأدوات الحالية والتكامل مع أدوات LangChain وخيار إنشاء أدواتك المخصصة. يستخدم فريق تحليل خدمة العملاء مجموعة من الأدوات، حيث يتم تحديد كل أداة وفقًا لمهمة الموظف والهدف من التطبيق. يتمتع كل وكيل بأذونات معينة فيما يتعلق بالأدوات التي يمكنه الوصول إليها في تكوينه.
يتم إنشاء الأدوات المخصصة من خلال تحديد وصف واضح للغرض من استخدام الأداة. على سبيل المثال، يحتوي وكيل محلل النص على العديد من الأدوات المخصصة لتحليل النص.
# src/customer_service_analyzer/tools/custom_tool.py
class SentimentAnalysisTool(BaseTool):
name: str = "Sentiment Analysis Tool"
description: str = "Determines the sentiment of the interactions in the transcripts."
def _run(self, transcript: str) -> str:
# Simulating sentiment analysis
sentiment = Helper.analyze_sentiment(transcript)
return sentiment
وصف الأداة هو ما يستخدمه الوكيل كمنطق لإجراء تحليل المشاعر على النص.
يمكن للوكلاء أيضًا استخدام الأدوات الحالية وواجهات برمجة التطبيقات (APIs) المتكاملة. يمكن للوكيل المتخصص في ضمان الجودة الوصول إلى
transcript_analysis:
description: >
Use the Text Analysis Tool to collect key information and insights to better
understand customer service interactions and improve service quality.
Conduct a thorough analysis of the call {transcript}.
Prepare a detailed report highlighting key insights, themes, and sentiment
from the transcripts.
Identify any escalation risks and flag them for the Quality Assurance Specialist.
Use the sentiment analysis tool to determine the overall sentiment of the
customer and the agent.
Use the keyword extraction tool to identify key keywords and phrases in the transcript.
expected_output: >
A detailed analysis report of the {transcript} highlighting key insights,
themes, and sentiment from the transcripts.
agent: transcript_analyzer
quality_evaluation:
description: >
Review the transcript analysis report on {transcript} from the Transcript Analyzer.
Utilize your expertise in customer service evaluation metrics and industry
standards, and internet to evaluate the quality of the customer service interaction.
Score the interaction based on the evaluation metrics and flag any high-risk
escalations. Develop expert recommendations to optimize customer service
quality. Ensure the report includes customer service metrics and feedback
for improvement.
expected_output: >
A detailed quality evaluation report of the {transcript} highlighting the
quality of the customer service interaction, scoring based on evaluation
metrics, flagging any high-risk escalations, and recommendations for improvement.
agent: quality_assurance_specialist
report_generation:
description: >
List the reports from the Transcript Analyzer and the Quality Assurance
Specialist, then develop a detailed action plan for customer service managers
to implement the changes.
Use the data from these agents output to create an organized report including
a summarization and actionable recommendations for call center managers.
Ensure the report includes keywords and sentiment analysis from the Transcript
Analyzer agent.
Ensure the report includes the Quality Assurance Specialist agent's report,
evaluation metrics and recommendations for improving customer service quality.
Ensure the report is well written and easy to understand.
Be smart and well explained.
Ensure the report is comprehensive, organized, and easy to understand with
labeled sections with relevant information.
expected_output: >
A comprehensive report that lists the reports from the Transcript Analyzer,
then the Quality Assurance Specialist.
The report should include the key insights from {transcript} and the quality
evaluation report from the Quality Assurance Specialist.
The report should include organized sections for each agent's findings,
summaries, and actionable recommendations for call center managers.
agent: report_generator
context:
- transcript_analysis
- quality_evaluation
يتم تنفيذ سير عمل المهمة في عملية متسلسلة تبدأ بتحليل النص الذي يتم إجراؤه بواسطة محلل النصوص. يمكن لنتائج مهمة ما أن تشكِّل سياقًا لمهمة مستقبلية. خلال التسلسل التالي، يستخدم متخصص ضمان الجودة تقرير تحليل النص لتوجيه تقييم الجودة الخاص به، مع ملاحظة أي كلمات رئيسية أو عبارات تُشير إلى التصعيد.
يستخدم وكيل إنشاء التقارير مخرجات محلل النسخ ووكلاء متخصصي ضمان الجودة كسياق لإنشاء تقرير شامل حول نسخة المكالمة. هذا التدفق هو مثال على التعاون متعدد الوكلاء وكيف يمكن للوكلاء إنجاز مهام معقدة وتوليد مخرجات أكثر قوة مع زيادة الوعي بالسياق أثناء أداء أدوارهم المتخصصة.
أولًا، نحتاج إلى إعداد البيئة الخاصة بنا لتشغيل التطبيق. يمكنك العثور على هذه الخطوات في ملف Markdown داخل مجلد مشروع crewAI على GitHub أو من خلال المتابعة هنا.
يجب أن تشبه بنية المشروع الخطوات التالية:
src/customer_service_analyzer/
├── config/
│ ├── agents.yaml # Agent configurations
│ └── tasks.yaml # Task definitions
├── tools/
│ ├── custom_tool.py # Custom crewAI tool implementations
│ └── tool_helper.py # Custom tool helper functions
├── crew.py # Crew orchestration
└── main.py # Application entry point
أنشئ مفتاح Serper API المجاني الخاص بك ودوِّنه. Serper هي واجهة برمجة تطبيقات بحث Google التي نستخدمها في هذا المشروع.
نحتاج إلى تثبيت إطار عمل crewAI لهذا البرنامج التعليمي وإعداد بيانات اعتماد watsonx.ai التي أنشأناها في الخطوة 2.
إذا كنت تستخدم uv لإدارة الحزم، يمكنك إضافة crewAI على النحو التالي:
إذا كنت تستخدم pip لإدارة الحزم، فقم بإعداد بيئة افتراضية ثم تثبيت crewAI في تلك البيئة.
لتثبيت crewAI، قم بتشغيل الأمر التالي في محطتك الطرفية.
In a separate .env file at the same directory level as the .env_sample file, set your credentials as strings like so:
WATSONX_APIKEY=your_watson_api_key_here
WATSONX_PROJECT_ID=your_watsonx_project_id_here
WATSONX_URL=your_endpoint (e.g. "https://us-south.ml.cloud.ibm.com")
SERPER_API_KEY=your_serper_api_key_here
يمكن تكوين crewAI لاستخدام أي نموذج LLM مفتوح المصدر. يمكن ربط نماذج LLM من خلال Ollama والعديد من واجهات برمجة التطبيقات الأخرى مثل IBM watsonx وOpenAI. يمكن للمستخدمين أيضًا الاستفادة من الأدوات المعدة مسبقًا والمتاحة من خلال CrewAI Toolkit بالإضافة إلى LangChain Tools.
تأكَّد من أنك في دليل العمل الصحيح لهذا المشروع. يمكنك تغيير الدلائل عن طريق تشغيل الأمر التالي في المحطة الطرفية.
لبدء تشغيل فريق وكلاء الذكاء الاصطناعي لديك وبدء تنفيذ المهام، قم بتشغيل هذا الأمر من المجلد الجذر لمشروعك. لاحِظ أن الطاقم قد يستمر في العمل لعدة دقائق قبل إرجاع النتيجة.
يقوم هذا الأمر بتهيئة طاقم تحليل مركز الاتصال، وتجميع الوكلاء وتعيين المهام لهم كما هو محدد في التكوين الخاص بك. سيقوم هذا المثال، دون تعديل، بتشغيل IBM Granite على watsonx.ai لإنشاء ملف report.md بالإخراج. يمكن لـ crewAI إرجاع JSON ونماذج Pydantic والسلاسل الخام كمخرجات. فيما يلي مثال على المخرجات التي يُنتجها الطاقم.
This result is an example of the final output after running the crew:
**Detailed Analysis Report of the Customer Service Interaction Transcript**
**Transcript Analysis Report**
The customer, Cynthia, called to report a damaged product, a jar of peanut butter that was open and spilled everywhere. She requested a replacement, but the agent, Gerald, responded defensively and blamed her for not noticing the damage before purchasing. The conversation escalated, with Cynthia becoming frustrated and threatening to post a negative review and contact the supervisor.
**Key Insights and Themes**
* The customer was dissatisfied with the product and the agent's response.
* The agent was unhelpful, unprofessional, and failed to take responsibility for the company's mistake.
* The conversation was confrontational, with both parties becoming increasingly agitated.
* The customer felt disrespected and unvalued, while the agent seemed dismissive and uncaring.
**Sentiment Analysis**
* Customer Sentiment: Frustrated, Angry, Disappointed
* Agent Sentiment: Defensive, Dismissive, Uncaring
**Keyword Extraction**
* Damaged Product
* Unhelpful Agent
* Confrontational Conversation
* Customer Dissatisfaction
* Unprofessional Response
**Escalation Risks**
* Negative Review: The customer threatened to post a negative review if the issue was not resolved promptly.
* Supervisor Involvement: The customer may contact the supervisor to report the incident and request further action.
**Recommendations for Quality Assurance Specialist**
* Review the call recording to assess the agent's performance and provide feedback on areas for improvement, using customer service metrics.
* Investigate the root cause of the damaged product and implement measures to prevent similar incidents in the future.
* Provide training on customer service skills, including active listening, empathy, and conflict resolution, using customer service standards.
* Monitor the customer's feedback and respond promptly to any concerns or complaints to maintain a positive customer experience.
* Recognize the standards for various customer service metrics to measure key performance indicators that are related to the areas mentioned above.
**Summary of Quality Evaluation Report**
The customer, Cynthia, called to report a damaged product, a jar of peanut butter that was open and spilled everywhere. She requested a replacement, but the agent, Gerald, responded defensively and blamed her for not noticing the damage before purchasing. Evaluation metrics showed a low Customer Satisfaction Score (CSAT), high Customer Effort Score (CES), and negative Net Promoter Score (NPS).
**Recommendations for Call Center Managers**
* Review the call recording, investigate the root cause of the damaged product, and provide training on customer service skills. Recognize the standards for various customer service metrics to measure key performance indicators.
* Monitor the customer's feedback and respond promptly to any concerns or complaints to maintain a positive customer experience.
* Implement measures to prevent similar incidents in the future, such as improving product packaging and handling procedures.
* Provide feedback and coaching to agents on their performance, highlighting areas for improvement and recognizing good performance.
كما هو موضح في الناتج النموذجي، عمل الوكلاء معًا لإكمال المهمة المعقدة المتمثلة في تحليل وتقييم وإنشاء تقرير حول النص الأصلي. أدى التعاون بين الوكلاء إلى تعزيز كفاءة التطبيق ودقته من خلال إدارة عمل كل وكيل ليتخصص في جانب معين من العملية. على سبيل المثال، أنشأ وكيل التقرير تقريرًا منظمًا يتضمن نتائج مهام التحليل والتقييم النصي. تعكس هذه النتيجة تنسيقًا سلسًا بين الوكلاء في التعامل مع أجزاء مختلفة من سير العمل.
يمكن أن توفِّر أطر العمل متعددة الوكلاء أداءً أكثر قوة وتحسينًا من خلال التعاون بين الوكلاء. لا تعمل كل بنية متعددة الوكلاء بالطريقة نفسها. على سبيل المثال، بعضها مخصص لتطوير البرمجيات، في حين أن البعض الآخر مثل crewAI وAutoGen يقدِّم تكوينات أكثر قابلية للتكوين.
تمكين المطورين من إنشاء وكلاء الذكاء الاصطناعي ونشرهم ومراقبتهم باستخدام استوديو IBM watsonx.ai.
حقِّق إنتاجية غير مسبوقة مع مجموعة من أكثر الحلول تكاملًا في القطاع لمساعدة الأعمال على بناء وتخصيص وإدارة وكلاء ومساعدي الذكاء الاصطناعي.
تحقيق وفورات في التكاليف تزيد على 90% باستخدام نماذج Granite الصغيرة والمفتوحة المصممة لتعزيز كفاءة المطوِّرين. تقدِّم هذه النماذج الجاهزة للمؤسسات أداءً استثنائيًا في معايير الأمان، وتتفوق في مجموعة واسعة من المهام المؤسسية من الأمن الإلكتروني إلى التوليد المعزز بالاسترجاع (RAG).