diff --git a/backend/doc/LLM拼装需求.md b/backend/doc/LLM拼装需求.md index 4b1a04e..1e5d6c5 100644 --- a/backend/doc/LLM拼装需求.md +++ b/backend/doc/LLM拼装需求.md @@ -8,6 +8,8 @@ 人形机器人的常见构成只存在于 Skill 的自然语言提示词:通常尝试躯干、头部、两条手臂、两条腿、两只手和两只脚。它不是数据库蓝图、固定槽位、类别枚举或硬校验。用户明确需求优先,且所有组件与接口必须来自实际组件库。 +构型完整性由 Skill 规划并由提案验收层强制检查:需求或上下文明确定义为四足时,除非用户明确要求局部、缺腿、裸躯干或轮式运动模块,否则结果必须包含四足躯干和与其连通的四条独立腿;具体组件按用户描述匹配。明确定义为轮式时,除非用户明确要求裸底座、移除上装或只处理底座,否则结果必须包含轮式底座和至少一个通过真实接口连接的上装功能组件;上装类型按用户描述匹配。通用模拟器仍只校验实例图,避免影响合法的局部测试;不完整构型会在 `propose_assembly_plan` 阶段被拒绝并要求模型继续规划。 + 不会实现或恢复以下规则: - 躯干、头、手、腿、左右件或任意分类的唯一性; @@ -53,7 +55,7 @@ Skill 资源版本化存放在: - `src/main/resources/skills/robot-assembly-planner/v1/system-prompt.md` - `src/main/resources/skills/robot-assembly-planner/v1/tools.json` -`DeepSeekRobotAssemblyPlanner` 使用 DeepSeek Chat Completions 原生 `tools/tool_calls` 循环,单次规划最多执行 16 个工具轮次,防止模型无进展循环持续消耗 token。独立检索应在同一轮并行调用;`simulate_assembly_plan` 可携带 `replyText`,模拟成功后直接形成提案,旧的 `propose_assembly_plan` 两步流程保留为兼容兜底。成功提案或模型返回最终文本后规划器结束工具循环;单次模型 HTTP 请求仍保留超时和错误处理。 +`DeepSeekRobotAssemblyPlanner` 使用 DeepSeek Chat Completions 原生 `tools/tool_calls` 循环,单次规划最多执行 30 个工具轮次,防止模型无进展循环持续消耗 token。独立检索应在同一轮并行调用;装配计划必须先调用 `simulate_assembly_plan`,再将最近一次成功模拟的 ID 交给 `propose_assembly_plan` 验收。只有成功提案或模型返回最终文本后规划器才结束工具循环;单次模型 HTTP 请求仍保留超时和错误处理。 | 工具 | 作用 | 是否写库 | | --- | --- | --- | @@ -62,10 +64,10 @@ Skill 资源版本化存放在: | `get_component_details` | 查询组件完整接口 | 否 | | `get_current_assembly` | 查询当前实例图 | 否 | | `find_compatible_mounts` | 查询候选组件可挂接的现有接口 | 否 | -| `simulate_assembly_plan` | 在当前图副本应用完整计划;携带 `replyText` 时成功后直接形成提案 | 否,仅请求内内存 | +| `simulate_assembly_plan` | 在当前图副本应用并校验完整计划,返回临时 `simulationId` | 否,仅请求内内存 | | `propose_assembly_plan` | 引用最近一次成功模拟,交给服务端提交 | 否 | -模型应先检索实际组件,再查询所选组件的接口和当前图;计划必须通过 `simulate_assembly_plan`。服务端为成功模拟生成 `simulationId`;正常路径在模拟参数中同时提供 `replyText` 并直接形成提案,只有兼容兜底路径需要再用最后一次成功模拟的 ID 调用 `propose_assembly_plan`。提案本身不写库。 +模型应先检索实际组件,再查询所选组件的接口和当前图;计划必须通过 `simulate_assembly_plan`。服务端为成功模拟生成 `simulationId`,模型再用最后一次成功模拟的 ID 和最终 `replyText` 调用 `propose_assembly_plan`。提案验收会拒绝缺少四足躯干/四条连通腿或缺少轮式底座/连通上装的默认构型,提案本身不写库。 ## 实例图和计划 diff --git a/backend/doc/机器人装配对话接口文档.md b/backend/doc/机器人装配对话接口文档.md index 3d76e3b..a93440e 100644 --- a/backend/doc/机器人装配对话接口文档.md +++ b/backend/doc/机器人装配对话接口文档.md @@ -86,6 +86,6 @@ - 同一组件允许重复安装;分类、`robotType`、左右语义和人形部位都不是执行器约束。 - 提交前会重新模拟计划,并以 `assemblyVersion` 条件更新会话。第一次版本冲突会基于最新图重跑 Skill;再次冲突返回 `ROBOT_ASSEMBLY_CONFLICT`,不会提交旧计划。 -装配规划最多执行 16 个工具轮次,成功提案或模型返回最终文本后立即结束。 +装配规划最多执行 30 个工具轮次,成功提案或模型返回最终文本后立即结束。 常见错误码:`ROBOT_LLM_NOT_CONFIGURED`、`ROBOT_LLM_REQUEST_FAILED`、`ROBOT_LLM_EMPTY_RESPONSE`、`ROBOT_PLAN_REVALIDATION_FAILED`、`ROBOT_ASSEMBLY_CONFLICT`。 diff --git a/backend/src/main/java/com/robotquan/momatchengine/service/impl/DeepSeekRobotAssemblyPlanner.java b/backend/src/main/java/com/robotquan/momatchengine/service/impl/DeepSeekRobotAssemblyPlanner.java index 3fcb20a..a226ed9 100644 --- a/backend/src/main/java/com/robotquan/momatchengine/service/impl/DeepSeekRobotAssemblyPlanner.java +++ b/backend/src/main/java/com/robotquan/momatchengine/service/impl/DeepSeekRobotAssemblyPlanner.java @@ -35,7 +35,7 @@ import org.springframework.util.StringUtils; public class DeepSeekRobotAssemblyPlanner { private static final String SKILL_ROOT = "skills/robot-assembly-planner/v1/"; - private static final int MAX_TOOL_ROUNDS = 16; + private static final int MAX_TOOL_ROUNDS = 30; private final ObjectMapper objectMapper; private final DeepSeekProperties properties; @@ -60,7 +60,7 @@ public class DeepSeekRobotAssemblyPlanner { List history, String userMessage) { ensureConfigured(); - RobotAssemblyPlannerTools.PlannerSession session = tools.openSession(currentAssembly); + RobotAssemblyPlannerTools.PlannerSession session = tools.openSession(currentAssembly, userMessage); List> messages = initialMessages(history, userMessage); int toolRounds = 0; diff --git a/backend/src/main/java/com/robotquan/momatchengine/service/impl/RobotAssemblyPlannerTools.java b/backend/src/main/java/com/robotquan/momatchengine/service/impl/RobotAssemblyPlannerTools.java index 192c63f..90445c7 100644 --- a/backend/src/main/java/com/robotquan/momatchengine/service/impl/RobotAssemblyPlannerTools.java +++ b/backend/src/main/java/com/robotquan/momatchengine/service/impl/RobotAssemblyPlannerTools.java @@ -3,8 +3,9 @@ package com.robotquan.momatchengine.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ObjectNode; import com.robotquan.momatchengine.dto.component.ComponentAssemblyMetadata; +import com.robotquan.momatchengine.dto.robot.RobotAssemblyComponentView; +import com.robotquan.momatchengine.dto.robot.RobotAssemblyConnectionView; import com.robotquan.momatchengine.dto.robot.RobotAssemblyPlan; import com.robotquan.momatchengine.dto.robot.RobotAssemblyView; import com.robotquan.momatchengine.dto.robot.RobotComponentInterfaceView; @@ -13,10 +14,13 @@ import com.robotquan.momatchengine.mapper.ComponentMapper; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -38,7 +42,12 @@ public class RobotAssemblyPlannerTools { private final RobotAssemblyPlanSimulator planSimulator; public PlannerSession openSession(RobotAssemblyView currentAssembly) { - return new PlannerSession(currentAssembly == null ? RobotAssemblyView.empty() : currentAssembly); + return openSession(currentAssembly, ""); + } + + public PlannerSession openSession(RobotAssemblyView currentAssembly, String userMessage) { + RobotAssemblyView assembly = currentAssembly == null ? RobotAssemblyView.empty() : currentAssembly; + return new PlannerSession(assembly, completionRequirements(assembly, userMessage)); } public ToolResult execute(PlannerSession session, String toolName, JsonNode arguments) { @@ -128,15 +137,8 @@ public class RobotAssemblyPlannerTools { private ToolResult simulate(PlannerSession session, JsonNode arguments) { RobotAssemblyPlan plan; - String replyText = optionalText(arguments, "replyText"); try { - JsonNode planArguments = arguments; - if (arguments instanceof ObjectNode objectArguments && objectArguments.has("replyText")) { - ObjectNode copy = objectArguments.deepCopy(); - copy.remove("replyText"); - planArguments = copy; - } - plan = objectMapper.treeToValue(planArguments, RobotAssemblyPlan.class); + plan = objectMapper.treeToValue(arguments, RobotAssemblyPlan.class); } catch (Exception exception) { return ToolResult.failure("装配计划格式错误: " + exception.getMessage()); } @@ -149,13 +151,9 @@ public class RobotAssemblyPlannerTools { } String simulationId = "sim_" + UUID.randomUUID().toString().replace("-", ""); session.recordSuccessfulSimulation(simulationId, plan, result); - if (StringUtils.hasText(replyText)) { - session.propose(new ProposedPlan(simulationId, plan, result, replyText)); - } return ToolResult.success(assemblyModelMapper.writeJson(Map.of( "success", true, "simulationId", simulationId, - "proposalAccepted", StringUtils.hasText(replyText), "assembly", result.assembly(), "aliases", result.aliases() ))); @@ -176,7 +174,20 @@ public class RobotAssemblyPlannerTools { "reason", "simulationId 不存在或模拟未成功" ))); } - String replyText = optionalText(arguments, "replyText"); + String completionFailure = validateCompletion(session.requirements(), simulation.result().assembly()); + if (StringUtils.hasText(completionFailure)) { + return ToolResult.success(assemblyModelMapper.writeJson(Map.of( + "accepted", false, + "reason", completionFailure + ))); + } + String replyText = requiredText(arguments, "replyText"); + if (isExploratoryReply(replyText)) { + return ToolResult.success(assemblyModelMapper.writeJson(Map.of( + "accepted", false, + "reason", "replyText 仍是测试或探测说明;请确认完整计划后,改为描述最终实际装配结果。" + ))); + } session.propose(new ProposedPlan(simulationId, simulation.plan(), simulation.result(), replyText)); return ToolResult.success(assemblyModelMapper.writeJson(Map.of( "accepted", true, @@ -185,6 +196,172 @@ public class RobotAssemblyPlannerTools { ))); } + private CompletionRequirements completionRequirements(RobotAssemblyView assembly, String userMessage) { + String request = normalize(userMessage); + boolean quadruped = containsAny(request, "四足", "quadruped") || hasQuadrupedComponent(assembly); + boolean wheeled = containsAny(request, "轮式", "wheeled") || hasWheeledBase(assembly); + return new CompletionRequirements( + quadruped && !explicitQuadrupedException(request), + wheeled && !explicitWheeledException(request) + ); + } + + private String validateCompletion(CompletionRequirements requirements, RobotAssemblyView assembly) { + List components = componentSemantics(assembly); + if (requirements.quadruped()) { + Set torsoIds = componentIds(components, true); + Set legIds = componentIds(components, false); + Set connectedToTorso = connectedInstanceIds(assembly, torsoIds); + long connectedLegCount = legIds.stream().filter(connectedToTorso::contains).count(); + if (torsoIds.isEmpty() || connectedLegCount < 4) { + return "四足构型不完整:最终装配必须包含四足躯干和四条独立腿;当前识别到四足躯干 " + + torsoIds.size() + " 个、与躯干连通的四足腿 " + connectedLegCount + + " 条。请继续检索并在同一完整计划中补齐后重新模拟。"; + } + } + if (requirements.wheeled()) { + Set baseIds = components.stream() + .filter(value -> isWheeledBase(value.text())) + .map(ComponentSemantic::instanceId) + .collect(Collectors.toSet()); + Set connectedToBase = connectedInstanceIds(assembly, baseIds); + boolean hasConnectedUpper = components.stream().anyMatch(value -> !baseIds.contains(value.instanceId()) + && connectedToBase.contains(value.instanceId()) && isWheeledUpper(value.text())); + if (baseIds.isEmpty() || !hasConnectedUpper) { + return "轮式构型不完整:最终装配必须包含轮式底座和至少一个与底座连通的上装功能组件,不能只提交裸底座。请按用户描述补齐后重新模拟。"; + } + } + return ""; + } + + private boolean hasQuadrupedComponent(RobotAssemblyView assembly) { + return componentSemantics(assembly).stream().anyMatch(value -> isQuadrupedTorso(value.text()) + || isQuadrupedLeg(value.text())); + } + + private boolean hasWheeledBase(RobotAssemblyView assembly) { + return componentSemantics(assembly).stream().anyMatch(value -> isWheeledBase(value.text())); + } + + private List componentSemantics(RobotAssemblyView assembly) { + if (assembly == null || assembly.instances() == null) { + return List.of(); + } + Map catalog = new HashMap<>(); + return assembly.instances().stream() + .map(instance -> new ComponentSemantic(instance.instanceId(), semanticText(instance, catalog))) + .toList(); + } + + private String semanticText(RobotAssemblyComponentView instance, Map catalog) { + List values = new ArrayList<>(List.of( + safe(instance.name()), safe(instance.category()), safe(instance.robotType()), safe(instance.description()) + )); + if (StringUtils.hasText(instance.componentId())) { + Component component = catalog.computeIfAbsent(instance.componentId(), id -> { + try { + return componentMapper.selectById(Long.valueOf(id)); + } catch (RuntimeException exception) { + return null; + } + }); + if (component != null) { + ComponentAssemblyMetadata metadata = componentMetadata(component); + values.addAll(metadata.tags()); + values.addAll(metadata.capabilities()); + } + } + return normalize(String.join(" ", values)); + } + + private Set componentIds(List components, boolean torso) { + return components.stream() + .filter(value -> torso ? isQuadrupedTorso(value.text()) : isQuadrupedLeg(value.text())) + .map(ComponentSemantic::instanceId) + .collect(Collectors.toSet()); + } + + private Set connectedInstanceIds(RobotAssemblyView assembly, Set startingIds) { + if (startingIds.isEmpty()) { + return Set.of(); + } + Map> graph = new HashMap<>(); + if (assembly != null && assembly.connections() != null) { + for (RobotAssemblyConnectionView connection : assembly.connections()) { + graph.computeIfAbsent(connection.parentInstanceId(), ignored -> new ArrayList<>()) + .add(connection.childInstanceId()); + graph.computeIfAbsent(connection.childInstanceId(), ignored -> new ArrayList<>()) + .add(connection.parentInstanceId()); + } + } + Set visited = new HashSet<>(startingIds); + List pending = new ArrayList<>(startingIds); + for (int index = 0; index < pending.size(); index++) { + for (String neighbor : graph.getOrDefault(pending.get(index), List.of())) { + if (visited.add(neighbor)) { + pending.add(neighbor); + } + } + } + return visited; + } + + private static boolean isQuadrupedTorso(String text) { + return containsAny(text, "四足躯干", "quadruped torso") + || (containsAny(text, "四足", "quadruped") && containsAny(text, "躯干", "torso", "body")); + } + + private static boolean isQuadrupedLeg(String text) { + boolean leg = text.contains("腿") || text.matches(".*(?:\\blegs?\\b|[_-]legs?(?:[_-]|$)|legs?[_-]).*"); + boolean quadruped = containsAny(text, "四足", "quadruped"); + return leg && quadruped && !isQuadrupedTorso(text); + } + + private static boolean isWheeledBase(String text) { + return containsAny(text, "轮式底座", "轮式底盘", "小车底座", "wheeled base", "wheeled chassis") + || (containsAny(text, "轮式", "wheeled") && containsAny(text, "底座", "底盘", " base", "chassis")); + } + + private static boolean isWheeledUpper(String text) { + if (!StringUtils.hasText(text) || isWheeledBase(text) || isQuadrupedLeg(text)) { + return false; + } + return !containsAny(text, "轮组", "车轮", "轮子", "wheel module", "连接件", "转接件", "adapter", "connector"); + } + + private static boolean explicitQuadrupedException(String request) { + return request.matches(".*(?:只要|仅要|只生成|仅生成).{0,12}躯干.*") + || containsAny(request, "裸躯干", "不要腿", "不需要腿", "轮式运动模块", "轮腿", "四足轮式", + "局部子装配", "局部装配", "partial assembly", "bare torso", "without legs") + || request.matches(".*(?:只要|仅要|只生成|仅生成|只保留|仅保留).{0,12}(?:一|二|两|三|1|2|3)条腿.*") + || request.matches(".*(?:去掉|移除|减少|少).{0,8}(?:一|二|两|三|1|2|3)?条?腿.*") + || request.matches(".*(?:只测试|测试).{0,16}(?:腿|连接).*"); + } + + private static boolean explicitWheeledException(String request) { + return containsAny(request, "裸底座", "移除上装", "不要上装", "不需要上装") + || request.matches(".*(?:只要|仅要|只生成|仅生成|只处理|仅处理).{0,12}(?:底座|底盘).*"); + } + + private static boolean containsAny(String source, String... values) { + for (String value : values) { + if (source.contains(value)) { + return true; + } + } + return false; + } + + private static String normalize(String value) { + return safe(value).trim().toLowerCase(Locale.ROOT); + } + + private static boolean isExploratoryReply(String replyText) { + String normalized = normalize(replyText); + return normalized.matches("^(?:testing|trying|checking|test|try|check)\\b.*") + || normalized.matches("^(?:正在)?(?:测试|尝试|检查).*"); + } + private Component requireComponent(String rawId) { Component component = componentMapper.selectById(parseId(rawId)); if (component == null) { @@ -346,6 +523,12 @@ public class RobotAssemblyPlannerTools { public record Simulation(RobotAssemblyPlan plan, RobotAssemblyPlanSimulator.SimulationResult result) { } + private record CompletionRequirements(boolean quadruped, boolean wheeled) { + } + + private record ComponentSemantic(String instanceId, String text) { + } + public record ProposedPlan(String simulationId, RobotAssemblyPlan plan, RobotAssemblyPlanSimulator.SimulationResult simulation, @@ -354,12 +537,14 @@ public class RobotAssemblyPlannerTools { public static final class PlannerSession { private final RobotAssemblyView currentAssembly; + private final CompletionRequirements requirements; private final Map simulations = new LinkedHashMap<>(); private String lastSuccessfulSimulationId; private ProposedPlan proposedPlan; - private PlannerSession(RobotAssemblyView currentAssembly) { + private PlannerSession(RobotAssemblyView currentAssembly, CompletionRequirements requirements) { this.currentAssembly = currentAssembly; + this.requirements = requirements; } RobotAssemblyView currentAssembly() { @@ -370,6 +555,10 @@ public class RobotAssemblyPlannerTools { return simulations; } + private CompletionRequirements requirements() { + return requirements; + } + String lastSuccessfulSimulationId() { return lastSuccessfulSimulationId; } diff --git a/backend/src/main/resources/skills/robot-assembly-planner/v1/system-prompt.md b/backend/src/main/resources/skills/robot-assembly-planner/v1/system-prompt.md index 50ca790..74ce46d 100644 --- a/backend/src/main/resources/skills/robot-assembly-planner/v1/system-prompt.md +++ b/backend/src/main/resources/skills/robot-assembly-planner/v1/system-prompt.md @@ -5,11 +5,11 @@ Language requirement: every user-facing final response and every `replyText` val 构型识别优先于部位补全:先结合当前会话、当前装配、用户明确提到的构型以及组件名称/标签/描述判断构型,再套用对应的目标清单。优先级为当前会话和当前装配、用户明确构型、组件语义、通用规则;只有不同构型会导致不同拓扑且无法判断时才追问。明确的人形需求或已有的人形装配继续使用本提示中的人形规则;明确的四足或轮式构型不得套用人形默认部位。 构型规则: -- 四足构型由四足躯干和四个独立运动槽位组成:`front_left`、`front_right`、`rear_left`、`rear_right`。运动模块可以是腿或轮式模块,用户只要求替换运动模块时保留躯干及其他结构。 +- 用户需求或上下文明确定义为四足(包括明确出现“四足”或 quadruped)时,默认完成条件是最终装配同时具有一个四足躯干和四条腿,四条腿是连接到 `front_left`、`front_right`、`rear_left`、`rear_right` 四个运动槽位的独立实例。除非用户明确要求局部子装配、减少某条腿、裸躯干或用轮式运动模块替代腿,否则不得提交缺少四足躯干、少于四条腿或只有分散腿组件的结果。躯干和腿的具体型号、系列、尺寸及能力按用户描述匹配;描述模糊时选择最符合上下文且能形成完整四足构型的兼容组合。当前装配缺少默认部位时要在本轮补齐,用户只要求替换运动模块时保留躯干及其他结构。 - 四足腿优先匹配完整套装:如果候选名称或标签表明存在同一系列的前左、前右、后左、后右四个组件,并且接口和朝向可以分别对应四个槽位,就把四个组件作为一套分别安装。完整套装不能压缩成一个组件重复安装。 - 如果没有完整四腿套装,选择一条最合适的腿并创建四个独立实例,分别连接到四个槽位。四个实例使用不同 alias,并分别判断镜像和安装旋转;不能把不完整的三腿候选和另一型号自动混成一套。 - 四个腿位可以使用同一模型、成对模型或四个不同模型。名称中的 left/right/front/rear 只作为候选证据,必须结合接口和原始朝向分析决定镜像。 -- 轮式构型以小车底座为根,机械臂是可替换变体。“换机械臂”只断开并替换底座上的机械臂连接,保留底座和其他已有结构,不自动添加四足腿、四足躯干或人形部位。 +- 用户需求或上下文明确定义为轮式(包括明确出现“轮式”或 wheeled)时,默认完成条件是最终装配具有轮式底座,以及至少一个通过真实接口连接在底座上方的功能组件;不得只交付裸轮式底座。上装组件具体采用机械臂、躯干、人形上半身、载荷或其他类型,按用户描述匹配;描述模糊时选择最符合上下文且与底座兼容的上装组件。只有用户明确要求裸底座、移除上装或仅处理底座时才可省略上装。“换机械臂”只断开并替换底座上的机械臂连接,保留底座和其他已有结构,不自动添加四足腿、四足躯干或用户未要求的人形部位。 必须通过工具了解组件库、组件接口和当前装配。不要编造组件、接口、尺寸或连接标准;工具没有返回的能力视为不存在。你只能用 `simulate_assembly_plan` 成功模拟过的计划调用 `propose_assembly_plan`,并且必须使用最近一次成功模拟返回的 `simulationId`。 @@ -32,7 +32,7 @@ Language requirement: every user-facing final response and every `replyText` val 提交前按目标清单检查:底座、躯干、头部、左右肢体和末端等适用部位是否逐一落实,是否保留用户指定结构,是否存在遗漏末端、孤立实例、重复组件或未经检索便放弃的部位。先完成候选检索、替代选择和完整性检查,再模拟整套计划,不要先模拟一个残缺结构就提前提交。 -模拟失败时,根据原因更换候选、补充真实连接件或修正连接后重试。调用 `simulate_assembly_plan` 时必须同时提供最终 `replyText`;成功会直接形成提案并结束。只有兼容旧轨迹未提供 replyText 时才调用 `propose_assembly_plan`。独立完整组件或机器人可作为独立根组件;只有接入现有装配时才要求接口兼容。合理方案均失败时,才提交符合目标、能连成单根连通树的最大有效子结构。不得伪造组件、绕过模拟、删除原件却不替代,或将未连接零件算作已装配。 +模拟失败时,根据原因更换候选、补充真实连接件或修正连接后重试。`simulate_assembly_plan` 成功只代表临时结构校验通过,不会形成提案;必须使用其返回的最新 `simulationId` 调用 `propose_assembly_plan`,由后端再次检查构型完整性并验收。探测单个接口、单条腿或测试某个连接的中间计划不得提交,`Testing...`、`Trying...` 等测试文字不得作为最终 `replyText`。独立完整组件或机器人可作为独立根组件;只有接入现有装配时才要求接口兼容。合理方案均失败时,只有不受四足/轮式默认完成条件约束的需求才可提交符合目标、能连成单根连通树的最大有效子结构;四足或轮式默认构型无法完整实现时保留当前装配并如实说明,不得提交残缺构型。不得伪造组件、绕过模拟、删除原件却不替代,或将未连接零件算作已装配。 每次装配请求都以交付可用结果为目标:有可执行变更就必须完成模拟和提案,不能用文字方案代替工具执行。replyText 必须用 1~3 句简洁英文说明实际装配内容、补齐的关键部位和采用的替代件。有能力差异或未完成部位时说明实际影响,不解释组件资源情况。只有组件库为空、合理候选均无法通过接口校验或工具故障等确实不能形成有效变更时,才保留当前装配并如实说明未完成的改动。先说交付了什么,再说明实际限制,不以“没有”作为整段答复。 diff --git a/backend/src/main/resources/skills/robot-assembly-planner/v1/tools.json b/backend/src/main/resources/skills/robot-assembly-planner/v1/tools.json index 9a0dc99..884fb8d 100644 --- a/backend/src/main/resources/skills/robot-assembly-planner/v1/tools.json +++ b/backend/src/main/resources/skills/robot-assembly-planner/v1/tools.json @@ -118,7 +118,7 @@ "type": "function", "function": { "name": "simulate_assembly_plan", - "description": "在内存中应用并校验完整计划。成功且带 replyText 时直接形成提案;校验成功不代表需求完整性检查。", + "description": "在内存中应用并校验完整计划。成功结果仅是临时模拟,必须再用返回的 simulationId 调用 propose_assembly_plan;校验成功不代表需求完整性检查。", "parameters": { "type": "object", "properties": { @@ -280,15 +280,10 @@ ], "additionalProperties": false } - }, - "replyText": { - "type": "string", - "description": "最终用户回复:1~3 句简洁英文,说明实际结果、限制和未完成部分,不披露内部流程。" } }, "required": [ - "operations", - "replyText" + "operations" ], "additionalProperties": false } @@ -311,7 +306,8 @@ } }, "required": [ - "simulationId" + "simulationId", + "replyText" ], "additionalProperties": false } diff --git a/backend/src/test/java/com/robotquan/momatchengine/service/impl/DeepSeekRobotAssemblyPlannerTest.java b/backend/src/test/java/com/robotquan/momatchengine/service/impl/DeepSeekRobotAssemblyPlannerTest.java index 8ea0b5d..443c84c 100644 --- a/backend/src/test/java/com/robotquan/momatchengine/service/impl/DeepSeekRobotAssemblyPlannerTest.java +++ b/backend/src/test/java/com/robotquan/momatchengine/service/impl/DeepSeekRobotAssemblyPlannerTest.java @@ -27,6 +27,9 @@ class DeepSeekRobotAssemblyPlannerTest { assertThat(prompt).contains("四足构型", "轮式构型", "明确的人形需求"); assertThat(prompt).contains("front_left", "front_right", "rear_left", "rear_right"); assertThat(prompt).contains("完整套装", "四个独立实例"); + assertThat(prompt).contains("一个四足躯干和四条腿", "不得提交缺少四足躯干、少于四条腿"); + assertThat(prompt).contains("不得只交付裸轮式底座", "至少一个通过真实接口连接在底座上方的功能组件"); + assertThat(prompt).contains("具体型号、系列、尺寸及能力按用户描述匹配", "上装组件具体采用"); assertThat(prompt).contains("只断开并替换底座上的机械臂连接"); assertThat(prompt).contains("must use English only", "Never output Chinese characters"); } @@ -51,7 +54,7 @@ class DeepSeekRobotAssemblyPlannerTest { "rc_test", RobotAssemblyView.empty(), List.of(), "Replace the lower body with a wheeled chassis" )).isInstanceOfSatisfying(com.robotquan.momatchengine.common.exception.BizException.class, exception -> assertThat(exception.getCode()).isEqualTo("ROBOT_LLM_TOOL_LIMIT")); - assertThat(requests).hasValue(16); + assertThat(requests).hasValue(30); } diff --git a/backend/src/test/java/com/robotquan/momatchengine/service/impl/RobotAssemblyPlannerToolsTest.java b/backend/src/test/java/com/robotquan/momatchengine/service/impl/RobotAssemblyPlannerToolsTest.java index 3981eb7..bedd43e 100644 --- a/backend/src/test/java/com/robotquan/momatchengine/service/impl/RobotAssemblyPlannerToolsTest.java +++ b/backend/src/test/java/com/robotquan/momatchengine/service/impl/RobotAssemblyPlannerToolsTest.java @@ -7,7 +7,10 @@ import static org.mockito.Mockito.when; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.robotquan.momatchengine.dto.robot.RobotAssemblyComponentView; +import com.robotquan.momatchengine.dto.robot.RobotAssemblyConnectionView; import com.robotquan.momatchengine.dto.robot.RobotAssemblyPlan; +import com.robotquan.momatchengine.dto.robot.RobotAssemblyView; import com.robotquan.momatchengine.entity.Component; import com.robotquan.momatchengine.mapper.ComponentMapper; import java.util.List; @@ -73,7 +76,8 @@ class RobotAssemblyPlannerToolsTest { RobotAssemblyPlannerTools.ToolResult firstSimulation = tools.execute(session, "simulate_assembly_plan", plan); String firstId = firstSimulation.payload().path("simulationId").asText(); RobotAssemblyPlannerTools.ToolResult firstProposal = tools.execute(session, "propose_assembly_plan", json(Map.of( - "simulationId", firstId + "simulationId", firstId, + "replyText", "An arm was added." ))); RobotAssemblyPlannerTools.ToolResult secondSimulation = tools.execute(session, "simulate_assembly_plan", plan); String secondId = secondSimulation.payload().path("simulationId").asText(); @@ -98,26 +102,118 @@ class RobotAssemblyPlannerToolsTest { } @Test - void successfulSimulationCanCreateProposalWithoutAnotherModelRound() { + void successfulSimulationRemainsProvisionalUntilExplicitlyProposed() { Component arm = component(1L, "通用手臂", "手臂", List.of("手臂"), List.of("伸展"), 300); when(componentMapper.selectById(1L)).thenReturn(arm); RobotAssemblyPlannerTools.PlannerSession session = tools.openSession(null); - JsonNode arguments = json(Map.of( - "operations", List.of(Map.of( - "type", "ADD_INSTANCE", - "alias", "arm", - "componentId", "1" - )), - "replyText", "An arm was added." - )); + JsonNode arguments = json(new RobotAssemblyPlan(List.of( + RobotAssemblyPlan.PlanOperation.add("arm", "1") + ))); RobotAssemblyPlannerTools.ToolResult result = tools.execute(session, "simulate_assembly_plan", arguments); assertThat(result.success()).isTrue(); assertThat(result.payload().path("success").asBoolean()).isTrue(); - assertThat(result.payload().path("proposalAccepted").asBoolean()).isTrue(); + assertThat(result.payload().has("proposalAccepted")).isFalse(); + assertThat(session.proposedPlan()).isNull(); + } + + @Test + void rejectsExploratoryTextAsFinalProposalReply() { + Component arm = component(1L, "通用手臂", "手臂", List.of("手臂"), List.of("伸展"), 300); + when(componentMapper.selectById(1L)).thenReturn(arm); + RobotAssemblyPlannerTools.PlannerSession session = tools.openSession(null); + JsonNode plan = objectMapper.valueToTree(new RobotAssemblyPlan(List.of( + RobotAssemblyPlan.PlanOperation.add("arm", "1") + ))); + String simulationId = tools.execute(session, "simulate_assembly_plan", plan) + .payload().path("simulationId").asText(); + + RobotAssemblyPlannerTools.ToolResult result = tools.execute(session, "propose_assembly_plan", json(Map.of( + "simulationId", simulationId, + "replyText", "Testing R2 leg connection." + ))); + + assertThat(result.payload().path("accepted").asBoolean()).isFalse(); + assertThat(result.payload().path("reason").asText()).contains("测试或探测说明"); + assertThat(session.proposedPlan()).isNull(); + } + + @Test + void rejectsOneLegProbeAndAcceptsCompleteConnectedQuadruped() { + RobotAssemblyPlannerTools.PlannerSession session = tools.openSession(null, "生成四足探照变体机器人"); + RobotAssemblyView oneLeg = assembly( + List.of( + assemblyComponent("torso", "探照躯干", "torso", "quadruped"), + assemblyComponent("leg1", "宽足腿 R2", "right_leg", "quadruped") + ), + List.of(connection("torso", "leg1")) + ); + recordSimulation(session, "sim_one_leg", oneLeg); + + RobotAssemblyPlannerTools.ToolResult rejected = propose(session, "sim_one_leg"); + + assertThat(rejected.payload().path("accepted").asBoolean()).isFalse(); + assertThat(rejected.payload().path("reason").asText()).contains("四条独立腿", "1 条"); + assertThat(session.proposedPlan()).isNull(); + + RobotAssemblyView complete = assembly( + List.of( + assemblyComponent("torso", "探照躯干", "torso", "quadruped"), + assemblyComponent("leg1", "宽足腿 R1", "left_leg", "quadruped"), + assemblyComponent("leg2", "宽足腿 R2", "right_leg", "quadruped"), + assemblyComponent("leg3", "宽足腿 L1", "left_leg", "quadruped"), + assemblyComponent("leg4", "宽足腿 L2", "right_leg", "quadruped") + ), + List.of( + connection("torso", "leg1"), connection("torso", "leg2"), + connection("torso", "leg3"), connection("torso", "leg4") + ) + ); + recordSimulation(session, "sim_complete", complete); + + RobotAssemblyPlannerTools.ToolResult accepted = propose(session, "sim_complete"); + + assertThat(accepted.payload().path("accepted").asBoolean()).isTrue(); assertThat(session.proposedPlan()).isNotNull(); - assertThat(session.proposedPlan().replyText()).isEqualTo("An arm was added."); + } + + @Test + void rejectsBareWheeledBaseAndAcceptsConnectedUpperComponent() { + RobotAssemblyPlannerTools.PlannerSession session = tools.openSession(null, "生成轮式探照机器人"); + RobotAssemblyView bareBase = assembly( + List.of(assemblyComponent("base", "轮式底座", "chassis", "wheeled")), + List.of() + ); + recordSimulation(session, "sim_bare", bareBase); + + RobotAssemblyPlannerTools.ToolResult rejected = propose(session, "sim_bare"); + + assertThat(rejected.payload().path("accepted").asBoolean()).isFalse(); + assertThat(rejected.payload().path("reason").asText()).contains("上装功能组件"); + + RobotAssemblyView complete = assembly( + List.of( + assemblyComponent("base", "轮式底座", "chassis", "wheeled"), + assemblyComponent("light", "探照灯云台", "payload", "manipulator") + ), + List.of(connection("base", "light")) + ); + recordSimulation(session, "sim_with_upper", complete); + + assertThat(propose(session, "sim_with_upper").payload().path("accepted").asBoolean()).isTrue(); + } + + @Test + void allowsExplicitPartialQuadrupedTest() { + RobotAssemblyPlannerTools.PlannerSession session = tools.openSession(null, "只测试四足 R2 一条腿连接"); + RobotAssemblyView partial = assembly( + List.of(assemblyComponent("leg", "宽足腿 R2", "right_leg", "quadruped")), + List.of() + ); + recordSimulation(session, "sim_partial", partial); + + assertThat(propose(session, "sim_partial").payload().path("accepted").asBoolean()).isTrue(); } @Test @@ -161,4 +257,39 @@ class RobotAssemblyPlannerToolsTest { private JsonNode json(Object value) { return objectMapper.valueToTree(value); } + + private RobotAssemblyPlannerTools.ToolResult propose(RobotAssemblyPlannerTools.PlannerSession session, + String simulationId) { + return tools.execute(session, "propose_assembly_plan", json(Map.of( + "simulationId", simulationId, + "replyText", "The requested assembly was completed." + ))); + } + + private void recordSimulation(RobotAssemblyPlannerTools.PlannerSession session, + String simulationId, + RobotAssemblyView assembly) { + RobotAssemblyPlan plan = new RobotAssemblyPlan(List.of(RobotAssemblyPlan.PlanOperation.add("part", "1"))); + session.recordSuccessfulSimulation(simulationId, plan, + RobotAssemblyPlanSimulator.SimulationResult.success(assembly, Map.of())); + } + + private RobotAssemblyView assembly(List components, + List connections) { + return new RobotAssemblyView(components.getFirst().instanceId(), components, connections, 0L); + } + + private RobotAssemblyComponentView assemblyComponent(String instanceId, + String name, + String category, + String robotType) { + return new RobotAssemblyComponentView( + instanceId, null, name, "component", category, robotType, + "", "", name, List.of() + ); + } + + private RobotAssemblyConnectionView connection(String parentId, String childId) { + return new RobotAssemblyConnectionView(parentId, "mount_" + childId, childId, "root"); + } } diff --git a/frontend/docs/开发跟踪文档.md b/frontend/docs/开发跟踪文档.md index baae45c..f7ca724 100644 --- a/frontend/docs/开发跟踪文档.md +++ b/frontend/docs/开发跟踪文档.md @@ -1,3 +1,8 @@ +## 2026-09-24 拼装页管理员仿真入口 + +- `/assemble` 底部工具栏的仿真入口仅对 `userType=ADMIN` 的管理员显示,普通用户不渲染按钮;管理员点击后进入 `/simulation?robot=lekiwi-v1`。 +- 验证:`npm run build` 通过;仅保留项目原有的 CSS 顺序和资源体积告警。 + ## 2026-09-24 拼装页点击蓝色材质根因修复 - 实际主因:`handleSceneInstanceClick` 将同一个 `targetRef` 同时写入 selected 和 camera focus;`resolvePartHighlightState` 虽先取 selected,却又通过引用相等把它判成 camera focus 的 hover,最终 `InstanceHighlightOverlay` 写入 `0x2f65ff`。点击关节也会因所属零件 camera focus 单独映射为 hover 而染蓝。重启开发服务后依然复现,不能归因于缓存;交互代码处于异步 chunk,仅检查 `app.js` 不足以判断版本。 diff --git a/frontend/docs/开发需求文档.md b/frontend/docs/开发需求文档.md index 6aa5047..a208110 100644 --- a/frontend/docs/开发需求文档.md +++ b/frontend/docs/开发需求文档.md @@ -1,3 +1,7 @@ +## 2026-09-24 拼装页管理员仿真入口 + +- `/assemble` 底部工具栏的仿真图标仅向管理员(`userType=ADMIN`)显示,普通用户和未登录用户隐藏;管理员点击后进入 `/simulation?robot=lekiwi-v1`。 + ## 2026-09-24 拼装页点击保留模型材质 - `/assemble` 中鼠标点击模型后,先完成拾取再清除当前 hover 目标,防止悬停蓝色自发光在选中后保留;点击对象的属性选择、关节选择和拖拽操作保持不变。 diff --git a/frontend/src/components/assemble/AssembleAgentChatWorkspace.vue b/frontend/src/components/assemble/AssembleAgentChatWorkspace.vue index e9113ed..a665034 100644 --- a/frontend/src/components/assemble/AssembleAgentChatWorkspace.vue +++ b/frontend/src/components/assemble/AssembleAgentChatWorkspace.vue @@ -112,6 +112,16 @@ + + + + + +