From 076e23eec3eb04db1360e5fa7e8eddb2e1d35eba Mon Sep 17 00:00:00 2001 From: Wenjie Zhang Date: Sun, 2 Nov 2025 01:15:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=88=A0=E9=99=A4=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=9A=84=20tools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agents/common/tools.py | 51 +----------------------------------- src/agents/reporter/graph.py | 2 +- 2 files changed, 2 insertions(+), 51 deletions(-) diff --git a/src/agents/common/tools.py b/src/agents/common/tools.py index 524b1bd4..f240c507 100644 --- a/src/agents/common/tools.py +++ b/src/agents/common/tools.py @@ -11,12 +11,7 @@ from pydantic import BaseModel, Field from src import config, graph_base, knowledge_base from src.utils import logger -# TODO[修改建议]:前端需要通过interrupt进行交互,点击是或否来批准执行 -# 返回中断点: -# is_approved : bool = True 或者 False -# resume_command = Command(resume=is_approved) -# stream = graph.stream(resume_command, config=config, stream_mode="messages") -# graph.invoke(resume_command, config=config) + @tool(name_or_callable="人工审批工具", description="请求人工审批工具,用于在执行重要操作前获得人类确认。") def get_approved_user_goal( operation_description: str, @@ -54,50 +49,6 @@ def get_approved_user_goal( return result -# TODO[修改建议]:前端需要通过interrupt进行交互,点击是或否来批准执行 -# 返回中断点: -# is_approved : bool = True 或者 False -# resume_command = Command(resume=is_approved) -# stream = graph.stream(resume_command, config=config, stream_mode="messages") -# graph.invoke(resume_command, config=config) -@tool(name_or_callable="人工审批工具", description="请求人工审批工具,用于在执行重要操作前获得人类确认。") -def get_approved_user_goal( - operation_description: str, -) -> dict: - """ - 请求人工审批,在执行重要操作前获得人类确认。 - - Args: - operation_description: 需要审批的操作描述,例如 "调用知识库工具" - Returns: - dict: 包含审批结果的字典,格式为 {"approved": bool, "message": str} - """ - # 构建详细的中断信息 - interrupt_info = { - "question": "是否批准以下操作?", - "operation": operation_description, - } - - # 触发人工审批 - is_approved = interrupt(interrupt_info) - - # 返回审批结果 - if is_approved: - result = { - "approved": True, - "message": f"✅ 操作已批准:{operation_description}", - } - print(f"✅ 人工审批通过: {operation_description}") - else: - result = { - "approved": False, - "message": f"❌ 操作被拒绝:{operation_description}", - } - print(f"❌ 人工审批被拒绝: {operation_description}") - - return result - - @tool(name_or_callable="查询知识图谱", description="使用这个工具可以查询知识图谱中包含的三元组信息。") def query_knowledge_graph(query: Annotated[str, "The keyword to query knowledge graph."]) -> Any: """Use this to query knowledge graph, which include some food domain knowledge.""" diff --git a/src/agents/reporter/graph.py b/src/agents/reporter/graph.py index 51563f58..29c12b69 100644 --- a/src/agents/reporter/graph.py +++ b/src/agents/reporter/graph.py @@ -39,7 +39,7 @@ async def context_based_model(request: ModelRequest, handler) -> ModelResponse: class SqlReporterAgent(BaseAgent): - name = "SQL 报告助手" + name = "数据库报表助手" description = "一个能够生成 SQL 查询报告的智能体助手。同时调用 Charts MCP 生成图表。" def __init__(self, **kwargs):