【Bug已解决】openclaw tool call timeout / Function execution exceeded limit — OpenClaw 工具调用超时解决方案 【Bug已解决】openclaw: tool call timeout / Function execution exceeded limit — OpenClaw 工具调用超时解决方案1. 问题描述OpenClaw 在执行工具调用时超时# 工具调用超时 $ openclaw --auto-approve 运行 npm install Error: Tool call timeout npm install exceeded 30000ms limit. # 或命令执行超时 $ openclaw --auto-approve 运行测试 Error: Command timeout npm test exceeded 60000ms. # 或文件操作超时 $ openclaw --auto-approve 分析大文件 Error: File operation timeout Reading large_file.js exceeded 30000ms. # 或 MCP 工具超时 $ openclaw 使用搜索工具 Error: MCP tool timeout Tool code_search did not respond in 30000ms.这个问题在以下场景中特别常见命令执行时间过长npm install、测试大文件读取网络请求慢MCP 工具响应慢默认超时过小系统资源不足2. 原因分析原因分类表原因分类具体表现占比命令执行长npm install约 35%大文件读取 10MB约 25%默认超时小30s约 20%MCP 慢工具约 10%网络请求慢约 5%资源不足CPU/内存约 5%3. 解决方案方案一增加超时最推荐# 步骤 1增加工具超时 export OPENCLAW_TOOL_TIMEOUT120000 # 120 秒 # 步骤 2永久设置 echo export OPENCLAW_TOOL_TIMEOUT120000 ~/.bashrc source ~/.bashrc # 步骤 3或在配置中设置 cat .openclaw/config.json EOF { toolTimeout: 120000 } EOF # 步骤 4验证 openclaw --auto-approve 运行 npm install方案二分步执行长命令# 步骤 1拆分长命令 openclaw --auto-approve 运行 npm install --prefer-offline # 步骤 2或先安装依赖 npm install # 手动先执行 openclaw --auto-approve 运行 npm test # 步骤 3使用更快命令 openclaw --auto-approve 运行 npm test -- --bail # 步骤 4验证 openclaw --auto-approve 运行 echo hello方案三预处理大文件# 步骤 1分块读取 head -n 200 large_file.js /tmp/preview.js openclaw --auto-approve 分析 /tmp/preview.js # 步骤 2使用 grep 过滤 grep function large_file.js /tmp/functions.txt openclaw --auto-approve 分析 /tmp/functions.txt # 步骤 3使用 wc 检查大小 wc -l large_file.js # 步骤 4验证 openclaw --auto-approve 分析 /tmp/preview.js方案四使用 --max-turns 控制# 步骤 1限制轮次 openclaw --auto-approve --max-turns 5 task # 步骤 2分步执行 openclaw --auto-approve --max-turns 3 第一步 openclaw --auto-approve --max-turns 3 第二步 # 步骤 3避免长任务 # 不要让 OpenClaw 执行可能很长的命令 # 步骤 4验证 openclaw --auto-approve --max-turns 1 echo hello方案五增加 MCP 超时# 步骤 1增加 MCP 超时 cat .openclaw/mcp_config.json EOF { servers: { code-search: { timeout: 60000 } } } EOF # 步骤 2或环境变量 export OPENCLAW_MCP_TIMEOUT60000 # 步骤 3验证 python3 -m json.tool .openclaw/mcp_config.json openclaw 使用搜索工具 # 步骤 4验证 openclaw --mcp-status方案六手动执行命令# 步骤 1手动执行长命令 npm install # 手动执行 npm test # 手动执行 # 步骤 2让 OpenClaw 分析结果 openclaw --print 分析 npm test 的输出: $(cat test-results.txt) # 步骤 3或让 OpenClaw 只做分析 openclaw 分析 test-results.txt # 步骤 4验证 openclaw --print hello4. 各方案对比总结方案适用场景推荐指数难度方案一增加超时通用⭐⭐⭐⭐⭐低方案二分步命令长命令⭐⭐⭐⭐⭐低方案三预处理大文件⭐⭐⭐⭐⭐低方案四--max-turns控制⭐⭐⭐⭐低方案五MCP 超时MCP⭐⭐⭐⭐低方案六手动执行长任务⭐⭐⭐⭐⭐低5. 常见问题 FAQ5.1 默认工具超时多少通常 30 秒。通过OPENCLAW_TOOL_TIMEOUT调整。5.2 如何增加超时export OPENCLAW_TOOL_TIMEOUT120000 # 120 秒5.3 npm install 超时增加超时或手动执行npm install。5.4 大文件读取超时使用head -n 200或grep预处理。5.5 MCP 工具超时在 mcp_config.json 中设置timeout: 60000。5.6 如何分步执行拆分长任务为多个小任务使用--max-turns 5。5.7 --max-turns 有什么用限制工具调用轮次避免长时间执行。5.8 手动执行命令先手动执行长命令让 OpenClaw 只分析结果。5.9 如何在配置中设置{toolTimeout: 120000}5.10 排查清单速查表□ 1. OPENCLAW_TOOL_TIMEOUT120000 □ 2. config.json: toolTimeout 120000 □ 3. 分步执行长命令 □ 4. npm install 手动执行 □ 5. head -n 200 预处理大文件 □ 6. grep 过滤大文件 □ 7. --max-turns 5 限制轮次 □ 8. OPENCLAW_MCP_TIMEOUT60000 □ 9. mcp_config.json: timeout 60000 □ 10. 手动执行 分析结果6. 总结根本原因工具调用超时最常见原因是命令执行过长35%和大文件读取25%最佳实践使用export OPENCLAW_TOOL_TIMEOUT120000增加超时分步执行拆分长命令使用--max-turns 5限制轮次预处理大文件head -n 200或grep过滤后再读取最佳实践建议手动执行长命令npm install让 OpenClaw 只分析结果故障排查流程图flowchart TD A[工具调用超时] -- B[增加超时] B -- C[OPENCLAW_TOOL_TIMEOUT120000] C -- D[openclaw 验证] D -- E{成功?} E --|是| F[✅ 问题解决] E --|否| G{是命令超时?} G --|是| H[分步执行] G --|否| I{是大文件?} H -- j[手动执行长命令] j -- K[openclaw 分析结果] K -- F I --|是| L[预处理文件] L -- M[head -n 200 过滤] M -- N[openclaw 分析 /tmp/preview] N -- F I --|否| O{是 MCP?} O --|是| P[增加 MCP 超时] P -- Q[OPENCLAW_MCP_TIMEOUT60000] Q -- D O --|否| R[使用 --max-turns] R -- S[--max-turns 5 限制轮次] S -- D D -- T{成功?} T --|是| F T --|否| U[在配置中设置] U -- V[config.json: toolTimeout 120000] V -- D F -- W[长期: 超时 分步 预处理] W -- X[✅ 长期方案]