refactor(minecraft): chat as tools to prevent scheme mismatch

This commit is contained in:
Rin
2026-02-18 11:12:05 +08:00
committed by Neko Ayaka
parent 6ff248c959
commit 2ea93a391b
3 changed files with 27 additions and 8 deletions
@@ -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)
@@ -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}
]
+1
View File
@@ -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