diff --git a/src/bot/index.js b/src/bot/index.js index a9e2b3c4..6085cfbc 100644 --- a/src/bot/index.js +++ b/src/bot/index.js @@ -426,7 +426,20 @@ export async function initBot(config, api, tools, skills, agents) { if (!handler) { result = `❌ Unknown tool: ${fn.name}`; } else { - const args = JSON.parse(fn.arguments || '{}'); + let args; + try { + args = JSON.parse(fn.arguments || '{}'); + } catch (parseErr) { + // Tool call JSON was truncated (common with large file content in file_write) + const argLen = (fn.arguments || '').length; + result = `❌ ${fn.name} failed: Tool call arguments JSON was truncated (${argLen} chars). ` + + (fn.name === 'file_write' + ? 'The file content is too large for a single tool call. Use bash with heredoc instead: bash({ command: "cat > /path/to/file << \'EOF\'\\ncontent here\\nEOF" })' + : 'Retry with shorter arguments or split into smaller calls.'); + logger.error(` → ${fn.name} failed: ${parseErr.message} (args length: ${argLen})`); + loopMessages.push({ role: 'tool', tool_call_id: tc.id, content: result }); + continue; + } logger.info(` → ${fn.name}(${fn.arguments?.slice(0, 100)})`); result = String(await handler(args)).slice(0, 8000); }