缺陷 / 高 / Agent 引擎
electron/harness/prompts/context-builder.ts
ContextBuilder.estimateTokens 在估算 system prompt token 时,仅累加 tool.name + tool.description,忽略 tool.parameters:
tools.forEach(tool => { total += tool.name.length + tool.description.length; });
但 tool.parameters(JSON Schema)通常占工具 token 的 70%+:
tools.forEach(tool => { total += tool.name.length + tool.description.length; // 估算 parameters schema 的 token if (tool.parameters) { const schemaStr = JSON.stringify(tool.parameters); total += estimateTokens(schemaStr); // 使用同一估算器 } });
或调用统一的 estimateMessagesTokens,将 tools 作为 messages 的一部分。
文件: electron/harness/prompts/context-builder.ts
修复: estimateTokens 在工具定义循环中补充 tool.parameters(JSON Schema)的 token 估算。之前仅累加 name + description,导致工具 token 估算偏低 70%+。
estimateTokens
tool.parameters
name + description
验证: tsc --noEmit 类型检查通过。
tsc --noEmit
No dependencies set.
The note is not visible to the blocked user.
问题类型
缺陷 / 高 / Agent 引擎
文件位置
electron/harness/prompts/context-builder.ts问题描述
ContextBuilder.estimateTokens 在估算 system prompt token 时,仅累加 tool.name + tool.description,忽略 tool.parameters:
但 tool.parameters(JSON Schema)通常占工具 token 的 70%+:
影响
建议修复
或调用统一的 estimateMessagesTokens,将 tools 作为 messages 的一部分。
修复说明
文件:
electron/harness/prompts/context-builder.ts修复:
estimateTokens在工具定义循环中补充tool.parameters(JSON Schema)的 token 估算。之前仅累加name + description,导致工具 token 估算偏低 70%+。验证:
tsc --noEmit类型检查通过。