本示例说明了如何创建一个 AI 支持团队,该团队可以根据客户咨询的性质,将其路由到合适的客服人员。
from agno.agent import Agent
from agno.knowledge.website import WebsiteKnowledgeBase
from agno.models.openai import OpenAIChat
from agno.team.team import Team
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.exa import ExaTools
from agno.tools.slack import SlackTools
from agno.vectordb.pgvector.pgvector import PgVector
knowledge_base = WebsiteKnowledgeBase(
urls=["https://docs.agno.com/introduction"],
# 要从种子 URL 跟踪的链接数量
max_links=10,
# 表名: ai.website_documents
vector_db=PgVector(
table_name="website_documents",
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
),
)
knowledge_base.load(recreate=False)
support_channel = "testing"
feedback_channel = "testing"
doc_researcher_agent = Agent(
name="文档研究员 Agent",
role="在知识库中搜索信息",
model=OpenAIChat(id="gpt-4o"),
tools=[DuckDuckGoTools(), ExaTools()],
knowledge=knowledge_base,
search_knowledge=True,
instructions=[
"你是给定产品的文档专家。请仔细搜索知识库以回答用户的问题。",
"始终根据文档提供准确的信息。",
"如果问题与常见问题解答匹配,请提供文档中的具体常见问题解答。",
"在相关时,包含指向解决用户问题的特定文档页面的直接链接。",
"如果您对答案不确定,请承认这一点并建议用户可以在哪里找到更多信息。",
"根据需要使用标题、项目符号和代码示例清晰地格式化您的响应。",
"始终验证您的答案是否直接解决了用户提出的具体问题。",
"如果您在知识库文档中找不到答案,请使用 DuckDuckGoTools 或 ExaTools 在网上搜索相关信息来回答用户的问题。",
],
)
escalation_manager_agent = Agent(
name="升级经理 Agent",
role="将问题升级到 slack 频道",
model=OpenAIChat(id="gpt-4o"),
tools=[SlackTools()],
instructions=[
"您是负责将关键问题路由到支持团队的升级经理。",
f"当用户报告问题时,请始终使用 send_message 工具函数将其与所有相关详细信息一起发送到 #{support_channel} Slack 频道。",
"包括用户的姓名、联系信息(如果可用)以及问题的清晰描述。",
"升级问题后,回复用户,确认他们的问题已得到升级。",
"您的回复应专业且令人安心,让他们知道支持团队将很快处理。",
"请始终包含票证或参考号(如果可用),以帮助用户跟踪他们的问题。",
"切勿尝试自己解决技术问题——您的职责严格是升级和沟通。",
],
)
feedback_collector_agent = Agent(
name="反馈收集员 Agent",
role="收集用户反馈",
model=OpenAIChat(id="gpt-4o"),
tools=[SlackTools()],
description="您是一个可以收集用户反馈的 AI Agent。",
instructions=[
"您负责收集用户关于产品或功能请求的反馈。",
f"当用户提供反馈或建议功能时,请使用 Slack 工具通过 send_message 工具函数将其发送到 #{feedback_channel} 频道。",
"在您的 Slack 消息中包含用户反馈的所有相关详细信息。",
"将反馈发送到 Slack 后,请专业地回复用户,感谢他们的贡献。",
"您的回复应确认他们的反馈,并向他们保证他们的反馈将被考虑在内。",
"在语气上要热情和感激,因为用户反馈对于改进我们的产品非常有价值。",
"不要承诺具体的时间表或保证他们的建议将被采纳。",
],
)
customer_support_team = Team(
name="客户支持团队",
mode="route",
model=OpenAIChat("gpt-4.5-preview"),
enable_team_history=True,
members=[doc_researcher_agent, escalation_manager_agent, feedback_collector_agent],
show_tool_calls=True,
markdown=True,
debug_mode=True,
show_members_responses=True,
instructions=[
"您是负责分类和路由客户咨询的首席客户支持代理。",
"仔细分析每条用户消息,判断它是:需要文档研究的问题、需要升级的错误报告、还是产品反馈。",
"对于产品的一般问题,请路由到 doc_researcher_agent,它将搜索文档以获取答案。",
"如果 doc_researcher_agent 找不到问题的答案,则将其路由到 escalation_manager_agent。",
"对于错误报告或技术问题,请立即路由到 escalation_manager_agent。",
"对于功能请求或产品反馈,请路由到 feedback_collector_agent。",
"始终清楚地解释您将咨询路由到特定代理的原因。",
"在收到相应代理的回复后,以专业且有帮助的方式将该信息传达给用户。",
"通过在整个对话中保持上下文,确保用户获得无缝的体验。",
],
)
# 添加查询,代理会将其重定向到相应的代理
customer_support_team.print_response(
"Hi Team, I want to build an educational platform where the models are have access to tons of study materials, How can Agno platform help me build this?",
stream=True,
)
# customer_support_team.print_response(
# "[Feature Request] Support json schemas in Gemini client in addition to pydantic base model",
# stream=True,
# )
# customer_support_team.print_response(
# "[Feature Request] Can you please update me on the above feature",
# stream=True,
# )
# customer_support_team.print_response(
# "[Bug] Async tools in team of agents not awaited properly, causing runtime errors ",
# stream=True,
# )
创建虚拟环境
打开 Terminal
并创建一个 python 虚拟环境。
python3 -m venv .venv
source .venv/bin/activate
安装所需的库
pip install openai duckduckgo-search slack_sdk exa_py
设置环境变量
export OPENAI_API_KEY=****
export SLACK_TOKEN=****
export EXA_API_KEY=****
运行 Agent
python ai_support_team.py