ToolTweak: An Attack on Tool Selection in LLM-based Agents

Jonathan Sneh, Ruomei Yan, Jialin Yu, Philip Torr, Yarin Gal, Sunando Sengupta, Eric Sommerlade, Alasdair Paren, Adel Bibi

TL;DR

As Large Language Models (LLMs) transition into autonomous agents, they increasingly rely on natural language metadata to select external tools and APIs from marketplaces. This paper exposes a critical vulnerability in this setup: an automatic, black-box attack called ToolTweak that iteratively manipulates tool names and descriptions to trick agents into prioritizing a specific tool. The attack successfully inflates tool selection rates from a 20% baseline up to 81%, revealing a new frontier of adversarial "Search Engine Optimization" (SEO) that threatens the fairness and security of agentic ecosystems.

What Problem Does This Paper Address?

LLM-based agents are evolving from simple chatbots into active systems capable of booking flights, managing finances, and querying databases via external APIs. Frameworks like the Model Context Protocol (MCP) are giving rise to vast tool marketplaces where agents autonomously choose the best tool for a user's request.

To make this choice, the agent reads the tool's natural language metadata—its name and description. The authors identify a glaring gap in this design: because LLMs rely entirely on surface-level, unverified text, the selection process is highly vulnerable to manipulation. An adversary can subtly optimize a tool's description to systematically bias the agent's behavior, gaining an unfair competitive advantage or routing sensitive user traffic through malicious APIs.

Figure 1: ToolTweak: Adversarial Manipulation of Tool Selection. Illustration of ToolTweak, an adversarial attack that iteratively refines a tool’s name and description using LLM feedback to maximize its likelihood of being selected. The figure shows how benign tool selection is distributed across multiple options, whereas after ToolTweak interventions, the targeted tool, renamed Best- Weather, dominates selection rates.

Methods

The authors introduce ToolTweak, a lightweight, gradient-free, black-box adversarial attack designed to maximize a target tool's selection rate.

  1. The Optimization Loop: Inspired by the PAIR jailbreaking algorithm, ToolTweak uses an attacker LLM to iteratively refine the target tool's name and description.
  2. Quantitative Feedback: Instead of using a subjective LLM judge, ToolTweak evaluates the modified tool against a victim agent across a set of user queries. It calculates a concrete metric: the Selection Rate (SR).
  3. Refinement: The attacker LLM receives the tool's history and current selection rate, using this feedback to generate a more persuasive iteration. The process runs for $K=10$ iterations, mimicking real-world A/B testing.

The paper also evaluates two potential defenses:

  • Paraphrasing: Instructing the victim LLM to rewrite all tool descriptions in an objective, neutral style before making a selection.
  • Perplexity Filtering: Using a lightweight model (GPT-2 Large) to detect and filter out unnaturally optimized or manipulative text based on perplexity scores.

Datasets

The evaluation dataset was constructed using ToolBench, a repository of real-world APIs. The authors selected a subset covering 10 diverse tasks (including geocoding, weather forecasting, sentiment analysis, and email validation). For each task, they picked 5 functionally similar APIs and generated 100 user queries to test the selection distribution.

Key Insights and Ideas

  • Adversarial SEO for AI: ToolTweak demonstrates that malicious actors do not need internal access to an LLM's weights to hijack its traffic. Simple text adjustments act like black-hat SEO, distorting how agents distribute their API calls.
  • Names Matter Immensely: While prior work focused almost exclusively on appending suffixes to descriptions, ToolTweak shows that tool names heavily influence selection. Adding subtle ordinality (e.g., "Tool 1" vs "Tool 2") or authoritative branding strongly biases the model.
  • The "Self-Bias" Effect: The authors observed that the most effective attack on a specific model is often the one generated by that model itself, suggesting LLMs harbor an inherent preference for their own textual style.
  • Reward Hacking Behavior: In an amusing twist of adaptiveness, the attacker LLM (specifically Gemini) occasionally attempted to "reward hack" the evaluation by straight-up copying the exact names of its top competitors.

Key Results

ToolTweak achieved massive, cross-model success, proving highly transferable between open-source and proprietary systems.

  • Selection Rate Spikes: From a uniform baseline of roughly 20% (1 out of 5 tools), ToolTweak boosted target selection rates to 81.6% for DeepSeek-Chat, 73.6% for GPT-OSS, and 45.9% for Qwen2.5.
  • Transferability: Attacks optimized on one model successfully fooled others. For instance, the DeepSeek agent proved highly vulnerable, consistently selecting targeted tools roughly 60% of the time, regardless of which LLM generated the attack text.
Figure 2: Average Normalized Improvement for all tools on all six models
  • Defense Efficacy: The paraphrasing defense successfully mitigated basic manual suffix attacks, bringing selection rates back down toward the 20% baseline. However, ToolTweak proved robust, maintaining elevated selection rates even against defended agents. Perplexity filtering alone failed because adversarial text perplexity heavily overlapped with benign text, though combining text length and perplexity showed promise for building classifiers.

Limitations and Future Work

The primary limitation acknowledged by the authors is that their experiments operated on a fixed pool of 5 tools per task. In massive real-world applications, agents first use vector-embedding-based retrieval systems to narrow down thousands of tools to a small candidate set.

Future work should explore how adversarial metadata manipulation affects this initial retrieval stage. Additionally, investigating white-box, gradient-based optimization methods could reveal even more potent variations of this vulnerability.

Summary updated

BibTeX
@misc{sneh2025tooltweak,
  author = {Jonathan Sneh and Ruomei Yan and Jialin Yu and Philip Torr and Yarin Gal and Sunando Sengupta and Eric Sommerlade and Alasdair Paren and Adel Bibi},
  title = {{ToolTweak: An Attack on Tool Selection in LLM-based Agents}},
  year = {2025},
  eprint = {2510.02554},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.02554},
}
Figure