发现语言模型中工具选择可用单一方向表示,可提前干预或检测错误。
Tool Calling is Linearly Readable and Steerable in Language Models

- 工具选择由激活空间中的特定方向决定,添加该方向即可切换所选工具。
- 在15个工具的合成测试中准确率达83%-100%,真实API测试中达77%-94%。
- 适用于需高可靠性工具调用的场景,如智能代理、自动化系统等。
当工具调用代理选错工具时,失败直到执行才暴露:邮件已发送,会议已错过。随着代理承担关键操作,一次错误的工具调用可能造成实际损害。目前我们无法在模型内部提前发现此类错误;本文表明,可以做到。在模型内部,工具选择由激活空间中的单一方向承载,每对工具对应一个方向。生成过程中加入该方向可切换模型所选工具。在12个指令微调和6个基础模型(Gemma 3、Qwen 3、Qwen 2.5、Llama 3.1,参数量270M至27B)上,40亿以上参数的模型在15工具合成基准上准确率达83%-100%,在真实API基准τ- bench airline上达77%-94%。后续的JSON参数自动适配新工具模式,仅改名称即可。相同的方向还能提前预警错误:模型在两个工具间犹豫的查询,失败率比确定情况高21倍(Gemma 3 27B)。这并非单纯主题注入:同量级随机向量切换率为0%;单一领域内14个共享主题的航空工具,在五款40亿至140亿模型上仍能以61%-89%的准确率读取将调用的工具。即使基础模型在输出前已具备正确工具表示:通过余弦读出其内部状态,在BFCL上可恢复61%-82%准确率,而原始生成仅2%-10%,说明预训练已形成表征,指令微调则将其与输出对接。研究覆盖单轮固定菜单场景;多轮代理循环中干预效果不稳定(与基线相比增减最高达30个百分点,无一致方向)。
原文摘要 · Abstract (English)
When a tool-calling agent picks the wrong tool, the failure is invisible until execution: the email gets sent, the meeting gets missed. As agents take on consequential actions, one bad tool call can do real damage. We currently have no way to look inside the model and catch the mistake before it happens; this paper shows that we can. Inside the model, the choice of tool is carried by a single direction in activation space, one direction per pair of tools. Adding that direction during generation switches which tool the model picks. Across 12 instruction-tuned and 6 base models spanning Gemma 3, Qwen 3, Qwen 2.5, and Llama 3.1 (270M to 27B), this works at 83-100% accuracy on 4B+ instruction-tuned models on a 15-tool synthetic benchmark and at 77-94% on the real-API benchmark $τ$-bench airline. The JSON arguments that follow automatically adapt to the new tool's schema, so flipping the name is enough. The same per-tool directions also flag likely errors before they happen: queries where the model is unsure between two tools fail 21x more often than queries where it is not (Gemma 3 27B). This is not just topic injection: random vectors at the same magnitude give a 0% switch rate, and a probe within a single domain (14 airline tools that share one topic) still reads which tool the model will call at top-1 61-89% across five 4B-14B models. Even base models already carry the right tool internally before they can emit it: reading the chosen tool off the model's internal state (cosine readout) recovers 61-82% accuracy on BFCL while base generation lands at 2-10%, suggesting pretraining forms the representation and instruction tuning later wires it to the output. Our results cover single-turn, fixed-menu settings; on multi-turn agent loops the same intervention is less stable (matched-baseline gain or loss of up to 30 percentage points with no consistent direction).
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。