CaptainAgent 是一款用于自适应团队建设的工具,现已推出。
作者:刘家乐、宋林欣、张洁宇、张少坤、吴庆云
太长不看
- 我们推出了 CaptainAgent,这是一款能够通过检索-选择-生成过程自适应地组建代理团队的代理,以通过 AG2 中的嵌套聊天对话模式处理复杂任务的代理。
- CaptainAgent 支持 AG2 中实现的所有类型的 ConversableAgent。
面对一个临时任务,动态组建一组能够有效解决问题的智能体是一项复杂的挑战。在许多情况下,我们需要手动设计和选择参与的智能体。在本博客中,我们将介绍 CaptainAgent,一个能够自主组建智能体团队的智能体,该团队可以根据各种复杂任务的需求进行定制。CaptainAgent 会迭代执行以下两个步骤,直到问题成功解决。
-
(步骤 1) CaptainAgent 会将任务分解,为每个子任务推荐所需的角色,然后据此创建一个代理团队。团队中的每个代理要么从头开始生成,要么从提供的代理库中检索并选择。如果提供了工具库,每个代理还会配备从该工具库中检索的预定义工具。

-
(步骤 2)对于每个子任务,相应的智能体团队将共同解决。完成后,将触发总结和反思步骤,根据多智能体对话历史记录生成报告。根据该报告,CaptainAgent 将决定是调整子任务及其对应的团队(返回步骤 1),还是终止任务并输出结果。

CaptainAgent 的设计使其能够利用预先指定的代理库和工具库中的代理和工具。在以下章节中,我们将演示如何使用 CaptainAgent,无论是否使用提供的库。
使用 CaptainAgent 安装 AG2:
pip install ag2[captainagent]
使用 CaptainAgent 时未预先指定代理/工具库
CaptainAgent 可以作为 AG2 中通用类的直接替代品AssistantAgent。它还允许自定义,例如添加代理/工具库。如果提供了库,CaptainAgent 会在解决任务时尝试利用它们。如果没有提供库,CaptainAgent 将自动生成新的代理。
from autogen.agentchat.contrib.captainagent import CaptainAgent
from autogen import UserProxyAgent, config_list_from_json
llm_config = {
"temperature": 0,
"config_list": config_list_from_json("OAI_CONFIG_LIST", filter_dict={"model": ["gpt-4o"]}),
}
## build agents
captain_agent = CaptainAgent(
name="captain_agent",
llm_config=llm_config,
code_execution_config={"use_docker": False, "work_dir": "groupchat"},
)
user_proxy = UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER"
)
query = "Search arxiv for the latest paper about large language models and discuss its potential application in software engineering."
result = user_proxy.initiate_chat(captain_agent, message=query)
使用 CaptainAgent 和预先指定的代理/工具库
要将 CaptainAgent 与预先指定的代理/工具库配合使用,只需指定代理库和工具库的路径即可。这两个库是独立的,因此您可以选择使用其中一个或两个。我们提供的工具库需要订阅特定的 API,详情请参阅文档。以下示例不一定需要使用工具,因此即使您已订阅这些工具也无妨。
要使用代理库中的代理,只需在 CaptainAgent 的配置中指定一个library_path sub-field或字段即可。autobuild_tool_config
from autogen.agentchat.contrib.captainagent import CaptainAgent
from autogen import UserProxyAgent, config_list_from_json
llm_config = {
"temperature": 0,
"config_list": config_list_from_json("OAI_CONFIG_LIST", filter_dict={"model": ["gpt-4o"]}),
}
## build agents
captain_agent = CaptainAgent(
name="captain_agent",
llm_config=llm_config,
nested_config=nested_mode_config,
agent_lib="captainagent_expert_library.json",
tool_lib="default",
code_execution_config={"use_docker": False, "work_dir": "groupchat"},
)
user_proxy = UserProxyAgent(
name="user_proxy",
human_input_mode="NEVER"
)
query = "Search arxiv for the latest paper about large language models and discuss its potential application in software engineering."
result = user_proxy.initiate_chat(captain_agent, message=query)
延伸阅读
有关如何配置 CaptainAgent 的详细说明,请参阅:
有关 CaptainAgent 和所提出的新团队建设范式:自适应构建的更多详细信息,请参阅我们的论文。
@article{song2024adaptive,
title={Adaptive In-conversation Team Building for Language Model Agents},
author={Linxin Song and Jiale Liu and Jieyu Zhang and Shaokun Zhang and Ao Luo and Shijian Wang and Qingyun Wu and Chi Wang},
year={2024},
eprint={2405.19425},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2405.19425},
}
觉得有用吗?
AG2 团队正在努力创作这样的内容,更不用说他们还在构建一个强大的开源端到端多代理自动化平台。
表达支持的最简单方法就是给AG2 代码库点个星标,但也可以看看它有哪些贡献,或者干脆亲自试用一下。
另外,如果您有任何关于 CaptainAgent 的有趣使用案例,或者您希望看到更多功能或改进,请告诉我们。欢迎加入我们的Discord服务器进行讨论。
文章来源:https://dev.to/ag2ai/introducing-captainagent-for-adaptive-team-building-3im6