-- ============================================================================ -- Agent 工具包表(agent_tool_pack) -- -- 设计要点: -- 1) 工具包 = 用户自定义的「任意工具组合」:tool_names 收录 agent_tool.tool_name 清单 -- (业务工具,不含 base 组基础工具 —— 基础工具始终注册、对模型始终可见); -- 2) 在「插件与技能 → 工具包」维护,在「新建研判方案」时勾选启用; -- 与方案的 tools_allow_json(工具组白名单)叠加: -- 组白名单 ∪ 工具包内工具 = 该方案最终可见的业务工具;全不勾 = 不限制(默认口径); -- 3) 按用户隔离(user_id):只有创建者可见/可改/可删;方案绑定工具包时后端校验归属; -- 4) tool_names 用 TEXT 存 JSON 字符串数组(与 agent.tools_allow_json 同口径,前端直接收数组)。 -- -- 执行库:PostgreSQL(master) -- -- ⚠️ 建表由**人工执行本脚本**完成,应用启动时不做 DDL(与 agent_tool.sql 同约定)。 -- 固定表名的建表语句只放 sql/ 脚本;代码里不做 CREATE TABLE。 -- ============================================================================ CREATE TABLE IF NOT EXISTS agent_tool_pack ( id BIGINT PRIMARY KEY, -- 应用侧生成(雪花 ID,MyBatis-Plus IdType.ASSIGN_ID) user_id BIGINT NOT NULL, -- 创建者(sa-token 登录用户 ID) name VARCHAR(100) NOT NULL, -- 工具包名(同用户内唯一) description VARCHAR(500), -- 一句话说明 tool_names TEXT NOT NULL DEFAULT '[]', -- 工具名清单(JSON 字符串数组,取 agent_tool.tool_name) create_at TIMESTAMP DEFAULT now(), update_at TIMESTAMP DEFAULT now() ); CREATE INDEX IF NOT EXISTS idx_agent_tool_pack_user ON agent_tool_pack(user_id); CREATE UNIQUE INDEX IF NOT EXISTS uk_agent_tool_pack_user_name ON agent_tool_pack(user_id, name); COMMENT ON TABLE agent_tool_pack IS '研判方案工具包:用户自定义工具组合,在「插件与技能 → 工具包」维护、新建方案时勾选'; COMMENT ON COLUMN agent_tool_pack.user_id IS '创建者(sa-token 登录用户 ID),用户隔离依据'; COMMENT ON COLUMN agent_tool_pack.name IS '工具包名(同用户内唯一)'; COMMENT ON COLUMN agent_tool_pack.tool_names IS '工具名清单(JSON 字符串数组),取值 agent_tool.tool_name(业务工具)'; -- 方案绑定的工具包(JSON 字符串数组:工具包 id 列表); -- 与 tools_allow_json(工具组白名单)叠加构成该方案的业务工具白名单 ALTER TABLE agent ADD COLUMN IF NOT EXISTS tool_packs_json TEXT; COMMENT ON COLUMN agent.tool_packs_json IS '方案勾选的工具包 id 列表(JSON 字符串数组);与 tools_allow_json 并集构成业务工具白名单'; -- ============================================================================ -- 系统内置工具包(is_builtin = 1) -- -- 语义与内置专家一致:全局可见、不可编辑、不可删除(服务端双重校验); -- user_id = 1(平台管理员);id 固定 1~6(雪花 ID 段远大于此,不会冲突), -- 便于其它脚本引用(如默认方案绑定)。 -- -- 六个内置包与业务工具组同构(工具名取自 AgentToolRegistry 各组清单), -- 供新建研判方案时一键勾选,无需自行组合。 -- ============================================================================ ALTER TABLE agent_tool_pack ADD COLUMN IF NOT EXISTS is_builtin SMALLINT NOT NULL DEFAULT 0; COMMENT ON COLUMN agent_tool_pack.is_builtin IS '1=系统内置(全局可见、不可编辑/删除);0=用户自建'; INSERT INTO agent_tool_pack (id, user_id, name, description, tool_names, is_builtin, create_at, update_at) VALUES (1, 1, '人员画像与亲密度', '人员枚举、通话/交易画像、常联系与常交易 TOP、亲密度分析等 12 个工具。', '["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"]', 1, now(), now()), (2, 1, '通话分析', '通话原始明细与夜间、连续、特殊日期敏感通话的汇总与明细,共 7 个工具。', '["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"]', 1, now(), now()), (3, 1, '交易与资金分析', '交易原始明细、大额/共同/代持/现金流/连续交易、快进快出等 16 个工具。', '["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"]', 1, now(), now()), (4, 1, '轨迹、出行与快递', '基站轨迹、境外活动、快递收寄、人员碰面、同住、同行出行等 16 个工具。', '["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"]', 1, now(), now()), (5, 1, '关系图谱', '案件关系网络取数(节点 + 连线),共 1 个工具。', '["get_case_graph"]', 1, now(), now()), (6, 1, '非表格材料档案', 'txt / doc / pdf 等非表格材料的清单检索与正文阅读,共 3 个工具。', '["list_file_profiles","stat_file_profiles_by_category","get_file_sample"]', 1, now(), now()) ON CONFLICT (id) DO NOTHING; -- 默认方案(row_id=1,内置「数刃」)绑定全部内置工具包; -- 内置方案不可编辑(服务端拒绝),其绑定关系只能由本脚本维护 UPDATE agent SET tool_packs_json = '["1","2","3","4","5","6"]' WHERE row_id = 1;