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).
Figures & tables
Figure 1: Comparison of the two discovery architectures. Left (RtP) : the user query is embedded directly and matched against the tool registry via vector search; the top- k results are passed to the LLM planner. Right (PtR) : the LLM first generates a draft plan with imaginary tool stubs, whose embeddings are used to query the registry; the matched real tools are returned to the planner for final execution planning.
Figure 2: Complexity-dependent crossover. (a) Both recall (solid) and precision (dashed) flip from RtP-dominant on G1 to PtR-dominant on G2/G3. (b) Per-query recall win/loss counts: RtP wins more queries on G1 (63 vs. 33); PtR wins more on G2 (69 vs. 30).
G1
G2
G3
k
RtP
PtR
RtP
PtR
RtP
PtR
1
.161
.127
.065
.079
.054
.075
3
.307
.223
.110
.148
.105
.139
5
.372
.279
.143
.184
.160
.177
10
.453
.356
.186
.234
.217
.229
20
.524
.444
.229
.295
.288
.299
Table 1: Recall at varying retrieval budget k . Bold : better architecture. Crossover holds at every k . Statistical significance of the RtP–PtR difference at k=5 is reported in Table 3 .
Figure 3: Recall and tool selection divergence vs. registry size. Shaded bands show ± std across 5 random seeds; the full-registry point (46,984 APIs) uses a single deterministic run. G1 (RtP advantage) and G2 (PtR advantage) recall curves are both shown; divergence grows monotonically with registry size.
Figure 4: Agent trajectory divergence across subsets: (a) selection rate = fraction of retrieved APIs the planner uses; (b) plan complexity = mean intended steps and APIs named; (c) Jaccard overlap of planner-selected API sets across architectures; (d) planner behavior when retrieval completely misses all Ground-Truth APIs; (e) trajectory fidelity = fraction of planner selections drawn from the retrieved set.
Query
PtR Stub(s)
Ground-Truth API
PtR R
RtP R
RtP wins: query contains the API name directly
“latest news about crime in Germany”
news_article_search_api
German Police and Crime News Live
0.00
1.00
“programming memes from Reddit”
reddit_api_client
Programming Memes Reddit/Get All
0.00
1.00
“electricity bill PLN analysis”
get_postpaid_pln_bill_details
Cek ID PLN/Get Data Tagihan
0.00
1.00
“Testing out Sharing w/ Rachael”
api_specification_retriever
Testing out Sharing w/ Rachael
0.00
1.00
PtR wins: query describes a capability; stubs bridge the semantic gap
Table 2: Representative queries illustrating the dual role of stub hallucination. Top : RtP achieves perfect recall when the query contains the API name directly; PtR’s generic stub abstracts away this signal and retrieves the wrong API. Bottom : PtR achieves higher recall when the query describes a functional need; stubs decompose multi-faceted intent into targeted sub-queries that RtP’s single embedding cannot match. “Ground-Truth API” is the ToolBench gold API for that query.
RtP
PtR
Subset
Metric
Mean
± Std
Mean
± Std
p
G1 ( n=200 )
Pass Rate
0.884
0.015
0.840
0.024
0.022∗
Precision
0.274
−
0.209
0.008
<0.001∗∗∗
Recall
0.372
−
0.289
0.010
0.002∗∗
G2 ( n=200 )
Pass Rate
0.747
0.015
0.855
0.020
<0.001∗∗∗
Precision
0.167
−
0.204
0.007
0.039∗
Table 3: Retrieval metrics by subset (4 independent runs each). RtP precision and recall are deterministic (no run-to-run variance; reported without std). p -values: one-sample t -test for precision/recall (PtR’s 4-run mean vs. deterministic RtP); two-sample t -test for pass rate. Bold : best mean per metric. ∗∗p<0.01 , ∗∗∗p<0.001 , n.s. = not significant.
Subset
Gen.%
Stubs/q
Unique%
Match%
Cos
G1
98.5%
2.1
98.6%
40.6%
0.874 (correct) / 0.872 (incorrect)
G2
99.5%
2.4
93.6%
38.3%
0.843 / 0.840
G3
100%
2.5
79.1%
24.8%
0.858 / 0.854
Table 4: Stub generation statistics by subset. Gen.% : fraction of queries generating stubs. Stubs/q : mean stubs per query. Unique% : fraction of stub names unique across queries. Match% : fraction of stubs whose top-1 matched API is in Ground-Truth. Cos : mean cosine similarity of stub to its top-1 match (virtually identical for correct vs. incorrect matches).
Subset
Stubs/q
PtR eff. width
RtP eff. width
Budget-equiv. k
RtP recall
G1
2.1
≈10
5
10
0.453
G2
2.4
≈12
5
10
0.186
G3
2.5
≈13
5
10
0.217
Table 5: Effective search width at k=5 . RtP searches exactly k candidates; PtR searches k× Stubs/q (union, deduped) then returns top- k . Budget-equivalent RtP recall from Table 1 .
Metric
Arch.
G1
G2
G3
Selection rate
PtR
28.6%
28.2%
26.8%
RtP
26.7%
21.2%
22.4%
Jaccard (selected)
both
0.40
0.29
0.28
Plan steps
PtR
3.8
3.9
4.1
RtP
3.5
3.7
3.6
Fidelity
PtR
98.8%
97.8%
98.5%
Table 6: Trajectory divergence metrics. Selection rate = fraction of retrieved APIs the planner uses. Jaccard = similarity of planner-selected API sets. Fidelity = fraction of planner selections drawn from the retrieved set.
Subset
n
Identical
Divergent
G1
200
2.5%
97.5%
G2
200
1.0%
99.0%
G3
100
0.0%
100.0%
Table 7: Tool selection divergence: fraction of queries where the two architectures retrieve different top- k API sets.
RtP
PtR
Overhead
Δ R
G1
∼226
∼396
+75%
−0.072
G2
∼238
∼429
+80%
+0.042
G3
∼221
∼450
+104%
+0.017
Table 8: Inference cost and recall benefit of PtR over RtP. The sign of Δ R matches the crossover in Table 3 , where the G1 and G2 recall differences are statistically significant ( p<0.01 ) and G3 is not.
Query
PtR Stub
RtP Retrieved (correct)
“crime news in Germany”
news_search_api
German Police and Crime News Live
“programming memes, Reddit”
reddit_api_client
Programming Memes Reddit/Get All Memes
“PLN electricity bill”
get_pln_bill_details
Cek ID PLN/Get Data Tagihan
“Testing out Sharing w/ Rachael”
api_spec_retriever
Testing out Sharing w/ Rachael/Input test
Table 9: Stub-hallucination examples: PtR’s over-generic stubs miss niche APIs that RtP matches directly.
G1 Recall
G2 Recall
Registry size
RtP
PtR
RtP
PtR
Div%
1,000
.646±.001
.586±.004
.339±.000
.366±.000
88.4±0.0
2,000
.603±.004
.544±.009
.300±.006
.336±.005
89.2±1.2
5,000
.536±.008
.470±.012
.249±.003
.294±.004
92.5±1.1
10,000
.484±.002
.414±.008
.215±.005
.260±.003
94.1±1.2
20,000
.430±.002
.357±.003
.184±.003
.226±.003
95.6±0.8
Table 10: Scaling study: RtP vs. PtR recall by registry size for the G1 (RtP-advantage) and G2 (PtR-advantage) subsets, with G1 tool-selection divergence ( ± std across 5 random seeds; full registry has no randomness). Bold marks the better architecture per subset: the crossover (RtP > PtR on G1, PtR > RtP on G2) holds at every registry size. The full-registry recall gaps are statistically significant on both subsets (Table 3 ). G2’s Ground-Truth set (1,048 APIs) exceeds the 1k target, so the smallest G2 point is gold-only (no distractors, zero variance).
Precision
Recall
Pass Rate
Subset
RtP
PtR
RtP
PtR
RtP
PtR
G1
0.274
0.186±0.006∗∗∗
0.372
0.259±0.012∗∗∗
0.855±0.018
0.786±0.024∗∗
G2
0.168
0.207±0.004∗∗∗
0.143
0.194±0.003∗∗∗
0.826±0.029
0.820±0.029n.s.
G3
0.135
0.123±0.008n.s.
0.160
0.146±0.008∗
0.790±0.008
0.805±0.013n.s.
Table 11: gpt-oss-120b replication (mean ± std, 4 runs). RtP precision and recall are deterministic. Bold : better architecture (by mean). Superscripts on PtR values denote significance of the PtR–RtP difference (one-sample t -test vs. deterministic RtP for precision/recall; two-sample for pass rate): ∗p<0.05 , ∗∗p<0.01 , ∗∗∗p<0.001 , n.s. = not significant. The G1 (RtP) and G2 (PtR) crossover replicates and is significant on precision and recall; on G3 the differences are small and the recall gap weakly reverses toward RtP, indicating G3 behavior is model-dependent.