Source-linked AI summary

Plan or Retrieve First? A Scale Study of Tool Discovery Architectures

Mingfei Zhang, Amit Surana, Ziauddin Majid, Chenxi Wang, Michael Xu

arXiv:2610.19068v1cs.AIcs.IR

TL;DR

Tool-augmented agents must find relevant APIs in large registries despite tight context limits, and evidence comparing retrieval paradigms has been limited. This paper compares direct query retrieval with retrieval guided by generated tool stubs, finding that which approach performs better depends on query complexity. It also identifies a scope boundary: the evaluation uses ToolBench gold trajectories as a retrieval proxy rather than assessing final answer quality.

  • Problem

    Tool agents face tight context limits in large API registries, while direct query retrieval assumes user intent is close enough to API documentation for embeddings to bridge the gap.

    Source: §1 · p. 1
  • Method

    The paper compares RtP, which retrieves from the raw query, with PtR, which generates hypothetical tool stubs as retrieval queries, in a controlled paradigm study.

    Source: §1 · p. 2
  • Results

    RtP leads on single-tool queries, while PtR leads on intra-category multi-tool queries and directionally on cross-category queries; this crossover holds across retrieval budgets and registry sizes.

    Source: §5 · p. 7
  • Takeaways & Limitations

    Routing single-tool queries to RtP and multi-tool queries to PtR reduces discovery-call overhead by approximately 36% with no retrieval-quality loss.

    Source: §1 · p. 2

    The evaluation uses ToolBench gold trajectories as a retrieval proxy and does not assess parameter correctness or final answer quality.

    Source: Limitations · pp. 7–8

Abstract

from arXiv · show

Tool-augmented LLM agents discover relevant APIs from large registries before planning execution, yet finite context windows prohibit injecting all tool definitions into a single prompt. The dominant approach, which we term Retrieve-then-Plan (RtP), embeds the user query and retrieves similar tools via approximate nearest-neighbor search. We study an alternative Plan-then-Retrieve (PtR) paradigm in which the LLM first generates Abstract Tool Stubs (hypothesized function signatures describing needed capabilities) which then serve as retrieval queries against the registry. Evaluating on ToolBench (46,984 unique API endpoints, 50 categories) across single-tool (G1), intra-category multi-tool (G2), and cross-category multi-tool (G3) query subsets, we find a clear complexity-dependent crossover: RtP outperforms PtR on single-tool queries while PtR outperforms RtP on multi-tool queries. This crossover holds at every retrieval budget (k=1 to 20), is robust across registry sizes from 1k to 47k APIs, and is consistent across model families (Gemini 2.5 Flash and gpt-oss-120b). We characterize a stub-hallucination failure mode (the LLM invents plausible but non-existent API names) that acts as a double-edged sword: on simple queries PtR's stubs abstract away proper-noun signals that RtP matches directly, yet on complex queries the same mechanism decomposes multi-faceted intent into functional sub-needs. We further analyze token overhead and show that PtR's extra discovery call roughly doubles inference cost, which pays off on multi-tool queries but hurts on single-tool ones, motivating complexity-adaptive routing as a practical direction, one that can be driven by a zero-cost signal already present in the pipeline (RtP's top-1 retrieval score).

1 Introduction

Tool retrieval under context constraints is dominated by Retrieve-then-Plan, but the comparison with Plan-then-Retrieve has remained unexplored. This paper compares the paradigms at scale and reports a complexity-dependent crossover, with implications for routing queries between them.

1 Introduction

  • Tool-augmented agents retrieve APIs under tight context constraints, and direct query embedding assumes user intent is close enough to API documentation for semantic search to bridge the gap.Prior work reports that this assumption often fails, motivating LLM-generated reformulations or plans before retrieval.Source: §1 · p. 1
  • Prior work includes query rewriting, synthetic-query enrichment, decompose-then-select benchmarking, and efforts to treat stub hallucination as a bug (Ma et al., 2025).The paper instead reports that stub hallucination can be useful on complex queries.Source: §1 · p. 1
  • The paper identifies a gap: prior work had not compared retrieval paradigms in a controlled large-registry setting or characterized how their trade-off changes with query complexity.The closest prior work, TOOLQP (Fang and Glass, 2026), uses trained, multiround query reformulations rather than zero-shot hypothetical function signatures.Source: §1 · p. 2
  • The paper compares Retrieve-then-Plan (RtP) with Plan-then-Retrieve (PtR), which generates Abstract Tool Stubs as retrieval queries in a zero-shot call without training.It characterizes stub hallucination as a dual mechanism and reports a complexity-dependent crossover robust to retrieval budget, registry size, and model family.Source: §1 · p. 2

2 Method

The study compares controlled RtP and PtR instantiations over the same ToolBench registry and infrastructure. It evaluates retrieval against gold API sets across three query subsets, using fixed-budget recall and precision as retrieval measures and pass rate as an additional outcome.

2.1 Architectures

  • RtP retrieves top-k APIs by matching the embedded raw query to tool documentation, while PtR generates hypothetical tool stubs, retrieves and reranks their matched APIs, then plans with that set.Both use GTE-base embeddings, a FAISS flat index over 46,984 deduplicated ToolBench endpoints, and Gemini 2.5 Flash; retrieval budget is k=5.Source: §2.1 · pp. 2–3

2.2 Data and Metrics

  • ToolBench evaluation uses G1 single-tool (n=200), G2 intra-category multi-tool (n=200), and G3 cross-category multi-tool (n=100) subsets, with retrieval measured against gold-trajectory APIs.Recall and precision are reported at k=5; PtR and pass rate are averaged over four runs, while deterministic RtP retrieval has no run-to-run variance.Source: §2.2 · p. 3
  • The evaluation uses gold trajectories as a retrieval proxy because planners select from retrieved APIs at least 96% of the time, but it does not assess parameter correctness or final answer quality.An unfiltered baseline is infeasible because ToolBench categories include thousands of APIs and fixed-size truncation usually misses gold APIs.Source: §2.2 · p. 3, §2.1 · p. 3

3 Results

The main result is a complexity-dependent crossover: RtP leads on single-tool queries, while PtR leads on intra-category multi-tool queries and has a directional advantage on cross-category queries. The crossover persists across retrieval budgets and registry sizes, while retrieval differences largely constrain the planner’s intended behavior.

3.1 Main Results

  • G1 recall favors RtP (0.372 vs. 0.289±0.010), while G2 recall favors PtR (0.188±0.007 vs. 0.143); G3 recall favors PtR directionally (0.172±0.008 vs. 0.160).The G3 recall difference is not significant; G1 and G2 pass-rate results also favor RtP and PtR, respectively, while G3 pass rate favors PtR.Source: §3.1 · p. 4

3.2 Scaling Behavior

  • PtR’s G2 recall advantage grows from +0.014 at k=1 to +0.066 at k=20, while the crossover holds across retrieval budgets and registry sizes from 1k to 47k APIs.Across registry sizes, recall degrades for both architectures but their G1 and G2 advantages persist; tool-selection divergence rises from 88% to 98%.Source: §3.1 · p. 4, §3.2 · p. 4

3.3 Agent Trajectory Divergence

  • Trajectory fidelity is at least 96% across subsets, indicating that planners almost always select from retrieved tools; selected-tool Jaccard similarity falls from 0.40 on G1 to 0.28 on G3.On G3, PtR plans average 4.1 intended steps and 1.4 APIs named versus RtP’s 3.6 steps and 1.1 APIs; RtP refuses more often on G2 (47% vs. 27%).Source: §3.3 · pp. 4–5

4 Discussion

The retrieval paradigms cross over with query complexity: RtP benefits from direct API-name signals on simple queries, while PtR decomposes multi-faceted intent on complex ones. PtR’s broader retrieval can help multi-tool queries, but its discovery call adds token and latency costs.

4.1 Why the Crossover Occurs

  • G2 recall advantage grows from +0.014 at k=1 to +0.066 at k=20 as PtR’s 2.4–2.5 stubs retrieve candidates for distinct functional sub-needs.G2 queries require a mean of 6.5 Ground-Truth APIs, compared with 5.2 on G1; at equal search width, RtP’s G2 recall is nearly identical, but its larger output halves precision.Source: §4.1 · p. 5

4.2 Stub Hallucination: The Mechanism

  • PtR generates 79–99% unique stub names, and multi-stub coverage can favor G3 even though only 24.8% of G3 stubs match a relevant API.Correct and incorrect stub matches have virtually identical cosine similarity, such as 0.874 versus 0.872 on G1, leaving the embedding space unable to distinguish good routing from bad.Source: §4.2 · p. 5

4.3 Discovery as the Binding Constraint

  • At least 96% trajectory fidelity shows planners almost always select retrieved APIs; on G3, PtR produces plans averaging 4.1 intended steps versus 3.6 for RtP.Figure 4 also tracks selection rate, plan complexity, cross-architecture Jaccard overlap, behavior after retrieval misses all Ground-Truth APIs, and trajectory fidelity.Source: §4.3 · p. 6, Figure 4 · p. 6
  • PtR adds ∼75–104% token overhead and one sequential LLM round-trip; routing G1 to RtP and G2/G3 to PtR saves ∼16% of inference tokens without retrieval-quality loss.The discovery call changes recall by −0.072 on G1 and +0.042 on G2; for queries requiring 12+ APIs, iterative discovery may be necessary regardless of architecture.Source: §4.3 · pp. 6–7

5 Conclusion

In a controlled comparison at 50k-API scale, RtP performs better on single-tool queries while PtR performs better on multi-tool queries. The crossover persists across retrieval budgets, registry sizes, and a second model family, motivating complexity-adaptive routing.

5 Conclusion

  • RtP wins on single-tool queries, while PtR leads on G2 recall by +0.045 (p<0.001, n=200) and directionally on G3 recall by +0.012 (n=100; not individually significant).The crossover holds across k=1–20 and registry sizes of 1k–47k APIs, and its directions replicate with gpt-oss-120b.Source: §5 · p. 7
  • Stub hallucination can erase direct API-name signals on simple queries yet decompose multi-faceted intent on complex ones.The conclusion characterizes this as a double-edged effect of stub hallucination.Source: §5 · p. 7
  • At least 96% trajectory fidelity makes retrieval the binding constraint, and complexity-adaptive routing reduces discovery-call overhead by ∼36% without retrieval-quality loss.The proposed routing sends single-tool queries to RtP and multi-tool queries to PtR.Source: §5 · p. 7

Limitations

The study isolates retrieval paradigm in a controlled ToolBench setting, but generalization to other registry types remains unvalidated. Its retrieval proxy does not assess parameter correctness or final-answer quality, and wall-clock latency depends on serving infrastructure.

Limitations

  • The comparison holds planner, embedding model, and benchmark fixed to Gemini 2.5 Flash, GTE-base, and ToolBench; generalization to differently named registries remains to be validated.An initial gpt-oss-120b replication confirms crossover directions across model families, not across registry types.Source: Limitations · p. 7
  • ToolBench gold trajectories serve as a retrieval proxy, so parameter correctness and final-answer quality are not assessed; wall-clock latency depends on serving infrastructure.PtR’s sequential discovery and retrieval calls add one LLM round-trip before planning begins.Source: Limitations · pp. 7–8

A Full Retrieval Metrics Table

Across subsets, RtP leads the retrieval metrics on G1 while PtR leads on G2 and G3. Stub statistics show frequent novel names and little embedding separation between correct and incorrect matches; at k=5, PtR searches a wider candidate pool, and trajectory metrics are computed on paired scorable queries.

A Full Retrieval Metrics Table

  • RtP leads pass rate, retrieval precision, and retrieval recall on G1, while PtR leads all three metrics on G2 and G3.Pass rate is supplementary; the main text focuses on precision and recall as primary retrieval metrics.Source: A Full Retrieval Metrics Table · p. 10

B Stub Generation Statistics

  • Stub names are 79–99% unique, while correct and incorrect matches have virtually identical cosine similarities of 0.874 and 0.872.The statistics indicate stubs are hallucinated from scratch and embeddings do not distinguish good routing from bad.Source: B Stub Generation Statistics · p. 10
  • At k=5, PtR searches ∼2–2.5× more candidates than RtP before returning the top-k set to the planner.Table 5 defines PtR’s effective width as k×Stubs/q, using a deduplicated union; its caption also reports budget-equivalent RtP recall from Table 1.Source: B Stub Generation Statistics · p. 10, Table 5 · p. 10

C Trajectory Analysis Detail

  • Trajectory divergence metrics are computed over paired queries with scorable responses from both architectures.Table 6 defines selection rate as the fraction of retrieved APIs used, Jaccard as overlap of selected API sets, and fidelity as selections drawn from the retrieved set.Source: C Trajectory Analysis Detail · p. 11, Table 6 · p. 11

D Tool Selection Divergence

Tool selection divergence rises with query complexity, reaching complete non-overlap on G3. Among divergent queries, RtP wins more often on G1, while PtR wins more often on G2.

E Inference Cost Analysis

PtR’s discovery call adds token cost that benefits G2 recall but hurts G1; examples show that abstracting away a brand can eliminate a direct retrieval match.

E Inference Cost Analysis

F Stub-Hallucination Examples

G PtR Win Examples (G1, G2, G3)

Examples illustrate how PtR’s stubs can retrieve tools for functional needs that direct query embeddings miss, including multi-tool and cross-category requests.

G PtR Win Examples (G1, G2, G3)

H G2/G3 RtP Win Examples

Examples show cases where RtP’s direct query match beats PtR’s over-generalized or misdirected stubs; the appendices describe scaling, model replication, prompts, and index configuration.

H G2/G3 RtP Win Examples

  • For a Greece energy-news query, RtP matches “Greek” and “Energy” and reaches recall 0.5, while PtR’s general-news and football stubs reach 0.0.Source: H G2/G3 RtP Win Examples · p. 12

I Scaling Study Details

H G2/G3 RtP Win Examples

  • For a New York craft-brewery query, RtP matches “brewery” and reaches recall 0.5, while PtR’s wrong decomposition reaches 0.0.Source: H G2/G3 RtP Win Examples · p. 13

J Model Generalization: gpt-oss-120b Replication

K Prompts

  • The zero-shot discovery prompt elicits abstract tool stubs from the query alone; the planner prompt selects APIs from the retrieved set.Source: K Prompts · p. 14

L FAISS Index Configuration

  • The index embeds each API’s tool name, API name, and description with 768-dimensional, L2-normalized GTE-base vectors for exact inner-product search.Source: L FAISS Index Configuration · p. 14
Loading 2610.19068v1…