AI 智能体是基于 LLM 的实体,可以代表用户或智能体式 AI 系统执行操作。智能体架构围绕两个不同的系统构建:单智能体和多智能体。
单智能体系统最适合解决狭义问题,因为此类系统依赖 LLM 智能体来执行生成式 AI 任务。例如,单个聊天机器人智能体可以专注于其能力范围内可以完成的特定任务或对话。
多智能体系统 (MAS) 是协调 AI 智能体之间的功能和交互的框架。多智能体架构不是试图在单智能体中包含所有功能,而是使用不同的智能体在同一个环境中工作来实现共同的目标。多智能体系统的主要优点包括智能体协作和适应能力,可以解决超出单智能体功能的问题。最佳方法取决于编译解决方案或实现结果所需的机器学习任务的复杂性。
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
工具的描述是智能体用于对转录内容进行情感分析的逻辑依据。
智能体还可以使用现有工具和集成应用程序编程接口 (API)。质量保证专员有权访问
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
首先,我们需要设置环境来运行该应用程序。您可以在 GitHub 上的 crewAI 项目文件夹中的 markdown 文件中找到这些步骤, 也可以在这里执行这些步骤。
项目结构应类似于以下步骤:
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 搜索 API。
在本教程中,我们需要安装crewAI 框架,并设置我们在第 2 步中生成的watsonx.ai 凭据。
如果使用 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 和其他几个 API(例如 IBM watsonx 和 OpenAI)进行连接。用户还可以通过crewAI Toolkit 和 LangChain Tools 充分利用预构建工具。
确保已进入该项目的正确工作目录。您可以在终端中运行以下命令来切换目录。
要启动您的 AI 智能体团队并开始执行任务,请从项目的根文件夹运行此命令。请注意,该团队可能需要运行几分钟才能返回结果。
此命令初始化客户服务中心分析团队,按照配置中的定义组装智能体并为其分配任务。此示例未经修改,将使用 watsonx.ai 上的 IBM Granite 创建包含输出结果的 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 开发平台,让开发人员能够构建、部署和监控 AI 代理。
借助在业界首屈一指的全面功能,帮助企业构建、定制和管理 AI 智能体和助手,从而在提高生产力方面取得突破性进展。
借助专为提高开发人员效率而设计的 Granite 小型开放式模型,可实现 90% 以上的成本节约。这些企业就绪型模型可根据安全基准提供卓越的性能,且适用于多种企业任务,包括网络安全、RAG 等。