fix: 工具执行 IPC 卡死问题 — 多层超时保护
问题:确认工具操作后 Agent Loop 卡死在'正在思考中',工具未执行。 修复: - tool-registry.ts: executeTool() 新增 25 秒 IPC 硬超时 - agent-engine.ts: executeTool 内部 .catch 捕获异常,防止 reject 逃逸 - ipc.ts: tool:execute handler 外层 try-catch 确保始终返回响应 - 全链路添加 console.log 便于排查
This commit is contained in:
@@ -283,9 +283,16 @@ export async function runAgentLoop(
|
||||
try {
|
||||
// 工具执行超时保护
|
||||
console.log('[AgentEngine] 执行工具:', call.function.name);
|
||||
logInfo(`执行工具: ${call.function.name}`, JSON.stringify(call.function.arguments));
|
||||
const result = await Promise.race([
|
||||
executeTool(call.function.name, call.function.arguments),
|
||||
new Promise<never>((_, reject) =>
|
||||
executeTool(call.function.name, call.function.arguments).then(r => {
|
||||
console.log('[AgentEngine] executeTool resolve:', call.function.name, r);
|
||||
return r;
|
||||
}).catch(err => {
|
||||
console.error('[AgentEngine] executeTool reject:', call.function.name, err);
|
||||
return { success: false, error: err?.message || String(err) } as ToolResult;
|
||||
}),
|
||||
new Promise<ToolResult>((_, reject) =>
|
||||
setTimeout(() => reject(new Error('工具执行超时(30秒)')), TOOL_EXEC_TIMEOUT)
|
||||
)
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user