当面对复杂任务时,人类倾向于将其解构为更简单的子任务并单独解决。规划模块旨在赋予智能体这种人类能力,期望使智能体的行为更加合理、强大、可靠。

在先前的智能体自主编排模块章节中,我们已经了解了智能体自主编排的能力。本章节我们重点介绍通过AWEL(智能体工作流)的编排。

使用AWEL进行编排

这里我们介绍如何通过DB-GPT中提供的WrappedAWELLayoutManage进行智能体的编排。 WrappedAWELLayoutManage将会在一个序列中运行智能体。 智能体可以通过hire方法将智能体添加到Manager中。

如下是一个WrappedAWELLayoutManage使用的例子

  1. import asyncio
  2. import os
  3. from dbgpt.agent import (
  4. AgentContext,
  5. AgentMemory,
  6. LLMConfig,
  7. UserProxyAgent,
  8. WrappedAWELLayoutManager,
  9. )
  10. from dbgpt.agent.expand.resources.search_tool import baidu_search
  11. from dbgpt.agent.expand.summary_assistant_agent import SummaryAssistantAgent
  12. from dbgpt.agent.expand.tool_assistant_agent import ToolAssistantAgent
  13. from dbgpt.agent.resource import ToolPack
  14. from dbgpt.model.proxy import OpenAILLMClient
  15. async def main():
  16. llm_client = OpenAILLMClient(
  17. model_alias="gpt-4o",
  18. api_base=os.getenv("OPENAI_API_BASE"),
  19. api_key=os.getenv("OPENAI_API_KEY"),
  20. )
  21. context: AgentContext = AgentContext(
  22. conv_id="test123", language="en", temperature=0.5, max_new_tokens=2048
  23. )
  24. agent_memory = AgentMemory()
  25. user_proxy = await UserProxyAgent().bind(agent_memory).bind(context).build()
  26. tools = ToolPack([baidu_search])
  27. tool_engineer = (
  28. await ToolAssistantAgent()
  29. .bind(context)
  30. .bind(LLMConfig(llm_client=llm_client))
  31. .bind(agent_memory)
  32. .bind(tools)
  33. .build()
  34. )
  35. summarizer = (
  36. await SummaryAssistantAgent()
  37. .bind(context)
  38. .bind(agent_memory)
  39. .bind(LLMConfig(llm_client=llm_client))
  40. .build()
  41. )
  42. manager = (
  43. await WrappedAWELLayoutManager()
  44. .bind(context)
  45. .bind(agent_memory)
  46. .bind(LLMConfig(llm_client=llm_client))
  47. .build()
  48. )
  49. manager.hire([tool_engineer, summarizer])
  50. await user_proxy.initiate_chat(
  51. recipient=manager,
  52. reviewer=user_proxy,
  53. message="Query the weather in Beijing",
  54. )
  55. if __name__ == "__main__":
  56. asyncio.run(main())

运行上述代码,你会看到智能体依次运行,并输出如下结果

  1. --------------------------------------------------------------------------------
  2. AWELBaseManager (to LuBan)-[]:
  3. "Query the weather in Beijing"
  4. --------------------------------------------------------------------------------
  5. un_stream ai response: {
  6. "thought": "To find the current weather in Beijing, I will use the baidu_search API to search for the latest weather information.",
  7. "tool_name": "baidu_search",
  8. "args": {
  9. "query": "current weather in Beijing",
  10. "num_results": 8
  11. }
  12. }
  13. --------------------------------------------------------------------------------
  14. LuBan (to Aristotle)-[gpt-4o]:
  15. "{\n \"thought\": \"To find the current weather in Beijing, I will use the baidu_search API to search for the latest weather information.\",\n \"tool_name\": \"baidu_search\",\n \"args\": {\n \"query\": \"current weather in Beijing\",\n \"num_results\": 8\n }\n}"
  16. >>>>>>>>LuBan Review info:
  17. Pass(None)
  18. >>>>>>>>LuBan Action report:
  19. execution succeeded,
  20. ### [Weather for Beijing, Beijing Municipality, China](http://www.baidu.com/link?url=wpnRKEh7u3CA7C7n3f3wuit8nrIMJXReMRsPJ4gSiZGg_3sSCOuxi4rUSDGkxgG2CEAITa25NLfKcSZOK34kyq)
  21. Location:Beijing Airport Current Time:25 Jun 2024, 16:31:38 Latest Report:25 Jun 2024, 08:30 Visibility:N/A Pressure:1009 mbar Humidity:32% Dew Point:10 °C Upcom...
  22. ### [Beijing, 11 10 天天气预报 - The Weather Channel | Weat...](http://www.baidu.com/link?url=BZa8Z5Ds-rPMRw0EZ0ly8tPzMbpYQ0CusdaFQ7RHkbHNOZMgf6wdK_j9vBISr2kLYE50_F5oxt9DHygAxaickcXVkgMi7e32C9vCZl_pQE0MpCt4sAc0PCjl8-NbThLAupds0gUYMbv2ejZjZN_ghQ6WW8EsJ_DzLSmD_eNfBdi)
  23. 准备好获悉最精确的Beijing, 11 10 天预报,包括最高温度、最低温度和降水几率 - 尽在 The Weather Channel Weather.com
  24. ### [北京天气预报,历史气温,旅游指数,北京一周天气预报【携程...](http://www.baidu.com/link?url=BZa8Z5Ds-rPMRw0EZ0ly8wGkeEiW3HVrw0DkMBPB2xdL8dtIcOu3i6Gou-eLBrwmYuoxCdCOQSYuVdghSmPDKK)
  25. 查看城市旅游详情 22°C21℃/34 晴东北风 微风 风向情况:东北风 风力等级:微风 总降水量:0.0mm 相对湿度:98% 日出时间:4:46 日落时间:19:4736小时天气预报07:03发布 今天夜间21℃多云西...
  26. ### [【北京天气预报15天_北京天气预报15天查询】-中国天气网](http://www.baidu.com/link?url=giZXlwF5kTZfCHQNvHwkiVMJvxN6YGgBro45EL8_XgdzrAdxFhhg0zhG_qhYxdRUij1d1tl0NGqqRemZp7iT_a)
  27. 6月底前长江中下游及广西贵州等地将有强降雨天气2024-06-27 16:40 安徽今夜到后天强降雨连连 雨带明日北抬后天再度南落2024-06-27 16:20 风雨将至 北京天空出现大片乳状云 20...
  28. ### [【北京天气预报15天_北京天气预报15天查询】-中国天气网](http://www.baidu.com/link?url=SMy_6WtAuEY7oKXSbWW9obyaP_VAqzF7w550INK-8CnyaX4wrr1qlCBvhjCrYbaXeRpbT40-6pGXLuo_cQrTUq)
  29. 北方高温今明天短暂缓和 南方强降雨依然频繁2024-06-14 08:11 地质灾害风险预警:浙江福建广东广西等局地地质灾害气象风险高2024-06-14 17:32 渍涝风险气象预报:浙江福建广东...
  30. ### [【北京天气预报15天_北京天气预报15天查询】-中国天气网](http://www.baidu.com/link?url=wpnRKEh7u3CA7C7n3f3wun3KHDiGBTRXtwcgVgSV9e7Y7_Ui5d8PBraMakoZpeunwTcHgkwboa_9YZco1d3t6OpiMsXeEaim0ReUKbIZCP7Qa4c7ZZ1ZO1AtnILEXR1F)
  31. 6月底前长江中下游及广西贵州等地将有强降雨天气2024-06-27 16:40 安徽今夜到后天强降雨连连 雨带明日北抬后天再度南落2024-06-27 16:20 风雨将至 北京天空出现大片乳状云 20...
  32. ### [【北京天气预报15天_北京天气预报15天查询】-中国天气网](http://www.baidu.com/link?url=Qo1T3nlH9bZ57GJ7SSOVNwSZBKnCpwkkr95rpZY4XcK-W607jhYj10I6g_DwXWzlzLsK-siZKMZNN736q26OiJVP3u0aWyXLCRbRT4etDtu)
  33. 6月底前长江中下游及广西贵州等地将有强降雨天气2024-06-27 16:40 安徽今夜到后天强降雨连连 雨带明日北抬后天再度南落2024-06-27 16:20 风雨将至 北京天空出现大片乳状云 20...
  34. --------------------------------------------------------------------------------
  35. un_stream ai response: Beijing weather summary:
  36. - Current temperature: 22°C
  37. - Temperature range: 21°C to 34°C
  38. - Conditions: Clear
  39. - Wind: Northeast wind, light breeze
  40. - Humidity: 98%
  41. - No precipitation
  42. - Sunrise: 4:46 AM
  43. - Sunset: 7:47 PM
  44. --------------------------------------------------------------------------------
  45. AWELBaseManager (to User)-[]:
  46. "Query the weather in Beijing"
  47. >>>>>>>>AWELBaseManager Review info:
  48. Pass(None)
  49. >>>>>>>>AWELBaseManager Action report:
  50. execution succeeded,
  51. Beijing weather summary:
  52. - Current temperature: 22°C
  53. - Temperature range: 21°C to 34°C
  54. - Conditions: Clear
  55. - Wind: Northeast wind, light breeze
  56. - Humidity: 98%
  57. - No precipitation
  58. - Sunrise: 4:46 AM
  59. - Sunset: 7:47 PM
  60. --------------------------------------------------------------------------------