agent_tool_pack.sql 6.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. -- ============================================================================
  2. -- Agent 工具包表(agent_tool_pack)
  3. --
  4. -- 设计要点:
  5. -- 1) 工具包 = 用户自定义的「任意工具组合」:tool_names 收录 agent_tool.tool_name 清单
  6. -- (业务工具,不含 base 组基础工具 —— 基础工具始终注册、对模型始终可见);
  7. -- 2) 在「插件与技能 → 工具包」维护,在「新建研判方案」时勾选启用;
  8. -- 与方案的 tools_allow_json(工具组白名单)叠加:
  9. -- 组白名单 ∪ 工具包内工具 = 该方案最终可见的业务工具;
  10. -- 工具包与工具组都不勾 = 仅注册基础设施工具,不注册业务工具;
  11. -- 3) 按用户隔离(user_id):只有创建者可见/可改/可删;方案绑定工具包时后端校验归属;
  12. -- 4) tool_names 用 TEXT 存 JSON 字符串数组(与 agent.tools_allow_json 同口径,前端直接收数组)。
  13. --
  14. -- 执行库:PostgreSQL(master)
  15. --
  16. -- ⚠️ 建表由**人工执行本脚本**完成,应用启动时不做 DDL(与 agent_tool.sql 同约定)。
  17. -- 固定表名的建表语句只放 sql/ 脚本;代码里不做 CREATE TABLE。
  18. -- ============================================================================
  19. CREATE TABLE IF NOT EXISTS agent_tool_pack (
  20. id BIGINT PRIMARY KEY, -- 应用侧生成(雪花 ID,MyBatis-Plus IdType.ASSIGN_ID)
  21. user_id BIGINT NOT NULL, -- 创建者(sa-token 登录用户 ID)
  22. name VARCHAR(100) NOT NULL, -- 工具包名(同用户内唯一)
  23. description VARCHAR(500), -- 一句话说明
  24. tool_names TEXT NOT NULL DEFAULT '[]', -- 工具名清单(JSON 字符串数组,取 agent_tool.tool_name)
  25. create_at TIMESTAMP DEFAULT now(),
  26. update_at TIMESTAMP DEFAULT now()
  27. );
  28. CREATE INDEX IF NOT EXISTS idx_agent_tool_pack_user ON agent_tool_pack(user_id);
  29. CREATE UNIQUE INDEX IF NOT EXISTS uk_agent_tool_pack_user_name ON agent_tool_pack(user_id, name);
  30. COMMENT ON TABLE agent_tool_pack IS '研判方案工具包:用户自定义工具组合,在「插件与技能 → 工具包」维护、新建方案时勾选';
  31. COMMENT ON COLUMN agent_tool_pack.user_id IS '创建者(sa-token 登录用户 ID),用户隔离依据';
  32. COMMENT ON COLUMN agent_tool_pack.name IS '工具包名(同用户内唯一)';
  33. COMMENT ON COLUMN agent_tool_pack.tool_names IS '工具名清单(JSON 字符串数组),取值 agent_tool.tool_name(业务工具)';
  34. -- 方案绑定的工具包(JSON 字符串数组:工具包 id 列表);
  35. -- 与 tools_allow_json(工具组白名单)叠加构成该方案的业务工具白名单
  36. ALTER TABLE agent ADD COLUMN IF NOT EXISTS tool_packs_json TEXT;
  37. COMMENT ON COLUMN agent.tool_packs_json IS '方案勾选的工具包 id 列表(JSON 字符串数组);与 tools_allow_json 并集构成业务工具白名单';
  38. -- ============================================================================
  39. -- 系统内置工具包(is_builtin = 1)
  40. --
  41. -- 语义与内置专家一致:全局可见、不可编辑、不可删除(服务端双重校验);
  42. -- user_id = 1(平台管理员);id 固定 1~6(雪花 ID 段远大于此,不会冲突),
  43. -- 便于其它脚本引用(如默认方案绑定)。
  44. --
  45. -- 六个内置包与业务工具组同构(工具名取自 AgentToolRegistry 各组清单),
  46. -- 供新建研判方案时一键勾选,无需自行组合。
  47. -- ============================================================================
  48. ALTER TABLE agent_tool_pack ADD COLUMN IF NOT EXISTS is_builtin SMALLINT NOT NULL DEFAULT 0;
  49. COMMENT ON COLUMN agent_tool_pack.is_builtin IS '1=系统内置(全局可见、不可编辑/删除);0=用户自建';
  50. INSERT INTO agent_tool_pack (id, user_id, name, description, tool_names, is_builtin, create_at, update_at)
  51. VALUES
  52. (1, 1, '人物画像', '人员枚举、通话/交易画像、常联系与常交易 TOP、亲密度分析等 12 个工具。',
  53. '["get_person_call_profile","stat_person_call_station","stat_person_call_top10","stat_call_record_summary","get_person_trans_profile","stat_person_trans_top10","stat_trans_record_summary","get_trans_bank_card_info","stat_trans_amount_trend_month","stat_trans_amount_trend_year","stat_intimacy_summary","list_persons"]',
  54. 1, now(), now()),
  55. (2, 1, '通话分析', '通话原始明细与夜间、连续、特殊日期敏感通话的汇总与明细,共 7 个工具。',
  56. '["get_call_records","stat_call_night_summary","stat_call_night_detail","stat_call_continuous_summary","stat_call_continuous_detail","stat_call_sensitive_summary","stat_call_sensitive_detail"]',
  57. 1, now(), now()),
  58. (3, 1, '交易与资金分析', '交易原始明细、大额/共同/代持/现金流/连续交易、快进快出等 16 个工具。',
  59. '["get_trans_records","stat_trans_big_summary","stat_trans_big_by_date","stat_trans_big_detail","stat_trans_together","stat_trans_card_hold","stat_trans_cash_flow","stat_trans_continuous_summary","stat_trans_continuous_detail","stat_trans_fast_fund_flow","stat_trans_financial","stat_trans_fixed_deposit","stat_trans_fixed_deposit_detail","stat_trans_frequency","stat_trans_sensitive_summary","stat_trans_sensitive_detail"]',
  60. 1, now(), now()),
  61. (4, 1, '轨迹、出行与快递', '基站轨迹、境外活动、快递收寄、人员碰面、同住、同行出行等 16 个工具。',
  62. '["stat_track_cell_tower_summary","stat_track_cell_tower_detail","stat_track_en_local_summary","stat_track_en_local_detail","stat_express_summary","stat_express_by_phone","get_express_records","stat_track_meet_summary","stat_track_meet_detail","stat_together_live_summary","stat_together_live_detail","get_hotel_stay_detail","get_together_live_info_detail","stat_together_travel_summary","stat_together_travel_detail","get_travel_record_detail"]',
  63. 1, now(), now()),
  64. (5, 1, '关系图谱', '案件关系网络取数(节点 + 连线),共 1 个工具。',
  65. '["get_case_graph"]',
  66. 1, now(), now()),
  67. (6, 1, '非表格材料档案', 'txt / doc / pdf 等非表格材料的清单检索与正文阅读,共 3 个工具。',
  68. '["list_file_profiles","stat_file_profiles_by_category","get_file_sample"]',
  69. 1, now(), now())
  70. ON CONFLICT (id) DO NOTHING;
  71. -- 默认方案(row_id=1,内置「数刃」)绑定全部内置工具包;
  72. -- 内置方案不可编辑(服务端拒绝),其绑定关系只能由本脚本维护
  73. UPDATE agent SET tool_packs_json = '["1","2","3","4","5","6"]' WHERE row_id = 1;