前言
📣我们在 🐫 CAMEL 框架中新增了多智能体协作 Workforce 模块!
本期公众号将为大家带来什么是Workforce,具体选择Workforce的原因以及对其特点和流程的图解。
❓什么是Workforce
- Workforce 是一个让多个Agent协同工作以解决任务的系统。
- 该模块采用分层架构,包含多个工作节点,每个工作节点可以包含一个或多个Agent作为工作者。工作节点由协调 Agent进行管理,协调Agent根据工作节点的描述和工具集为其分配任务。
- 在工作队伍中,还有一个任务规划Agent,负责将任务分解和组合,使工作队伍能够一步步地解决任务。🤔
⬇️下图的示例展示了工作队伍如何协作,利用具有不同工具的 Agent规划前往巴黎的旅行,以及实现代码。
为何选Workforce?
🤔可能你会问:“Multi-Agent Workforce和传统Workflow工作流有什么区别?”
答案在于Multi-Agent系统的动态问题解决能力。与静态工作流不同,Workforce 可以实时适应。当你将一个复杂任务分配给一组 Agents时,即使任务的某个部分失败,Workforce 也会自动分解问题,重新启动新的 Agent,并持续迭代,直到任务完全解决。
🔄这种灵活性使Multi-Agent系统在大规模解决复杂问题时成为一个改变游戏规则的工具。🚀
⬇️详情也可以在官网的Doc中查看!
https://docs.camel-ai.org/
key_modules/workforce.html
🤩以下是案例,也可以去 google
🤩以下是最令人期待的案例环节 🤩
Google Colab 的链接也可以查看和复制:https://shorturl.asia/gKxMH
安装
首先,您需要安装包含所有依赖项的 CAMEL:
%pip install "camel-ai[all]==0.2.6"
%pip install nest_asyncio
设置 API 密钥
import os
from getpass import getpass
os.environ["OPENAI_API_KEY"] = getpass("Enter your OpenAI API key: ")
# Ref: https://developers.google.com/custom-search/v1/overview
os.environ["GOOGLE_API_KEY"] = getpass("Enter your Google Search API key: ")
# Ref: https://cse.google.com/cse/all
os.environ["SEARCH_ENGINE_ID"] = getpass("Enter your Google Search Engine ID: ")
# Ref: https://openweathermap.org
os.environ["OPENWEATHERMAP_API_KEY"] = getpass("Enter your OpenWeatherMap API key: ")
代码输出:
Enter your OpenAI API key: ·········· Enter your Google Search API key: ·········· Enter your Google Search Engine ID: ·········· Enter your OpenWeatherMap API key: ··········
导入依赖项并设置 AsyncIO
from camel.agents.chat_agent import ChatAgent
from camel.configs.openai_config import ChatGPTConfig
from camel.messages.base import BaseMessage
from camel.models import ModelFactory
from camel.tasks.task import Task
from camel.toolkits import (
WEATHER_FUNCS,
GoogleMapsToolkit,
OpenAIFunction,
SearchToolkit,
)
from camel.types import ModelPlatformType, ModelType
from camel.societies import Workforce
import nest_asyncio
nest_asyncio.apply()
创建工作 agent
search_toolkit = SearchToolkit()
search_tools = [
OpenAIFunction(search_toolkit.search_google),
OpenAIFunction(search_toolkit.search_duckduckgo),
]
# Set up web searching agent
search_agent_model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O,
model_config_dict=ChatGPTConfig().as_dict(),
)
search_agent = ChatAgent(
system_message=BaseMessage.make_assistant_message(
role_name="Web searching agent",
content="You can search online for information",
),
model=search_agent_model,
tools=[*search_tools, *WEATHER_FUNCS],
)
# Set up tour guide agent
tour_guide_agent_model = ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O,
model_config_dict=ChatGPTConfig().as_dict(),
)
tour_guide_agent = ChatAgent(
BaseMessage.make_assistant_message(
role_name="Tour guide",
content="You are a tour guide",
),
model=tour_guide_agent_model,
tools=GoogleMapsToolkit().get_tools(),
)
# Set up traveler agent
traveler_agent = ChatAgent(
BaseMessage.make_assistant_message(
role_name="Traveler",
content="You can ask questions about your travel plans",
),
model=ModelFactory.create(
model_platform=ModelPlatformType.OPENAI,
model_type=ModelType.GPT_4O,
model_config_dict=ChatGPTConfig().as_dict(),
),
)
创建工作队伍并添加agent
workforce = Workforce('A travel group')
workforce.add_single_agent_worker(
"A tour guide",
worker=tour_guide_agent,
).add_single_agent_worker(
"A traveler", worker=traveler_agent
).add_single_agent_worker(
"An agent who can do online searches", worker=search_agent
)
代码输出:
Workforce 135004461820576 (A travel group)
创建任务并分配给工作队伍
# specify the task to be solved
human_task = Task(
content=(
"Plan a one-week trip to Paris, considering some historical places"
" to visit and weather conditions."
),
id='0',
)
task = workforce.process_task(human_task)
代码输出:
Worker node 135004442253472 (An agent who can do online searches) get task 0.0: Research and list historical places to visit in Paris.
======
Reply from Worker node 135004442253472 (An agent who can do online searches):
1. Eiffel Tower 2. Notre-Dame Cathedral 3. The Louvre Museum 4. Arc de Triomphe 5. Palace of Versailles 6. Sainte-Chapelle 7. Panthéon 8. Les Invalides 9. Place de la Concorde 10. Sacré-Cœur Basilica 11. Conciergerie 12. Palais Garnier 13. Pont Neuf 14. Château de Vincennes 15. Musée d'Orsay 16. Hôtel de Ville 17. La Sorbonne 18. Saint-Germain-des-Prés 19. Cluny Museum 20. Grand Palais 21. Petit Palais 22. Tuileries Garden 23. Place des Vosges 24. La Madeleine 25. Saint-Sulpice 26. Palais-Royal
======
Worker node 135004442253472 (An agent who can do online searches) get task 0.1: Check the weather conditions for the week of the trip.
======
Reply from Worker node 135004442253472 (An agent who can do online searches):
Weather in Paris, FR: 17.02°Celsius, feels like 16.29°Celsius. Max temp: 18.28°Celsius, Min temp: 15.88°Celsius. Wind: 4.12 meters_sec at 250 degrees. Visibility: 10000 meters. Sunrise at 1727761823, Sunset at 1727803787.
======
Worker node 135004442253472 (An agent who can do online searches) get task 0.2: Plan the itinerary based on the historical places and weather conditions.
======
Reply from Worker node 135004442253472 (An agent who can do online searches):
Day 1: - Morning: Eiffel Tower - Afternoon: Notre-Dame Cathedral - Evening: The Louvre Museum Day 2: - Morning: Arc de Triomphe - Afternoon: Palace of Versailles - Evening: Sainte-Chapelle Day 3: - Morning: Panthéon - Afternoon: Les Invalides - Evening: Place de la Concorde Day 4: - Morning: Sacré-Cœur Basilica - Afternoon: Conciergerie - Evening: Palais Garnier Day 5: - Morning: Pont Neuf - Afternoon: Château de Vincennes - Evening: Musée d'Orsay Day 6: - Morning: Hôtel de Ville - Afternoon: La Sorbonne - Evening: Saint-Germain-des-Prés Day 7: - Morning: Cluny Museum - Afternoon: Grand Palais and Petit Palais - Evening: Tuileries Garden Day 8: - Morning: Place des Vosges - Afternoon: La Madeleine - Evening: Saint-Sulpice and Palais-Royal Weather conditions are mild with temperatures ranging from 15.88°C to 18.28°C, so all activities are feasible.
======
Worker node 135004456387200 (A tour guide) get task 0.3: Provide detailed descriptions and addresses of the selected historical places.
======
Reply from Worker node 135004456387200 (A tour guide):
Here are the detailed descriptions and addresses of the selected historical places in Paris: 1. **Eiffel Tower** - Address: Avenue Gustave Eiffel, 75007 Paris, France - Description: An iconic symbol of France, the Eiffel Tower is a wrought-iron lattice tower on the Champ de Mars, named after the engineer Gustave Eiffel. 2. **Notre-Dame Cathedral** - Address: Notre-Dame Cathedral, Paris, France - Description: A medieval Catholic cathedral on the Île de la Cité, Notre-Dame is renowned for its French Gothic architecture and historical significance. 3. **The Louvre Museum** - Address: The Louvre Museum, Paris, France - Description: The world's largest art museum and a historic monument in Paris, it is home to thousands of works of art, including the Mona Lisa. 4. **Arc de Triomphe** - Address: Arc de Triomphe, Paris, France - Description: One of the most famous monuments in Paris, it stands at the western end of the Champs-Élysées and honors those who fought and died for France. 5. **Palace of Versailles** - Address: Palace of Versailles, 78000 Versailles, France - Description: A former royal residence, the Palace of Versailles is known for its opulent architecture, gardens, and the Hall of Mirrors. 6. **Sainte-Chapelle** - Address: Boulevard du Palais, 75001 Paris, France - Description: A royal chapel in the Gothic style, located within the medieval Palais de la Cité, it is famous for its stunning stained glass windows. 7. **Panthéon** - Address: Panthéon, Paris, France - Description: Originally built as a church, the Panthéon now functions as a mausoleum containing the remains of distinguished French citizens. 8. **Les Invalides** - Address: 75007 Paris, France - Description: A complex of buildings containing museums and monuments, all relating to the military history of France, and the burial site of Napoleon Bonaparte. 9. **Place de la Concorde** - Address: 75008 Paris, France - Description: The largest square in Paris, it is known for its historical significance and its central location between the Champs-Élysées and the Tuileries Garden. 10. **Sacré-Cœur Basilica** - Address: Rue du Chevalier de la Barre, 75018 Paris, France - Description: A Roman Catholic church and minor basilica, dedicated to the Sacred Heart of Jesus, located at the summit of the butte Montmartre. 11. **Conciergerie** - Address: Boulevard du Palais, 75001 Paris, France - Description: A former royal palace and prison, now a museum, located on the Île de la Cité. 12. **Palais Garnier** - Address: Place de l'Opéra, 75009 Paris, France - Description: A 1,979-seat opera house, which was the primary home of the Paris Opera and its associated Paris Opera Ballet until 1989. 13. **Pont Neuf** - Address: 75001 Paris, France - Description: The oldest standing bridge across the river Seine in Paris. 14. **Château de Vincennes** - Address: Avenue de Paris, 94300 Vincennes, France - Description: A historic castle that served as a royal residence, it is one of the best-preserved medieval castles in Europe. 15. **Musée d'Orsay** - Address: 75007 Paris, France - Description: A museum housed in a former railway station, it holds mainly French art dating from 1848 to 1914, including paintings, sculptures, and photography. 16. **Hôtel de Ville** - Address: 4e Arrondissement, 75004 Paris, France - Description: The building housing the city's local administration, it has been the headquarters of the municipality of Paris since 1357. 17. **La Sorbonne** - Address: Quartier de la Sorbonne, 75005 Paris, France - Description: A historic building in the Latin Quarter, it is the seat of the former University of Paris. 18. **Saint-Germain-des-Prés** - Address: 75006 Paris, France - Description: One of the four administrative quarters of the 6th arrondissement of Paris, known for its cafés and intellectual history. 19. **Cluny Museum** - Address: Rue du Sommerard, 75005 Paris, France - Description: Officially known as the Musée de Cluny, it is a museum of medieval artifacts located in the Latin Quarter. 20. **Grand Palais** - Address: 75008 Paris, France - Description: A large historic site, exhibition hall, and museum complex located at the Champs-Élysées. 21. **Petit Palais** - Address: Avenue Winston Churchill, 75008 Paris, France - Description: An art museum in Paris, it houses the City of Paris Museum of Fine Arts. 22. **Tuileries Garden** - Address: 75001 Paris, France - Description: A public garden located between the Louvre Museum and the Place de la Concorde. 23. **Place des Vosges** - Address: Paris, France - Description: The oldest planned square in Paris, located in the Marais district. 24. **La Madeleine** - Address: Place de la Madeleine, 75008 Paris, France - Description: A Roman Catholic church designed in its present form as a temple to the glory of Napoleon's army. 25. **Saint-Sulpice** - Address: Rue Palatine, 75006 Paris, France - Description: A Roman Catholic church in Paris, known for its gnomon and for being the second largest church in the city. 26. **Palais-Royal** - Address: 75001 Paris, France - Description: A former royal palace located in the 1st arrondissement of Paris, it now serves as the seat of the Ministry of Culture and the Constitutional Council.
======
获取任务的结果
print('Final Result of Original task:\n', task.result)
代码输出:
Final Result of Original task: **Final Plan for a One-Week Trip to Paris:** **Overview:** - Duration: 7 days - Weather: Mild temperatures ranging from 15.88°C to 18.28°C, making all activities feasible. **Itinerary:** **Day 1:** - **Morning:** Visit the **Eiffel Tower** - Address: Avenue Gustave Eiffel, 75007 Paris, France - Description: An iconic symbol of France, known for its wrought-iron lattice structure. - **Afternoon:** Explore the **Notre-Dame Cathedral** - Address: Notre-Dame Cathedral, Paris, France - Description: A medieval Catholic cathedral famous for its French Gothic architecture. - **Evening:** Tour the **Louvre Museum** - Address: The Louvre Museum, Paris, France - Description: The world's largest art museum, home to thousands of works including the Mona Lisa. **Day 2:** - **Morning:** Visit the **Arc de Triomphe** - Address: Arc de Triomphe, Paris, France - Description: A monument honoring those who fought for France. - **Afternoon:** Day trip to the **Palace of Versailles** - Address: Palace of Versailles, 78000 Versailles, France - Description: A former royal residence known for its opulent architecture and gardens. - **Evening:** Visit **Sainte-Chapelle** - Address: Boulevard du Palais, 75001 Paris, France - Description: A royal chapel famous for its stunning stained glass windows. **Day 3:** - **Morning:** Explore the **Panthéon** - Address: Panthéon, Paris, France - Description: A mausoleum for distinguished French citizens. - **Afternoon:** Visit **Les Invalides** - Address: 75007 Paris, France - Description: A complex of buildings related to France's military history. - **Evening:** Stroll through the **Place de la Concorde** - Address: 75008 Paris, France - Description: The largest square in Paris with historical significance. **Day 4:** - **Morning:** Visit the **Sacré-Cœur Basilica** - Address: Rue du Chevalier de la Barre, 75018 Paris, France - Description: A basilica located at the summit of Montmartre. - **Afternoon:** Tour the **Conciergerie** - Address: Boulevard du Palais, 75001 Paris, France - Description: A former royal palace and prison, now a museum. - **Evening:** Attend a performance at the **Palais Garnier** - Address: Place de l'Opéra, 75009 Paris, France - Description: A historic opera house. **Day 5:** - **Morning:** Walk across the **Pont Neuf** - Address: 75001 Paris, France - Description: The oldest standing bridge across the Seine. - **Afternoon:** Visit the **Château de Vincennes** - Address: Avenue de Paris, 94300 Vincennes, France - Description: A well-preserved medieval castle. - **Evening:** Explore the **Musée d'Orsay** - Address: 75007 Paris, France - Description: A museum of French art from 1848 to 1914. **Day 6:** - **Morning:** Visit the **Hôtel de Ville** - Address: 4e Arrondissement, 75004 Paris, France - Description: The city's local administration headquarters. - **Afternoon:** Explore **La Sorbonne** - Address: Quartier de la Sorbonne, 75005 Paris, France - Description: A historic building in the Latin Quarter. - **Evening:** Enjoy the ambiance of **Saint-Germain-des-Prés** - Address: 75006 Paris, France - Description: Known for its cafés and intellectual history. **Day 7:** - **Morning:** Visit the **Cluny Museum** - Address: Rue du Sommerard, 75005 Paris, France - Description: A museum of medieval artifacts. - **Afternoon:** Explore the **Grand Palais** and **Petit Palais** - Address: 75008 Paris, France - Description: A historic site and art museum complex. - **Evening:** Relax in the **Tuileries Garden** - Address: 75001 Paris, France - Description: A public garden located between the Louvre and Place de la Concorde. **Additional Activities (if time permits):** - **Place des Vosges**: The oldest planned square in Paris. - **La Madeleine**: A church designed as a temple to Napoleon's army. - **Saint-Sulpice**: Known for its gnomon and as the second largest church in Paris. - **Palais-Royal**: A former royal palace now housing the Ministry of Culture. This plan provides a comprehensive exploration of Paris's historical sites while considering the mild weather conditions for a pleasant experience.
欢迎加入CAMEL AI社区一起交流和探讨!