package com.xly.tool; import com.xly.agent.AgentIdentity; import com.xly.service.PreviewService; import dev.langchain4j.agent.tool.P; import dev.langchain4j.agent.tool.Tool; /** * PreviewChange 工具(写路径的模型侧入口,**只读**)。 * *

模型解析出「对哪条记录做什么改动」后,本工具生成一张**预览卡**:整表当前值 + 改动/状态变化高亮 + * ERP 同名操作按钮(保存/审核/反审核/作废/取消作废/删除)。**本工具不写入任何数据**——用户点卡上按钮后, * 确定性端点(/api/agent/preview/{id}/save)重校验并写 ai_op_queue(AI 侧唯一写入口),执行由 ERP 侧负责。 * *

由 {@code AgentFactory} 按请求身份新建:携带 {@link AgentIdentity}(工具内鉴权)与会话 id。 */ public class PreviewChangeTool { private final PreviewService previews; private final AgentIdentity identity; private final String convId; public PreviewChangeTool(PreviewService previews, AgentIdentity identity, String convId) { this.previews = previews; this.identity = identity; this.convId = convId; } @Tool("为一次写操作生成**预览卡**(只读:本工具绝不写入数据,也不生成任何单据)。卡片展示记录当前内容、" + "改动或状态变化高亮,并带对应操作按钮(保存/审核/反审核/作废/取消作废/删除);只有用户点了按钮," + "系统才会提交待办。action:update=改字段(recordKeyword+fieldChinese+newValue);" + "invalid=作废(业务单据要“删除/取消”一律用它,可复原);cancelInvalid=复原/取消作废;examine=审核;" + "cancelExamine=销审/反审核;delete=物理删除(业务单据别用)。**新增不用本工具**(新增走 collectForm)。" + "本工具自行定位主表与记录,无需先 findForms。预览卡出现后你就停下等用户,绝不能说已保存/已完成。") public String previewChange( @P("动作:update|invalid|cancelInvalid|examine|cancelExamine|delete") String action, @P("实体/单据类型,如 报价 / 客户 / 销售订单") String entityKeyword, @P("记录名称或单号关键词") String recordKeyword, @P(value = "要改的字段中文名(仅 update)", required = false) String fieldChinese, @P(value = "新值(仅 update,逐字照抄用户原话)", required = false) String newValue) { return previews.buildPreview(identity, convId, action, entityKeyword, recordKeyword, fieldChinese, newValue); } }