Commit 5c38d571e483b6dbc577f28ecee951fc2a2b1d11
1 parent
6e789a25
添加未清选择 改成动态引导语
Showing
2 changed files
with
84 additions
and
12 deletions
src/main/java/com/xly/service/XlyErpService.java
| ... | ... | @@ -352,9 +352,10 @@ public class XlyErpService { |
| 352 | 352 | ){ |
| 353 | 353 | String sSystemPrompt = AgentSystemPrompt.sSystemPrompt; |
| 354 | 354 | //如果客户输入了确认/生成 切换引导语言 |
| 355 | - Boolean isConfirmed = dynamicToolProvider.isConfirmed(input) || input.contains("生成") || input.contains("确认"); | |
| 355 | + Boolean isConfirmed = dynamicToolProvider.isConfirmed(input,session); | |
| 356 | 356 | if(ObjectUtil.isNotEmpty(session.getSSystemPrompt()) && isConfirmed){ |
| 357 | 357 | sSystemPrompt = session.getSSystemPrompt(); |
| 358 | +// session.setSSystemPrompt(); | |
| 358 | 359 | //重新生成新的aiAgent拿新的aiAgent 做选择 |
| 359 | 360 | aiAgent = createConfirmeAgent(session); |
| 360 | 361 | } | ... | ... |
src/main/java/com/xly/tool/DynamicToolProvider.java
| 1 | 1 | package com.xly.tool; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import cn.hutool.core.util.BooleanUtil; | |
| 4 | 5 | import cn.hutool.core.util.ObjectUtil; |
| 5 | 6 | import cn.hutool.core.util.StrUtil; |
| 6 | 7 | import cn.hutool.json.JSONUtil; |
| ... | ... | @@ -464,6 +465,10 @@ public class DynamicToolProvider implements ToolProvider { |
| 464 | 465 | public String doDynamicTool(ToolMeta meta,UserSceneSession session) { |
| 465 | 466 | List<ParamRule> paramRuleData = meta.getParamRuleListAll(); |
| 466 | 467 | List<ParamRule> paramRuleDataCheck = meta.getParamRuleListCheck(); |
| 468 | + Map<String, Object> argsOld = session.getArgs(); | |
| 469 | + if(ObjectUtil.isEmpty(argsOld)){ | |
| 470 | + argsOld = new HashMap<>(); | |
| 471 | + } | |
| 467 | 472 | Map<String, Object> args = session.getArgs(); |
| 468 | 473 | |
| 469 | 474 | List<String> missing = checkRequiredParams(args, paramRuleDataCheck); |
| ... | ... | @@ -478,8 +483,7 @@ public class DynamicToolProvider implements ToolProvider { |
| 478 | 483 | if (userMessage != null) { |
| 479 | 484 | input = StrUtil.replace(getChatMessageContent(userMessage), "用户输入:", StrUtil.EMPTY); |
| 480 | 485 | } |
| 481 | - | |
| 482 | - Boolean isConfirmed = isConfirmed(input) || input.contains("生成") || input.contains("确认"); | |
| 486 | + Boolean isConfirmed = isConfirmed(input,session); | |
| 483 | 487 | |
| 484 | 488 | if((isConfirmed && (4== meta.getIBizType() ||1== meta.getIBizType())) |
| 485 | 489 | || 2== meta.getIBizType() |
| ... | ... | @@ -491,8 +495,15 @@ public class DynamicToolProvider implements ToolProvider { |
| 491 | 495 | { |
| 492 | 496 | List<String> missingAfter = checkConfirmAfterParam(args, paramRuleData); |
| 493 | 497 | if (!missingAfter.isEmpty()) { |
| 498 | + //合并已选择数据 | |
| 499 | + argsOld.putAll(args); | |
| 500 | + session.setArgs(argsOld); | |
| 494 | 501 | String askMsg = buildAskUserMessage(meta, missingAfter,args); |
| 495 | - throw new DataException(askMsg); | |
| 502 | + session.setSFunPrompts(askMsg); | |
| 503 | + List<ParamRule> paramRuleDataMiss = getMissParamRuleAfter(args, paramRuleData); | |
| 504 | + String sSystemPrompt = buildMissParamPrompt(session,paramRuleDataMiss); | |
| 505 | + session.setSSystemPrompt(sSystemPrompt); | |
| 506 | + return askMsg; | |
| 496 | 507 | } |
| 497 | 508 | return executeTool(meta, args, paramRuleData, session.getUserId(), session); |
| 498 | 509 | } |
| ... | ... | @@ -720,15 +731,34 @@ public class DynamicToolProvider implements ToolProvider { |
| 720 | 731 | return bDbZero || bBhcs || (!returnMap.containsKey(pd.getSParamValue()) || (ObjectUtil.isEmpty(returnMap.get(pd.getSParamValue())))); |
| 721 | 732 | } |
| 722 | 733 | |
| 734 | + /*** | |
| 735 | + * @Author 钱豹 | |
| 736 | + * @Date 1:08 2026/5/19 | |
| 737 | + * @Param [args, paramDefs] | |
| 738 | + * @return java.util.List<java.lang.String> | |
| 739 | + * @Description 获取缺失参数提示 | |
| 740 | + **/ | |
| 723 | 741 | private List<String> checkConfirmAfterParam(Map<String, Object> args, List<ParamRule> paramDefs) { |
| 742 | + List<ParamRule> paramRuleList = getMissParamRuleAfter( args, paramDefs); | |
| 743 | + return paramRuleList.stream() | |
| 744 | + .map(ParamRule::getSParam) | |
| 745 | + .toList(); | |
| 746 | + } | |
| 747 | + | |
| 748 | + /*** | |
| 749 | + * @Author 钱豹 | |
| 750 | + * @Date 2026/5/19 | |
| 751 | + * @Param [args, paramDefs] | |
| 752 | + * @return java.util.List<com.xly.entity.ParamRule> | |
| 753 | + * @Description 获取保存后的缺失参数 | |
| 754 | + **/ | |
| 755 | + private List<ParamRule> getMissParamRuleAfter(Map<String, Object> args, List<ParamRule> paramDefs) { | |
| 724 | 756 | Map<String,Object> returnMap = transformationArgs( args, paramDefs); |
| 725 | 757 | return paramDefs.stream() |
| 726 | - .filter(pd -> Boolean.TRUE.equals(pd.getBConfirmAfter()) && pd.getBTipModel()) | |
| 727 | - .filter(pd -> | |
| 728 | - (!returnMap.containsKey(pd.getSParam()) || (ObjectUtil.isEmpty(returnMap.get(pd.getSParam())))) | |
| 729 | - && (!returnMap.containsKey(pd.getSParamValue()) || (ObjectUtil.isEmpty(returnMap.get(pd.getSParamValue())))) | |
| 730 | - ) | |
| 731 | - .map(ParamRule::getSParam) | |
| 758 | + .filter(pd -> ObjectUtil.isNotEmpty(pd.getBConfirmAfter()) && BooleanUtil.toBoolean(pd.getBConfirmAfter().toString())) | |
| 759 | + .filter(pd -> (!returnMap.containsKey(pd.getSParam()) || (ObjectUtil.isEmpty(returnMap.get(pd.getSParam())))) | |
| 760 | + && (!returnMap.containsKey(pd.getSParamValue()) || (ObjectUtil.isEmpty(returnMap.get(pd.getSParamValue())))) | |
| 761 | + ) | |
| 732 | 762 | .toList(); |
| 733 | 763 | } |
| 734 | 764 | |
| ... | ... | @@ -1013,6 +1043,40 @@ public class DynamicToolProvider implements ToolProvider { |
| 1013 | 1043 | return markdown.toString(); |
| 1014 | 1044 | } |
| 1015 | 1045 | |
| 1046 | + | |
| 1047 | + /** | |
| 1048 | + * 缺失参数统一提示模板:强制AI调用自定义方法,一次性回填所有参数 | |
| 1049 | + */ | |
| 1050 | + public String buildMissParamPrompt(UserSceneSession session, List<ParamRule> paramRuleDataMiss) { | |
| 1051 | + String methodNo = session.getCurrentTool().getSMethodNo(); | |
| 1052 | + String rowJson = JSONUtil.toJsonStr(session.getArgs()); | |
| 1053 | + | |
| 1054 | + String paramDesc = paramRuleDataMiss.stream() | |
| 1055 | + .map(p -> p.getSParam() + ":" + p.getSParamValue() + ",示例:" + p.getSExampleValue()) | |
| 1056 | + .collect(Collectors.joining("\n")); | |
| 1057 | + | |
| 1058 | + String paramKeys = paramRuleDataMiss.stream() | |
| 1059 | + .map(p -> "\"" + p.getSParamValue() + "\":\"\"") | |
| 1060 | + .collect(Collectors.joining(",")); | |
| 1061 | + | |
| 1062 | + return String.format(""" | |
| 1063 | + 请你补充参数。 | |
| 1064 | + | |
| 1065 | + 【极强约束·必须100%%遵守】 | |
| 1066 | + 1. 必须调用方法:%s | |
| 1067 | + 2. 只输出标准JSON,禁止说话、禁止解释、禁止换行 | |
| 1068 | + | |
| 1069 | + 缺失参数: | |
| 1070 | + %s | |
| 1071 | + | |
| 1072 | + 已填数据: | |
| 1073 | + %s | |
| 1074 | + | |
| 1075 | + 输出格式: | |
| 1076 | + {%s} | |
| 1077 | + """, methodNo, paramDesc, rowJson, paramKeys); | |
| 1078 | + } | |
| 1079 | + | |
| 1016 | 1080 | public String buildDynamicSystemPrompt(UserSceneSession session) { |
| 1017 | 1081 | String methodNo = session.getCurrentTool().getSMethodNo(); |
| 1018 | 1082 | String rowJson = JSONUtil.toJsonStr(session.getCurrentRowData()); |
| ... | ... | @@ -1161,7 +1225,14 @@ public class DynamicToolProvider implements ToolProvider { |
| 1161 | 1225 | return String.format("%s", result.get("initialResult")); |
| 1162 | 1226 | } |
| 1163 | 1227 | |
| 1164 | - public boolean isConfirmed(String userResponse) { | |
| 1165 | - return userResponse.matches("(?i)(确认|全部确认|部分确认|是|yes|confirm|true|是的|可以|没问题|确定|好的|生成|)"); | |
| 1228 | + public boolean isConfirmed(String userResponse,UserSceneSession session) { | |
| 1229 | + boolean check = userResponse.matches("(?i)(确认|全部确认|部分确认|是|yes|confirm|true|是的|可以|没问题|确定|好的|生成|)"); | |
| 1230 | + return check || userResponse.contains("生成") | |
| 1231 | + || userResponse.contains("确认") | |
| 1232 | + || (ObjectUtil.isNotEmpty(session.getArgs()) | |
| 1233 | + && session.getArgs().containsKey("operateType") | |
| 1234 | + && session.getArgs().containsKey("sSlaveId") | |
| 1235 | + && ObjectUtil.isNotEmpty(session.getArgs().get("sSlaveId")) | |
| 1236 | + ); | |
| 1166 | 1237 | } |
| 1167 | 1238 | } |
| 1168 | 1239 | \ No newline at end of file | ... | ... |