個人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