V20261117_02__ai_remove_unused_tools.sql 3.4 KB

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