个人AI副驾驶正逐渐成为真正的游戏规则改变者。它们有潜力改变我们管理日常任务和责任的方式。与基本的聊天机器人不同,这些智能助手是复杂的系统,能够理解我们个人生活的细微差别,使我们的日常活动更加顺畅和高效。
构建这样的AI副驾驶可能会相当复杂,如果没有适当的基础设施。AWS多代理编排器是一个灵活且强大的框架,用于管理多个AI代理。该编排器的分类器根据用户输入、代理的特性以及对话历史选择合适的代理。编排器还便于在每个代理的对话历史中进行存储。通过这种方式,可以确保每次交互都得到最合适的处理。
为各种任务构建AI副驾驶
让我们构建一个AI 副驾驶,它可以检查日历、建议健身计划,并同时阅读新闻。这些是完全独立的任务,在用户与它们互动的过程中可能具有不同的上下文。这个个人助理的完整源代码可以在 这里找到。
日历代理
这是一个链式代理,内部使用ApiAgent通过Calendly API获取日历邀请。ApiAgent的响应将流式传输到BedrockLLMAgent以总结邀请。
agent1 = ApiAgent(ApiAgentOptions(
endpoint = f"https://api.calendly.com/user_busy_times?user={CALENDLY_USER_URI}&start_time={start_time}&end_time={end_time}",
method = "GET",
name = "Calendly Schedule Agent",
description = "Specializes in Calendar scheduling",
streaming=False,
headers_callback=custom_headers_callback,
))
agent2 = BedrockLLMAgent(BedrockLLMAgentOptions(
name="Calendar Summarization",
streaming=True,
description="You are an AI agent specialized in summarizing calendar events. Given a list of events, produce a concise summary"\
" highlighting key details such as event names, dates, times, and participants. Ensure the summary is clear, brief, and "\
"informative for quick understanding. Do not provide duplicate information or irrelevant details.",
model_id="anthropic.claude-3-5-sonnet-20240620-v1:0",
callbacks=ChainlitAgentCallbacks()
))
新闻阅读代理
新闻阅读代理也利用了链式代理,内部使用ApiAgent通过Gnews API获取新闻。ApiAgent的响应将流式传输到BedrockLLMAgent以总结新闻。
agent1 = ApiAgent(ApiAgentOptions(
endpoint = f"https://gnews.io/api/v4/search?q=example&apikey={GNEWS_API_KEY}",
method = "GET",
name = "News Reader Agent",
description = "Specializes in reading news from various sources",
streaming=False
))
agent2 = BedrockLLMAgent(BedrockLLMAgentOptions(
name="News Summarization Agent",
streaming=True,
description="You are a skilled journalist tasked with creating concise, engaging news summaries."\
"Given the following text, produce a clear and informative summary that captures the key points," \
"main actors, and significant details. Your summary should be objective, well-structured, "\
"and easily digestible for a general audience. Aim for clarity and brevity while maintaining the essence of the news story.",
model_id="anthropic.claude-3-5-sonnet-20240620-v1:0",
callbacks=ChainlitAgentCallbacks()
))
健身代理
健身代理是一个独立的代理,使用LLM模型来建议健身计划、饮食计划和健康提示。
fitness_agent = BedrockLLMAgent(BedrockLLMAgentOptions(
name="Fitness Agent",
streaming=True,
description="Specializes in fitness, health, and wellness. It can provide workout routines, diet plans, and general health tips.",
model_id="anthropic.claude-3-5-sonnet-20240620-v1:0",
callbacks=ChainlitAgentCallbacks()
))
运行应用
按照以下说明进行准备工作。
1. 克隆仓库:
git clone https://github.com/ravilaudya/task-copilot.git
cd task-copilot
2. 创建虚拟环境:
conda create -p venv python=3.12
conda activate ./venv
3. 安装所需依赖:
pip install -r requirements.txt
4. 运行应用:
chainlit run app.py --port 8888
与副驾驶互动
应用运行后,将打开一个浏览器窗口,您可以在其中与AI副驾驶互动。一些您可以提问的示例包括:
- “最新新闻是什么?”
- “我这周的日程如何?”
- “我如何减肥?”
结论
AI副驾驶通过提供快速且相关的信息,简化日常任务并提高生产力,这些信息根据个人偏好定制。有了合适的基础设施,构建这样的AI副驾驶成为一个可管理和有回报的项目。拥有这样的副驾驶就像身边有一个可靠的伙伴,让生活变得更轻松一些。
Source:
https://dzone.com/articles/ai-copilot-using-multi-agent-orchestrator