refactor(agent): 移除未使用的 MiniAgent 并优化 Agent 配置
- 删除 mini_agent 模块(示例智能体不再需要) - 调整 FilesystemMiddleware 参数配置 - 重构 ReporterContext,移除 MySQL 工具改为动态 MCP 配置
This commit is contained in:
parent
db833de69b
commit
ff38ac9e26
@ -105,13 +105,12 @@ class DeepAgent(BaseAgent):
|
|||||||
inject_attachment_context, # 附件上下文注入
|
inject_attachment_context, # 附件上下文注入
|
||||||
RuntimeConfigMiddleware(extra_tools=all_mcp_tools),
|
RuntimeConfigMiddleware(extra_tools=all_mcp_tools),
|
||||||
TodoListMiddleware(),
|
TodoListMiddleware(),
|
||||||
FilesystemMiddleware(),
|
FilesystemMiddleware(tool_token_limit_before_evict=5000),
|
||||||
SubAgentMiddleware(
|
SubAgentMiddleware(
|
||||||
default_model=sub_model,
|
default_model=sub_model,
|
||||||
default_tools=search_tools,
|
default_tools=search_tools,
|
||||||
subagents=[critique_sub_agent, research_sub_agent],
|
subagents=[critique_sub_agent, research_sub_agent],
|
||||||
default_middleware=[
|
default_middleware=[
|
||||||
TodoListMiddleware(), # 子智能体也有 todo 列表
|
|
||||||
FilesystemMiddleware(),
|
FilesystemMiddleware(),
|
||||||
RuntimeConfigMiddleware(
|
RuntimeConfigMiddleware(
|
||||||
model_context_name="subagents_model",
|
model_context_name="subagents_model",
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
from .graph import MiniAgent
|
|
||||||
|
|
||||||
__all__ = ["MiniAgent"]
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
from langchain.agents import create_agent
|
|
||||||
|
|
||||||
from src.agents.common import BaseAgent, load_chat_model
|
|
||||||
from src.agents.common.middlewares import (
|
|
||||||
RuntimeConfigMiddleware,
|
|
||||||
)
|
|
||||||
from src.services.mcp_service import get_tools_from_all_servers
|
|
||||||
|
|
||||||
|
|
||||||
class MiniAgent(BaseAgent):
|
|
||||||
name = "智能体 Demo"
|
|
||||||
description = "一个基于内置工具的智能体示例"
|
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
|
|
||||||
async def get_graph(self, **kwargs):
|
|
||||||
"""构建图"""
|
|
||||||
context = self.context_schema.from_file(module_name=self.module_name)
|
|
||||||
all_mcp_tools = await get_tools_from_all_servers()
|
|
||||||
|
|
||||||
graph = create_agent(
|
|
||||||
model=load_chat_model(context.model),
|
|
||||||
system_prompt=context.system_prompt,
|
|
||||||
middleware=[
|
|
||||||
RuntimeConfigMiddleware(extra_tools=all_mcp_tools),
|
|
||||||
],
|
|
||||||
checkpointer=await self._get_checkpointer(),
|
|
||||||
)
|
|
||||||
|
|
||||||
return graph
|
|
||||||
@ -10,29 +10,31 @@ from src.agents.common.middlewares import (
|
|||||||
from src.agents.common.toolkits.mysql import get_mysql_tools
|
from src.agents.common.toolkits.mysql import get_mysql_tools
|
||||||
from src.agents.common.tools import gen_tool_info, get_buildin_tools
|
from src.agents.common.tools import gen_tool_info, get_buildin_tools
|
||||||
from src.services.mcp_service import get_tools_from_all_servers
|
from src.services.mcp_service import get_tools_from_all_servers
|
||||||
|
from src.services.mcp_service import get_mcp_server_names
|
||||||
|
|
||||||
from src.utils import logger
|
from src.utils import logger
|
||||||
|
|
||||||
|
|
||||||
@dataclass(kw_only=True)
|
@dataclass(kw_only=True)
|
||||||
class ReporterContext(BaseContext):
|
class ReporterContext(BaseContext):
|
||||||
# 覆盖默认的工具列表,添加 MySQL 工具包
|
|
||||||
tools: Annotated[list[dict], {"__template_metadata__": {"kind": "tools"}}] = field(
|
"""覆盖 BaseContext,定义数据库报表助手智能体的可配置参数"""
|
||||||
default_factory=lambda: [t.name for t in get_mysql_tools()],
|
mcps: Annotated[list[str], {"__template_metadata__": {"kind": "mcps"}}] = field(
|
||||||
|
default_factory=lambda: ["mcp-server-chart"],
|
||||||
metadata={
|
metadata={
|
||||||
"name": "工具",
|
"name": "MCP服务器",
|
||||||
# 添加额外的 MySQL 工具包选项
|
"options": lambda: get_mcp_server_names(),
|
||||||
"options": lambda: gen_tool_info(get_buildin_tools() + get_mysql_tools()),
|
"description": (
|
||||||
"description": "包含内置的工具,以及用于数据库报表生成的 MySQL 工具包。",
|
"MCP服务器列表,建议使用支持 SSE 的 MCP 服务器,"
|
||||||
|
"如果需要使用 uvx 或 npx 运行的服务器,也请在项目外部启动 MCP 服务器,并在项目中配置 MCP 服务器。"
|
||||||
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
def __post_init__(self):
|
|
||||||
self.mcps = ["mcp-server-chart"] # 默认启用 Charts MCPs
|
|
||||||
|
|
||||||
|
|
||||||
class SqlReporterAgent(BaseAgent):
|
class SqlReporterAgent(BaseAgent):
|
||||||
name = "数据库报表助手"
|
name = "数据库报表助手"
|
||||||
description = "一个能够生成 SQL 查询报告的智能体助手。同时调用 Charts MCP 生成图表。"
|
description = "一个能够生成 SQL 查询报告的智能体助手。同时调用 Charts MCP 生成图表。MySQL 工具默认启用,无法选择,mcp 默认启用 Charts MCPs。"
|
||||||
context_schema = ReporterContext
|
context_schema = ReporterContext
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
@ -42,14 +44,13 @@ class SqlReporterAgent(BaseAgent):
|
|||||||
"""构建图"""
|
"""构建图"""
|
||||||
context = self.context_schema.from_file(module_name=self.module_name)
|
context = self.context_schema.from_file(module_name=self.module_name)
|
||||||
all_mcp_tools = await get_tools_from_all_servers()
|
all_mcp_tools = await get_tools_from_all_servers()
|
||||||
# 合并 MySQL 工具和 MCP 工具
|
|
||||||
extra_tools = get_mysql_tools() + all_mcp_tools
|
|
||||||
|
|
||||||
graph = create_agent(
|
graph = create_agent(
|
||||||
model=load_chat_model(context.model),
|
model=load_chat_model(context.model),
|
||||||
system_prompt=context.system_prompt,
|
system_prompt=context.system_prompt,
|
||||||
|
tools=get_mysql_tools(), # MySQL 工具默认启用,这里添加的 tools,不会在工具选择框中出现
|
||||||
middleware=[
|
middleware=[
|
||||||
RuntimeConfigMiddleware(extra_tools=extra_tools),
|
RuntimeConfigMiddleware(extra_tools=all_mcp_tools),
|
||||||
],
|
],
|
||||||
checkpointer=await self._get_checkpointer(),
|
checkpointer=await self._get_checkpointer(),
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user