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, # 附件上下文注入
|
||||
RuntimeConfigMiddleware(extra_tools=all_mcp_tools),
|
||||
TodoListMiddleware(),
|
||||
FilesystemMiddleware(),
|
||||
FilesystemMiddleware(tool_token_limit_before_evict=5000),
|
||||
SubAgentMiddleware(
|
||||
default_model=sub_model,
|
||||
default_tools=search_tools,
|
||||
subagents=[critique_sub_agent, research_sub_agent],
|
||||
default_middleware=[
|
||||
TodoListMiddleware(), # 子智能体也有 todo 列表
|
||||
FilesystemMiddleware(),
|
||||
RuntimeConfigMiddleware(
|
||||
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.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_mcp_server_names
|
||||
|
||||
from src.utils import logger
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class ReporterContext(BaseContext):
|
||||
# 覆盖默认的工具列表,添加 MySQL 工具包
|
||||
tools: Annotated[list[dict], {"__template_metadata__": {"kind": "tools"}}] = field(
|
||||
default_factory=lambda: [t.name for t in get_mysql_tools()],
|
||||
|
||||
"""覆盖 BaseContext,定义数据库报表助手智能体的可配置参数"""
|
||||
mcps: Annotated[list[str], {"__template_metadata__": {"kind": "mcps"}}] = field(
|
||||
default_factory=lambda: ["mcp-server-chart"],
|
||||
metadata={
|
||||
"name": "工具",
|
||||
# 添加额外的 MySQL 工具包选项
|
||||
"options": lambda: gen_tool_info(get_buildin_tools() + get_mysql_tools()),
|
||||
"description": "包含内置的工具,以及用于数据库报表生成的 MySQL 工具包。",
|
||||
"name": "MCP服务器",
|
||||
"options": lambda: get_mcp_server_names(),
|
||||
"description": (
|
||||
"MCP服务器列表,建议使用支持 SSE 的 MCP 服务器,"
|
||||
"如果需要使用 uvx 或 npx 运行的服务器,也请在项目外部启动 MCP 服务器,并在项目中配置 MCP 服务器。"
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
def __post_init__(self):
|
||||
self.mcps = ["mcp-server-chart"] # 默认启用 Charts MCPs
|
||||
|
||||
|
||||
class SqlReporterAgent(BaseAgent):
|
||||
name = "数据库报表助手"
|
||||
description = "一个能够生成 SQL 查询报告的智能体助手。同时调用 Charts MCP 生成图表。"
|
||||
description = "一个能够生成 SQL 查询报告的智能体助手。同时调用 Charts MCP 生成图表。MySQL 工具默认启用,无法选择,mcp 默认启用 Charts MCPs。"
|
||||
context_schema = ReporterContext
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
@ -42,14 +44,13 @@ class SqlReporterAgent(BaseAgent):
|
||||
"""构建图"""
|
||||
context = self.context_schema.from_file(module_name=self.module_name)
|
||||
all_mcp_tools = await get_tools_from_all_servers()
|
||||
# 合并 MySQL 工具和 MCP 工具
|
||||
extra_tools = get_mysql_tools() + all_mcp_tools
|
||||
|
||||
graph = create_agent(
|
||||
model=load_chat_model(context.model),
|
||||
system_prompt=context.system_prompt,
|
||||
tools=get_mysql_tools(), # MySQL 工具默认启用,这里添加的 tools,不会在工具选择框中出现
|
||||
middleware=[
|
||||
RuntimeConfigMiddleware(extra_tools=extra_tools),
|
||||
RuntimeConfigMiddleware(extra_tools=all_mcp_tools),
|
||||
],
|
||||
checkpointer=await self._get_checkpointer(),
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user