mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-09 04:49:26 +00:00
refactor(agent): Agent modular refactoring (#1487)
This commit is contained in:
@@ -14,27 +14,33 @@
|
||||
python examples/agents/auto_plan_agent_dialogue_example.py
|
||||
"""
|
||||
|
||||
|
||||
import asyncio
|
||||
|
||||
from dbgpt.agent import (
|
||||
AgentContext,
|
||||
GptsMemory,
|
||||
AgentMemory,
|
||||
AutoPlanChatManager,
|
||||
LLMConfig,
|
||||
ResourceLoader,
|
||||
UserProxyAgent,
|
||||
)
|
||||
from dbgpt.agent.expand.code_assistant_agent import CodeAssistantAgent
|
||||
from dbgpt.agent.plan import AutoPlanChatManager
|
||||
from dbgpt.util.tracer import initialize_tracer
|
||||
|
||||
initialize_tracer(
|
||||
"/tmp/agent_auto_plan_agent_dialogue_example_trace.jsonl", create_system_app=True
|
||||
)
|
||||
|
||||
|
||||
async def main():
|
||||
from dbgpt.model.proxy import OpenAILLMClient
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-4")
|
||||
context: AgentContext = AgentContext(conv_id="test456", gpts_app_name="代码分析助手")
|
||||
agent_memory = AgentMemory()
|
||||
|
||||
default_memory = GptsMemory()
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-4")
|
||||
context: AgentContext = AgentContext(
|
||||
conv_id="test456", gpts_app_name="代码分析助手", max_new_tokens=2048
|
||||
)
|
||||
|
||||
resource_loader = ResourceLoader()
|
||||
|
||||
@@ -42,21 +48,21 @@ async def main():
|
||||
await CodeAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind(resource_loader)
|
||||
.bind(agent_memory)
|
||||
.build()
|
||||
)
|
||||
|
||||
manager = (
|
||||
await AutoPlanChatManager()
|
||||
.bind(context)
|
||||
.bind(default_memory)
|
||||
.bind(agent_memory)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.build()
|
||||
)
|
||||
manager.hire([coder])
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(default_memory).build()
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(agent_memory).build()
|
||||
|
||||
await user_proxy.initiate_chat(
|
||||
recipient=manager,
|
||||
@@ -66,7 +72,7 @@ async def main():
|
||||
# message="find papers on LLM applications from arxiv in the last month, create a markdown table of different domains.",
|
||||
)
|
||||
|
||||
print(await default_memory.one_chat_completions("test456"))
|
||||
print(await agent_memory.gpts_memory.one_chat_completions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -19,16 +19,16 @@ import os
|
||||
|
||||
from dbgpt.agent import (
|
||||
AgentContext,
|
||||
AgentMemory,
|
||||
AgentResource,
|
||||
GptsMemory,
|
||||
LLMConfig,
|
||||
ResourceLoader,
|
||||
ResourceType,
|
||||
UserProxyAgent,
|
||||
WrappedAWELLayoutManager,
|
||||
)
|
||||
from dbgpt.agent.expand.plugin_assistant_agent import PluginAssistantAgent
|
||||
from dbgpt.agent.expand.summary_assistant_agent import SummaryAssistantAgent
|
||||
from dbgpt.agent.plan import WrappedAWELLayoutManager
|
||||
from dbgpt.agent.resource import PluginFileLoadClient
|
||||
from dbgpt.configs.model_config import ROOT_PATH
|
||||
from dbgpt.util.tracer import initialize_tracer
|
||||
@@ -44,8 +44,7 @@ async def main():
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test456", gpts_app_name="信息析助手")
|
||||
|
||||
default_memory = GptsMemory()
|
||||
|
||||
agent_memory = AgentMemory()
|
||||
resource_loader = ResourceLoader()
|
||||
plugin_file_loader = PluginFileLoadClient()
|
||||
resource_loader.register_resource_api(plugin_file_loader)
|
||||
@@ -60,7 +59,7 @@ async def main():
|
||||
await PluginAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind(agent_memory)
|
||||
.bind([plugin_resource])
|
||||
.bind(resource_loader)
|
||||
.build()
|
||||
@@ -68,7 +67,7 @@ async def main():
|
||||
summarizer = (
|
||||
await SummaryAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(default_memory)
|
||||
.bind(agent_memory)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.build()
|
||||
)
|
||||
@@ -76,13 +75,13 @@ async def main():
|
||||
manager = (
|
||||
await WrappedAWELLayoutManager()
|
||||
.bind(context)
|
||||
.bind(default_memory)
|
||||
.bind(agent_memory)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.build()
|
||||
)
|
||||
manager.hire([tool_engineer, summarizer])
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(default_memory).build()
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(agent_memory).build()
|
||||
|
||||
await user_proxy.initiate_chat(
|
||||
recipient=manager,
|
||||
@@ -93,7 +92,7 @@ async def main():
|
||||
# message="find papers on LLM applications from arxiv in the last month, create a markdown table of different domains.",
|
||||
)
|
||||
|
||||
print(await default_memory.one_chat_completions("test456"))
|
||||
print(await agent_memory.gpts_memory.one_chat_completions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -19,8 +19,8 @@ import os
|
||||
|
||||
from dbgpt.agent import (
|
||||
AgentContext,
|
||||
AgentMemory,
|
||||
AgentResource,
|
||||
GptsMemory,
|
||||
LLMConfig,
|
||||
ResourceLoader,
|
||||
ResourceType,
|
||||
@@ -40,7 +40,7 @@ async def main():
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test456")
|
||||
|
||||
default_memory: GptsMemory = GptsMemory()
|
||||
agent_memory = AgentMemory()
|
||||
|
||||
plugin_resource = AgentResource(
|
||||
type=ResourceType.Plugin,
|
||||
@@ -52,13 +52,13 @@ async def main():
|
||||
plugin_file_loader = PluginFileLoadClient()
|
||||
resource_loader.register_resource_api(plugin_file_loader)
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
user_proxy = await UserProxyAgent().bind(agent_memory).bind(context).build()
|
||||
|
||||
tool_engineer = (
|
||||
await PluginAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind(agent_memory)
|
||||
.bind([plugin_resource])
|
||||
.bind(resource_loader)
|
||||
.build()
|
||||
@@ -70,8 +70,8 @@ async def main():
|
||||
message="查询今天成都的天气",
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(await default_memory.one_chat_completions("test456"))
|
||||
# dbgpt-vis message infos
|
||||
print(await agent_memory.gpts_memory.one_chat_completions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -17,7 +17,7 @@
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from dbgpt.agent import AgentContext, GptsMemory, LLMConfig, UserProxyAgent
|
||||
from dbgpt.agent import AgentContext, AgentMemory, LLMConfig, UserProxyAgent
|
||||
from dbgpt.agent.expand.retrieve_summary_assistant_agent import (
|
||||
RetrieveSummaryAssistantAgent,
|
||||
)
|
||||
@@ -29,17 +29,16 @@ async def summary_example_with_success():
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo-16k")
|
||||
context: AgentContext = AgentContext(conv_id="retrieve_summarize")
|
||||
|
||||
default_memory = GptsMemory()
|
||||
agent_memory = AgentMemory()
|
||||
summarizer = (
|
||||
await RetrieveSummaryAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind(agent_memory)
|
||||
.build()
|
||||
)
|
||||
|
||||
user_proxy = UserProxyAgent(memory=default_memory, agent_context=context)
|
||||
user_proxy = UserProxyAgent(memory=agent_memory, agent_context=context)
|
||||
|
||||
paths_urls = [
|
||||
os.path.join(ROOT_PATH, "examples/agents/example_files/Nuclear_power.pdf"),
|
||||
@@ -56,7 +55,7 @@ async def summary_example_with_success():
|
||||
)
|
||||
|
||||
# dbgpt-vis message infos
|
||||
print(await default_memory.one_chat_completions("retrieve_summarize"))
|
||||
print(await agent_memory.gpts_memory.one_chat_completions("retrieve_summarize"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -16,7 +16,14 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from dbgpt.agent import AgentContext, GptsMemory, LLMConfig, UserProxyAgent
|
||||
from dbgpt.agent import (
|
||||
AgentContext,
|
||||
AgentMemory,
|
||||
AgentMemoryFragment,
|
||||
HybridMemory,
|
||||
LLMConfig,
|
||||
UserProxyAgent,
|
||||
)
|
||||
from dbgpt.agent.expand.code_assistant_agent import CodeAssistantAgent
|
||||
|
||||
|
||||
@@ -25,17 +32,17 @@ async def main():
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test123")
|
||||
default_memory: GptsMemory = GptsMemory()
|
||||
agent_memory = AgentMemory(HybridMemory[AgentMemoryFragment].from_chroma())
|
||||
|
||||
coder = (
|
||||
await CodeAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind(agent_memory)
|
||||
.build()
|
||||
)
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(default_memory).build()
|
||||
user_proxy = await UserProxyAgent().bind(context).bind(agent_memory).build()
|
||||
|
||||
await user_proxy.initiate_chat(
|
||||
recipient=coder,
|
||||
@@ -44,7 +51,7 @@ async def main():
|
||||
# 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(await default_memory.one_chat_completions("test123"))
|
||||
print(await agent_memory.gpts_memory.one_chat_completions("test123"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -16,7 +16,7 @@
|
||||
|
||||
import asyncio
|
||||
|
||||
from dbgpt.agent import AgentContext, GptsMemory, LLMConfig, UserProxyAgent
|
||||
from dbgpt.agent import AgentContext, AgentMemory, LLMConfig, UserProxyAgent
|
||||
from dbgpt.agent.expand.summary_assistant_agent import SummaryAssistantAgent
|
||||
|
||||
|
||||
@@ -26,17 +26,16 @@ async def summary_example_with_success():
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="summarize")
|
||||
|
||||
default_memory: GptsMemory = GptsMemory()
|
||||
|
||||
agent_memory = AgentMemory()
|
||||
summarizer = (
|
||||
await SummaryAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind(agent_memory)
|
||||
.build()
|
||||
)
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
user_proxy = await UserProxyAgent().bind(agent_memory).bind(context).build()
|
||||
|
||||
await user_proxy.initiate_chat(
|
||||
recipient=summarizer,
|
||||
@@ -71,8 +70,8 @@ async def summary_example_with_success():
|
||||
""",
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(await default_memory.one_chat_completions("summarize"))
|
||||
# dbgpt-vis message infos
|
||||
print(await agent_memory.gpts_memory.one_chat_completions("summarize"))
|
||||
|
||||
|
||||
async def summary_example_with_faliure():
|
||||
@@ -81,17 +80,16 @@ async def summary_example_with_faliure():
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="summarize")
|
||||
|
||||
default_memory: GptsMemory = GptsMemory()
|
||||
|
||||
agent_memory = AgentMemory()
|
||||
summarizer = (
|
||||
await SummaryAssistantAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind(agent_memory)
|
||||
.build()
|
||||
)
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
user_proxy = await UserProxyAgent().bind(agent_memory).bind(context).build()
|
||||
|
||||
# Test the failure example
|
||||
|
||||
@@ -112,7 +110,7 @@ async def summary_example_with_faliure():
|
||||
""",
|
||||
)
|
||||
|
||||
print(await default_memory.one_chat_completions("summarize"))
|
||||
print(await agent_memory.gpts_memory.one_chat_completions("summarize"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@@ -19,8 +19,8 @@ import os
|
||||
|
||||
from dbgpt.agent import (
|
||||
AgentContext,
|
||||
AgentMemory,
|
||||
AgentResource,
|
||||
GptsMemory,
|
||||
LLMConfig,
|
||||
ResourceLoader,
|
||||
ResourceType,
|
||||
@@ -40,11 +40,11 @@ initialize_tracer("/tmp/agent_trace.jsonl", create_system_app=True)
|
||||
async def main():
|
||||
from dbgpt.model.proxy.llms.chatgpt import OpenAILLMClient
|
||||
|
||||
agent_memory = AgentMemory()
|
||||
|
||||
llm_client = OpenAILLMClient(model_alias="gpt-3.5-turbo")
|
||||
context: AgentContext = AgentContext(conv_id="test456")
|
||||
|
||||
default_memory: GptsMemory = GptsMemory()
|
||||
|
||||
db_resource = AgentResource(
|
||||
type=ResourceType.DB,
|
||||
name="TestData",
|
||||
@@ -55,15 +55,15 @@ async def main():
|
||||
sqlite_file_loader = SqliteLoadClient()
|
||||
resource_loader.register_resource_api(sqlite_file_loader)
|
||||
|
||||
user_proxy = await UserProxyAgent().bind(default_memory).bind(context).build()
|
||||
user_proxy = await UserProxyAgent().bind(agent_memory).bind(context).build()
|
||||
|
||||
sql_boy = (
|
||||
await DataScientistAgent()
|
||||
.bind(context)
|
||||
.bind(LLMConfig(llm_client=llm_client))
|
||||
.bind(default_memory)
|
||||
.bind([db_resource])
|
||||
.bind(resource_loader)
|
||||
.bind(agent_memory)
|
||||
.build()
|
||||
)
|
||||
|
||||
@@ -74,7 +74,7 @@ async def main():
|
||||
)
|
||||
|
||||
## dbgpt-vis message infos
|
||||
print(await default_memory.one_chat_completions("test456"))
|
||||
print(await agent_memory.gpts_memory.one_chat_completions("test456"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Reference in New Issue
Block a user