ai_remove_unused_tools_20261117.sql 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. -- ============================================================================
  2. -- 移除平台内置无用工具:get_current_time / get_current_user / ai_usage_by_agent / get_current_workspace
  3. --
  4. -- 背景:
  5. -- 1) 当前时间已由 CurrentTimeMiddleware 每轮注入 system prompt(分钟精度),
  6. -- 不再需要模型调用工具查时间;
  7. -- 2) 提问用户身份由平台运行期上下文提供,业务分析工具不依赖该工具;
  8. -- 3) 「按智能体用量」工具及其专属 IPlatformUsageService / PlatformUsageMapper 一并下线;
  9. -- 4) get_current_workspace(WorkspaceInfoTool)随工作空间信息工具整体下线。
  10. --
  11. -- 幂等:可重复执行。
  12. -- ============================================================================
  13. -- 一、清理引用(先清引用,再删注册行)
  14. delete from ai_scenario_pack_tool
  15. where tool_code in ('get_current_time', 'get_current_user', 'ai_usage_by_agent', 'get_current_workspace');
  16. delete from ai_agent_tool
  17. where tool_code in ('get_current_time', 'get_current_user', 'ai_usage_by_agent', 'get_current_workspace');
  18. delete from ai_agent_tool_trust
  19. where tool_code in ('get_current_time', 'get_current_user', 'ai_usage_by_agent', 'get_current_workspace');
  20. delete from ai_session_resource
  21. where resource_type = 'tool'
  22. and resource_id in (select id from ai_tool
  23. where tool_code in ('get_current_time', 'get_current_user', 'ai_usage_by_agent', 'get_current_workspace'));
  24. delete from ai_tool_tag_rel
  25. where tool_id in (select id from ai_tool
  26. where tool_code in ('get_current_time', 'get_current_user', 'ai_usage_by_agent', 'get_current_workspace'));
  27. -- 二、删除工具注册行
  28. delete from ai_tool
  29. where tool_code in ('get_current_time', 'get_current_user', 'ai_usage_by_agent', 'get_current_workspace');
  30. -- 三、修正入口 / 专家提示词中「调用 get_current_time / get_current_user」的旧指引
  31. -- (仅命中旧文案时替换;提示词已被人工改过则保持原样)
  32. update ai_entry_agent
  33. set sys_prompt = replace(sys_prompt,
  34. '5. 涉及今天、本周、距今多久等时间语义时,可调用 get_current_time 获取精确时间;需要判断当前是谁在问时,可用 get_current_user 或 get_current_dept。',
  35. '5. 涉及今天、本周、距今多久等时间语义时,直接使用 system prompt 末尾「当前时间」段落给出的时间,不要凭猜测判断,也不需要调用工具查询时间。')
  36. where sys_prompt like '%get_current_time%';
  37. update ai_expert_agent
  38. set sys_prompt = replace(sys_prompt,
  39. '5. 涉及今天、本周、距今多久等时间语义时,可调用 get_current_time 获取精确时间;需要判断当前是谁在问时,可用 get_current_user 或 get_current_dept。',
  40. '5. 涉及今天、本周、距今多久等时间语义时,直接使用 system prompt 末尾「当前时间」段落给出的时间,不要凭猜测判断,也不需要调用工具查询时间。')
  41. where sys_prompt like '%get_current_time%';