mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-13 05:01:25 +00:00
feat(agent): Multi agents v0.1 (#1044)
Co-authored-by: qidanrui <qidanrui@gmail.com> Co-authored-by: csunny <cfqsunny@163.com> Co-authored-by: Fangyin Cheng <staneyffer@gmail.com>
This commit is contained in:
@@ -21,39 +21,30 @@ import os
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.agents.agents_mange import agent_mange
|
||||
from dbgpt.agent.agents.expand.code_assistant_agent import CodeAssistantAgent
|
||||
from dbgpt.agent.agents.expand.plugin_assistant_agent import PluginAgent
|
||||
from dbgpt.agent.agents.plan_group_chat import PlanChat, PlanChatManager
|
||||
from dbgpt.agent.agents.planner_agent import PlannerAgent
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
from dbgpt.serve.agent.team.plan.team_auto_plan import AutoPlanChatManager
|
||||
|
||||
if __name__ == "__main__":
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient()
|
||||
context: AgentContext = AgentContext(conv_id="test456", llm_provider=llm_client)
|
||||
# context.llm_models = [ModelMetadata(model="gpt-3.5-turbo")]
|
||||
context.llm_models = [ModelMetadata(model="gpt-4-vision-preview")]
|
||||
context.llm_models = [ModelMetadata(model="gpt-3.5-turbo")]
|
||||
# context.llm_models = [ModelMetadata(model="gpt-4-vision-preview")]
|
||||
context.gpts_name = "代码分析助手"
|
||||
|
||||
default_memory = GptsMemory()
|
||||
coder = CodeAssistantAgent(memory=default_memory, agent_context=context)
|
||||
## TODO add other agent
|
||||
|
||||
groupchat = PlanChat(agents=[coder], messages=[], max_round=50)
|
||||
planner = PlannerAgent(
|
||||
agent_context=context,
|
||||
memory=default_memory,
|
||||
plan_chat=groupchat,
|
||||
)
|
||||
|
||||
manager = PlanChatManager(
|
||||
plan_chat=groupchat,
|
||||
planner=planner,
|
||||
manager = AutoPlanChatManager(
|
||||
agent_context=context,
|
||||
memory=default_memory,
|
||||
)
|
||||
manager.hire([coder])
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
|
||||
|
73
examples/agents/awel_layout_agents_chat_examples.py
Normal file
73
examples/agents/awel_layout_agents_chat_examples.py
Normal file
@@ -0,0 +1,73 @@
|
||||
"""Agents: auto plan agents example?
|
||||
|
||||
Examples:
|
||||
|
||||
Execute the following command in the terminal:
|
||||
Set env params.
|
||||
.. code-block:: shell
|
||||
|
||||
export OPENAI_API_KEY=sk-xx
|
||||
export OPENAI_API_BASE=https://xx:80/v1
|
||||
|
||||
run example.
|
||||
..code-block:: shell
|
||||
python examples/agents/auto_plan_agent_dialogue_example.py
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.agents.expand.plugin_assistant_agent import PluginAssistantAgent
|
||||
from dbgpt.agent.agents.expand.summary_assistant_agent import SummaryAssistantAgent
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
from dbgpt.serve.agent.team.layout.team_awel_layout import AwelLayoutChatManger
|
||||
|
||||
current_dir = os.getcwd()
|
||||
parent_dir = os.path.dirname(current_dir)
|
||||
test_plugin_dir = os.path.join(parent_dir, "test_files")
|
||||
|
||||
if __name__ == "__main__":
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient()
|
||||
context: AgentContext = AgentContext(conv_id="test456", llm_provider=llm_client)
|
||||
context.llm_models = [ModelMetadata(model="gpt-3.5-turbo")]
|
||||
context.gpts_name = "信息析助手"
|
||||
|
||||
default_memory = GptsMemory()
|
||||
manager = AwelLayoutChatManger(
|
||||
agent_context=context,
|
||||
memory=default_memory,
|
||||
)
|
||||
|
||||
### agents
|
||||
tool_enginer = PluginAssistantAgent(
|
||||
agent_context=context,
|
||||
memory=default_memory,
|
||||
plugin_path=test_plugin_dir,
|
||||
)
|
||||
summarizer = SummaryAssistantAgent(
|
||||
agent_context=context,
|
||||
memory=default_memory,
|
||||
)
|
||||
|
||||
manager.hire([tool_enginer, summarizer])
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=manager,
|
||||
reviewer=user_proxy,
|
||||
message="查询成都今天天气",
|
||||
# message="查询今天的最新热点财经新闻",
|
||||
# message="Find papers on gpt-4 in the past three weeks on arxiv, and organize their titles, authors, and links into a markdown table",
|
||||
# message="find papers on LLM applications from arxiv in the last month, create a markdown table of different domains.",
|
||||
)
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(asyncio.run(default_memory.one_plan_chat_competions("test456")))
|
51
examples/agents/plugin_agent_dialogue_example.py
Normal file
51
examples/agents/plugin_agent_dialogue_example.py
Normal file
@@ -0,0 +1,51 @@
|
||||
"""Agents: single agents about CodeAssistantAgent?
|
||||
|
||||
Examples:
|
||||
|
||||
Execute the following command in the terminal:
|
||||
Set env params.
|
||||
.. code-block:: shell
|
||||
|
||||
export OPENAI_API_KEY=sk-xx
|
||||
export OPENAI_API_BASE=https://xx:80/v1
|
||||
|
||||
run example.
|
||||
..code-block:: shell
|
||||
python examples/agents/single_agent_dialogue_example.py
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.agents.expand.plugin_assistant_agent import PluginAssistantAgent
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
|
||||
if __name__ == "__main__":
|
||||
from dbgpt.model import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient()
|
||||
context: AgentContext = AgentContext(conv_id="test456", llm_provider=llm_client)
|
||||
context.llm_models = [ModelMetadata(model="gpt-3.5-turbo")]
|
||||
|
||||
default_memory = GptsMemory()
|
||||
tool_enginer = PluginAssistantAgent(
|
||||
memory=default_memory,
|
||||
agent_context=context,
|
||||
plugin_path="/Users/tuyang.yhj/Code/python/DB-GPT/plugins",
|
||||
)
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=tool_enginer,
|
||||
reviewer=user_proxy,
|
||||
message="查询今天成都的天气",
|
||||
)
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(asyncio.run(default_memory.one_plan_chat_competions("test456")))
|
@@ -70,3 +70,12 @@ with DAG("simple_rag_example") as dag:
|
||||
>> model_task
|
||||
>> output_parser_task
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if dag.leaf_nodes[0].dev_mode:
|
||||
from dbgpt.core.awel import setup_dev_environment
|
||||
|
||||
setup_dev_environment([dag])
|
||||
else:
|
||||
pass
|
||||
|
192
examples/notebook/agent_awel_layout_dialogue_example.ipynb
Normal file
192
examples/notebook/agent_awel_layout_dialogue_example.ipynb
Normal file
@@ -0,0 +1,192 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "6de2e0bb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"\"\"\"Agents: auto plan agents example?\n",
|
||||
"\n",
|
||||
" Examples:\n",
|
||||
"\n",
|
||||
" Execute the following command in the terminal:\n",
|
||||
" Set env params.\n",
|
||||
" .. code-block:: shell\n",
|
||||
"\n",
|
||||
" export OPENAI_API_KEY=sk-xx\n",
|
||||
" export OPENAI_API_BASE=https://xx:80/v1\n",
|
||||
"\n",
|
||||
" run example.\n",
|
||||
" ..code-block:: shell\n",
|
||||
" python examples/agents/auto_plan_agent_dialogue_example.py\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"import os\n",
|
||||
"from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent\n",
|
||||
"from dbgpt.serve.agent.team.layout.team_awel_layout import AwelLayoutChatManger\n",
|
||||
"from dbgpt.agent.agents.expand.plugin_assistant_agent import PluginAssistantAgent\n",
|
||||
"from dbgpt.agent.agents.expand.summary_assistant_agent import SummaryAssistantAgent\n",
|
||||
"\n",
|
||||
"from dbgpt.agent.agents.agent import AgentContext\n",
|
||||
"from dbgpt.agent.memory.gpts_memory import GptsMemory\n",
|
||||
"from dbgpt.core.interface.llm import ModelMetadata\n",
|
||||
"\n",
|
||||
"import asyncio\n",
|
||||
"\n",
|
||||
"from dbgpt.model import OpenAILLMClient"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "153c9e0e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"current_dir = os.getcwd()\n",
|
||||
"parent_dir = os.path.dirname(current_dir)\n",
|
||||
"test_plugin_dir = os.path.join(parent_dir, \"test_files\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "437b9c40",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\u001b[33mUser\u001b[0m (to layout_manager)-[]:\n",
|
||||
"\n",
|
||||
"\"查询成都今天天气\"\n",
|
||||
"\n",
|
||||
"--------------------------------------------------------------------------------\n",
|
||||
"\u001b[33mlayout_manager\u001b[0m (to ToolScientist)-[]:\n",
|
||||
"\n",
|
||||
"\"查询成都今天天气\"\n",
|
||||
"\n",
|
||||
"--------------------------------------------------------------------------------\n",
|
||||
"un_stream ai response: {\n",
|
||||
" \"tool_name\": \"google_search\",\n",
|
||||
" \"args\": {\n",
|
||||
" \"query\": \"成都今天天气\"\n",
|
||||
" },\n",
|
||||
" \"thought\": \"I will use the google-search tool to search for the weather in Chengdu today.\"\n",
|
||||
"}\n",
|
||||
"{'query': '成都今天天气'}\n",
|
||||
"_google_search:成都今天天气\n",
|
||||
"\u001b[33mToolScientist\u001b[0m (to Summarizer)-[gpt-3.5-turbo]:\n",
|
||||
"\n",
|
||||
"\"{\\n \\\"tool_name\\\": \\\"google_search\\\",\\n \\\"args\\\": {\\n \\\"query\\\": \\\"成都今天天气\\\"\\n },\\n \\\"thought\\\": \\\"I will use the google-search tool to search for the weather in Chengdu today.\\\"\\n}\"\n",
|
||||
"\u001b[32m>>>>>>>>ToolScientist Review info: \n",
|
||||
" Pass.None\u001b[0m\n",
|
||||
"\u001b[34m>>>>>>>>ToolScientist Action report: \n",
|
||||
"execution succeeded,\n",
|
||||
"Error: Please configure GOOGLE_API_KEY and GOOGLE_API_CX in .env first!\u001b[0m\n",
|
||||
"\n",
|
||||
"--------------------------------------------------------------------------------\n",
|
||||
"un_stream ai response: The User's Question: 查询成都今天天气\n",
|
||||
"\n",
|
||||
"今天成都的天气预报是晴天,最高温度约为28摄氏度,最低温度约为16摄氏度。\n",
|
||||
"\u001b[33mSummarizer\u001b[0m (to layout_manager)-[gpt-3.5-turbo]:\n",
|
||||
"\n",
|
||||
"\"The User's Question: 查询成都今天天气\\n\\n今天成都的天气预报是晴天,最高温度约为28摄氏度,最低温度约为16摄氏度。\"\n",
|
||||
"\u001b[32m>>>>>>>>Summarizer Review info: \n",
|
||||
" Pass.None\u001b[0m\n",
|
||||
"\u001b[34m>>>>>>>>Summarizer Action report: \n",
|
||||
"execution succeeded,\n",
|
||||
"The User's Question: 查询成都今天天气\n",
|
||||
"\n",
|
||||
"今天成都的天气预报是晴天,最高温度约为28摄氏度,最低温度约为16摄氏度。\u001b[0m\n",
|
||||
"\n",
|
||||
"--------------------------------------------------------------------------------\n",
|
||||
"\u001b[33mlayout_manager\u001b[0m (to User)-[None]:\n",
|
||||
"\n",
|
||||
"\"查询成都今天天气\"\n",
|
||||
"\u001b[32m>>>>>>>>layout_manager Review info: \n",
|
||||
" Pass.None\u001b[0m\n",
|
||||
"\u001b[34m>>>>>>>>layout_manager Action report: \n",
|
||||
"execution succeeded,\n",
|
||||
"The User's Question: 查询成都今天天气\n",
|
||||
"\n",
|
||||
"今天成都的天气预报是晴天,最高温度约为28摄氏度,最低温度约为16摄氏度。\u001b[0m\n",
|
||||
"\n",
|
||||
"--------------------------------------------------------------------------------\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"os.environ['OPENAI_API_KEY']=\"sk-x\"\n",
|
||||
"os.environ['OPENAI_API_BASE']=\"https://proxy_url/v1\"\n",
|
||||
"os.environ['BAIDU_COOKIE']=\"\"\"your baidu cookie\"\"\"\n",
|
||||
"\n",
|
||||
"llm_client = OpenAILLMClient()\n",
|
||||
"context: AgentContext = AgentContext(conv_id=\"test456\", llm_provider=llm_client)\n",
|
||||
"context.llm_models = [ModelMetadata(model=\"gpt-3.5-turbo\")]\n",
|
||||
"context.gpts_name = \"信息析助手\"\n",
|
||||
"\n",
|
||||
"default_memory = GptsMemory()\n",
|
||||
"manager = AwelLayoutChatManger(\n",
|
||||
" agent_context=context,\n",
|
||||
" memory=default_memory,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"### agents\n",
|
||||
"tool_enginer = PluginAssistantAgent(\n",
|
||||
" agent_context=context,\n",
|
||||
" memory=default_memory,\n",
|
||||
" plugin_path=test_plugin_dir,\n",
|
||||
")\n",
|
||||
"summarizer = SummaryAssistantAgent(\n",
|
||||
" agent_context=context,\n",
|
||||
" memory=default_memory,\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"manager.hire([tool_enginer, summarizer])\n",
|
||||
"\n",
|
||||
"user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"await user_proxy.a_initiate_chat(\n",
|
||||
" recipient=manager,\n",
|
||||
" reviewer=user_proxy,\n",
|
||||
" message=\"查询成都今天天气\",\n",
|
||||
")\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "7ded4107",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
BIN
examples/test_files/DB-GPT-Plugins-main-20231117140550.zip
Normal file
BIN
examples/test_files/DB-GPT-Plugins-main-20231117140550.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user