用注意力机制动态选工具,大幅减少大模型调用外部工具的开销。
Tool Attention Is All You Need: Dynamic Tool Gating and Lazy Schema Loading for Eliminating the MCP/Tools Tax in Scalable Agentic Workflows
- 通过工具注意力机制,按需加载工具描述,避免冗余注入。
- 实测每轮工具调用tokens从4.73万降至2400,上下文利用率从24%提至91%。
- 适合需要高效调用大量工具的智能体系统开发者,尤其关注成本与性能平衡者。
模型上下文协议(MCP)已成为连接大语言模型代理与外部工具的通用接口,但其依赖无状态、即时注入工具模式,带来每轮约1万至6万tokens的隐性开销,即‘工具税’。该开销导致键值缓存膨胀,当上下文利用率接近70%时引发推理质量下降,并使令牌预算成为持续运营成本。本文提出工具注意力(Tool Attention),将‘注意力就是一切’范式从词元自注意力扩展至工具门控注意力。该机制结合(i)基于句子嵌入的意图模式重叠度评分,(ii)考虑状态的门控函数以确保前置条件与访问范围,以及(iii)两阶段惰性工具加载器,仅在上下文中保留紧凑摘要池,对前k个被选工具才加载完整JSON schema。我们在一个模拟120工具、6服务器的基准上评估,各服务器令牌数根据真实MCP部署审计校准。结果表明,工具注意力将每轮工具相关令牌量降低95.0%(47.3k → 2.4k),有效上下文利用率从24%提升至91%。任务成功率、延迟、成本与推理质量为基于测量令牌数与公开部署数据推算的投影值,非直接测量。整体结果支持核心论点:协议级效率,而非单纯上下文长度,是可扩展智能体系统的瓶颈所在。代码已开源于https://github.com/asadani/tool-attention。
原文摘要 · Abstract (English)
The Model Context Protocol (MCP) has become a common interface for connecting large language model (LLM) agents to external tools, but its reliance on stateless, eager schema injection imposes a hidden per-turn overhead the MCP Tax or Tools Tax that practitioner reports place between roughly 10k and 60k tokens in typical multi-server deployments. This payload inflates the key-value cache, is associated with reasoning degradation as context utilization approaches published fracture points around 70%, and turns token budgets into a recurring operational cost. We introduce Tool Attention, a middleware-layer mechanism that generalizes the "Attention Is All You Need" paradigm from self-attention over tokens to gated attention over tools. Tool Attention combines (i) an Intent Schema Overlap (ISO) score from sentence embeddings, (ii) a state-aware gating function enforcing preconditions and access scopes, and (iii) a two-phase lazy schema loader that keeps a compact summary pool in context and promotes full JSON schemas only for top-k gated tools. We evaluate on a simulated 120-tool, six-server benchmark whose per-server token counts are calibrated to public audits of real MCP deployments. In this simulation, Tool Attention directly reduces measured per-turn tool tokens by 95.0% (47.3k -> 2.4k) and raises effective context utilization (a token-ratio quantity) from 24% to 91%. End-to-end figures for task success, latency, cost, and reasoning quality are reported as projections derived from the measured token counts combined with published deployment telemetry; they are not measured on live LLM agents, and we mark projected values explicitly throughout. Taken together, the results support a simple thesis: protocol-level efficiency, not raw context length, is a binding constraint on scalable gentic systems. The code for this work is accessible at https://github.com/asadani/tool-attention
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。