mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-08 04:23:35 +00:00
feat(agent): Multi agent sdk (#976)
Co-authored-by: xtyuns <xtyuns@163.com> Co-authored-by: Fangyin Cheng <staneyffer@gmail.com> Co-authored-by: csunny <cfqsunny@163.com> Co-authored-by: qidanrui <qidanrui@gmail.com>
This commit is contained in:
0
examples/agents/__init__.py
Normal file
0
examples/agents/__init__.py
Normal file
73
examples/agents/auto_plan_agent_dialogue_example.py
Normal file
73
examples/agents/auto_plan_agent_dialogue_example.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
|
||||
"""
|
||||
|
||||
|
||||
from dbgpt.agent.agents.planner_agent import PlannerAgent
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.agents.plan_group_chat import PlanChat, PlanChatManager
|
||||
|
||||
from dbgpt.agent.agents.expand.code_assistant_agent import CodeAssistantAgent
|
||||
from dbgpt.agent.agents.expand.plugin_assistant_agent import PluginAgent
|
||||
from dbgpt.agent.agents.agents_mange import agent_mange
|
||||
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
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.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,
|
||||
agent_context=context,
|
||||
memory=default_memory,
|
||||
)
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=manager,
|
||||
reviewer=user_proxy,
|
||||
message="Obtain simple information about issues in the repository 'eosphoros-ai/DB-GPT' in the past three days and analyze the data. Create a Markdown table grouped by day and status.",
|
||||
# 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")))
|
48
examples/agents/single_agent_dialogue_example.py
Normal file
48
examples/agents/single_agent_dialogue_example.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""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
|
||||
"""
|
||||
|
||||
from dbgpt.agent.agents.expand.code_assistant_agent import CodeAssistantAgent
|
||||
from dbgpt.agent.agents.user_proxy_agent import UserProxyAgent
|
||||
from dbgpt.agent.memory.gpts_memory import GptsMemory
|
||||
from dbgpt.agent.agents.agent import AgentContext
|
||||
from dbgpt.core.interface.llm import ModelMetadata
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
|
||||
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()
|
||||
coder = CodeAssistantAgent(memory=default_memory, agent_context=context)
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
|
||||
asyncio.run(
|
||||
user_proxy.a_initiate_chat(
|
||||
recipient=coder,
|
||||
reviewer=user_proxy,
|
||||
message="式计算下321 * 123等于多少", # 用python代码的方式计算下321 * 123等于多少
|
||||
# message="download data from https://raw.githubusercontent.com/uwdata/draco/master/data/cars.csv and plot a visualization that tells us about the relationship between weight and horsepower. Save the plot to a file. Print the fields in a dataset before visualizing it.",
|
||||
)
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(asyncio.run(default_memory.one_plan_chat_competions("test456")))
|
Reference in New Issue
Block a user