From 2ea93a391b3fca603dfcce2e9be6f0e0623c6ea3 Mon Sep 17 00:00:00 2001 From: Rin Date: Thu, 15 Jan 2026 03:26:29 +0800 Subject: [PATCH] refactor(minecraft): chat as tools to prevent scheme mismatch --- .../src/cognitive/action/task-executor.ts | 32 +++++++++++++++---- .../conscious/prompts/brain-prompt.ts | 2 +- services/minecraft/src/utils/errors.ts | 1 + 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/services/minecraft/src/cognitive/action/task-executor.ts b/services/minecraft/src/cognitive/action/task-executor.ts index 902a220c9..0bef14b2e 100644 --- a/services/minecraft/src/cognitive/action/task-executor.ts +++ b/services/minecraft/src/cognitive/action/task-executor.ts @@ -113,18 +113,36 @@ export class TaskExecutor extends EventEmitter { try { let result: string | void if (action.type === 'sequential' || action.type === 'parallel') { - if (action.type === 'parallel') { - const available = this.actionAgent.getAvailableActions() - const def = available.find(a => a.name === action.step.tool) - if (!def || def.execution !== 'parallel') { - throw new ActionError('UNKNOWN', `Tool '${action.step.tool}' is not allowed for parallel actions`, { + if (action.step.tool === 'chat') { + const message = (action.step.params as any)?.message + if (typeof message !== 'string' || message.trim().length === 0) + throw new Error('Invalid chat tool params: expected params.message to be a non-empty string') + + if (action.type === 'parallel') { + throw new ActionError('SYNC_ONLY', 'Tool \'chat\' is not allowed for parallel actions', { tool: action.step.tool, requestedExecution: action.type, - allowedExecution: def?.execution, + allowedExecution: 'sequential', }) } + + await this.chatAgent.sendMessage(message) + result = 'Message sent' + } + else { + if (action.type === 'parallel') { + const available = this.actionAgent.getAvailableActions() + const def = available.find(a => a.name === action.step.tool) + if (!def || def.execution !== 'parallel') { + throw new ActionError('UNKNOWN', `Tool '${action.step.tool}' is not allowed for parallel actions`, { + tool: action.step.tool, + requestedExecution: action.type, + allowedExecution: def?.execution, + }) + } + } + result = await this.actionAgent.performAction(action.step) } - result = await this.actionAgent.performAction(action.step) } else if (action.type === 'chat') { await this.chatAgent.sendMessage(action.message) diff --git a/services/minecraft/src/cognitive/conscious/prompts/brain-prompt.ts b/services/minecraft/src/cognitive/conscious/prompts/brain-prompt.ts index 40b925fab..c3dad32fc 100644 --- a/services/minecraft/src/cognitive/conscious/prompts/brain-prompt.ts +++ b/services/minecraft/src/cognitive/conscious/prompts/brain-prompt.ts @@ -78,7 +78,7 @@ Output format: "executionStrategy": "Short-term plan if any." }, "actions": [ - {"type":"chat","message":"...","require_feedback": false}, + {"type":"sequential","step":{"tool":"chat","params":{"message":"..."}},"require_feedback": false}, {"type":"parallel","step":{"tool":"action name","params":{...}},"require_feedback": true}, {"type":"sequential","step":{"tool":"action name","params":{...}},"require_feedback": false} ] diff --git a/services/minecraft/src/utils/errors.ts b/services/minecraft/src/utils/errors.ts index d67c0d406..ddb4da364 100644 --- a/services/minecraft/src/utils/errors.ts +++ b/services/minecraft/src/utils/errors.ts @@ -9,6 +9,7 @@ export type ActionErrorCode | 'ITEM_NOT_FOUND' | 'PLACEMENT_FAILED' | 'ACTIVATION_FAILED' + | 'SYNC_ONLY' export class ActionError extends Error { public readonly code: ActionErrorCode