Sample record. This work is fictional demonstration content. Results, people and institutions are placeholders; references in full-text articles are real publications.
Highlights
- Tool selection is cast as retrieval conditioned on the evolving task state.
- A two-stage selector cuts prompt length by 87% with a 2.1-point loss versus an oracle.
- State-conditioned retrieval accounts for most of the improvement over instruction-only retrieval.
- Overlapping tool descriptions remain the dominant failure mode.
Abstract
Language agents that act through external tools are limited by the size of their prompt: listing hundreds of tool descriptions crowds out the task and degrades accuracy. We study tool selection as a retrieval problem and propose a two-stage selector that (i) retrieves a short list of candidate tools using an embedding of the evolving task state and (ii) lets the model re-rank candidates with a single constrained call. Across a synthetic suite of 4,000 tools and three long-horizon task families, the selector keeps task success within 2.1 points of an oracle that sees only the correct tools, while reducing prompt length by 87%. Ablations show that conditioning retrieval on the task state, rather than on the initial instruction alone, accounts for most of the gain. We discuss failure cases, including tools with overlapping descriptions, and release the evaluation harness.
Keywords language agents · tool use · retrieval · long-horizon tasks · prompt compression
1.Introduction
Language models can now call external tools such as search engines, code interpreters, calendars and databases [1, 2]. In practice the number of available tools grows quickly: an enterprise assistant may expose thousands of functions through an API gateway. The common approach of placing every tool description in the prompt does not scale, since long prompts raise latency and cost and, as we show, reduce the accuracy with which the right tool is chosen.
We therefore ask whether tool selection can be treated as retrieval, as is done for documents in retrieval-augmented generation [3, 4]. Two properties of agentic tasks make this harder than document retrieval. First, the information need changes as the agent proceeds: the tool needed at step 12 is rarely implied by the initial instruction. Second, tools are used, not read, so a near-miss is costly.
Our contributions are as follows:
- a formulation of tool selection as retrieval conditioned on the evolving task state;
- a two-stage selector combining dense retrieval with a constrained model re-rank;
- an evaluation harness with 4,000 synthetic tools and three task families, released with this article.
3.Method
Let T = {t₁, …, tₙ} be the tool set, where each tool tⱼ has a natural-language description dⱼ. At step k the agent has a task state sₖ consisting of the instruction, a short summary of previous actions and the most recent observation.
Stage 1: state-conditioned retrieval
We embed the state and each description with the same encoder and score tools by cosine similarity. The shortlist Cₖ contains the top m tools:
Stage 2: constrained re-ranking
The model receives only the shortlist and must output the identifier of one tool or the token NONE. Because the output space is restricted to |Cₖ|+1 symbols, we decode with a constrained grammar, which removes invalid tool names. The full procedure is summarised below.
def select_tool(state, tools, encoder, model, m=8):
q = encoder(state.summary())
shortlist = top_k(tools, key=lambda t: cosine(q, t.embedding), k=m)
return model.choose(state, options=shortlist + [NONE], constrained=True)The training objective for the encoder is a contrastive loss over (state, correct tool) pairs, with the other shortlisted tools as hard negatives [4].
4.Experiments
Setup
We generate 4,000 tools with natural-language descriptions, grouped into 120 families with deliberately overlapping descriptions, and three task families (data analysis, scheduling and document workflows) with 8 to 40 steps each. Each configuration is run with five seeds. We compare against (a) all tools in the prompt, (b) instruction-only retrieval, and (c) an oracle that is shown only the correct tools.
Results
Table 1 reports task success. State-conditioned selection is within 2.1 points of the oracle, and substantially better than instruction-only retrieval. Figure 1 shows that the advantage grows with the number of available tools: with all tools in the prompt, success falls steadily, whereas the selector stays nearly flat.
| Method | Analysis | Scheduling | Documents | Prompt tokens |
|---|---|---|---|---|
| All tools in prompt | 27.4 | 31.0 | 24.2 | 212k |
| Instruction-only retrieval | 57.2 | 60.3 | 52.8 | 3.1k |
| State-conditioned (ours) | 74.1 | 76.8 | 72.5 | 3.4k |
| Oracle (correct tools only) | 76.0 | 78.9 | 74.6 | 2.9k |
Prompt tokens are the average prompt length per step.
- All tools in prompt
- Instruction-only retrieval
- State-conditioned (ours)
Ablations
Removing the re-ranking stage lowers success by 3.4 points, and shrinking the shortlist from 8 to 3 candidates lowers it by 5.2 points, mostly through missed retrievals. Using the instruction alone as the query reduces success by 8.9 points on the longest tasks.
5.Discussion and limitations
The dominant failure mode is confusion between tools in the same family: when two descriptions differ only in a parameter, both retrieval and re-ranking select the wrong one in 31% of failures. Better descriptions, or retrieval over usage examples, are plausible remedies. Our tools are synthetic, and real APIs contain noisier documentation; the results should be read as controlled evidence about the selection mechanism, not as a deployment estimate.
6.Conclusion
Treating tool selection as state-conditioned retrieval lets agents work with very large tool sets at a fraction of the prompt cost. We release the harness so that selection can be evaluated in isolation from the rest of the agent.
Declarations
- Author contributions
- L.H. and T.I. contributed equally to the methodology; M.T. built the evaluation harness. L.H. wrote the manuscript with input from all authors.
- Funding
- Sample article – no funding to declare.
- Competing interests
- The authors declare no competing interests.
- Data and code availability
- The evaluation harness and synthetic tool set are described in the article. Sample article. All results, names and affiliations in this demonstration article are synthetic placeholders.
- Acknowledgements
- We thank the anonymous reviewers for their detailed comments.
References
- [1]Schick, T., Dwivedi-Yu, J., Dessì, R., Raileanu, R., Lomeli, M., Hambro, E., Zettlemoyer, L., Cancedda, N., Scialom, T. (2023). Toolformer: Language models can teach themselves to use tools. Advances in Neural Information Processing Systems, 36. arXiv:2302.04761
- [2]Yao, S., Zhao, J., Yu, D., Du, N., Shafran, I., Narasimhan, K., Cao, Y. (2023). ReAct: Synergizing reasoning and acting in language models. International Conference on Learning Representations. arXiv:2210.03629
- [3]Lewis, P., Perez, E., Piktus, A., Petroni, F., Karpukhin, V., Goyal, N., et al. (2020). Retrieval-augmented generation for knowledge-intensive NLP tasks. Advances in Neural Information Processing Systems, 33. arXiv:2005.11401
- [4]Karpukhin, V., Oğuz, B., Min, S., Lewis, P., Wu, L., Edunov, S., Chen, D., Yih, W.-t. (2020). Dense passage retrieval for open-domain question answering. Proceedings of EMNLP, 6769–6781. arXiv:2004.04906
- [5]Liu, X., Yu, H., Zhang, H., Xu, Y., et al. (2024). AgentBench: Evaluating LLMs as agents. International Conference on Learning Representations. arXiv:2308.03688
Peer review
Open reports from independent reviewers. See how outcomes are determined.
- Status
- Peer reviewed
- Requested
- 12 Nov 2025
- Completed
- 9 Feb 2026
- Report identity
- Signed reports
Reports on version 1
- Approved with reservations
Dr. Henrik Solberg
A clearly written study that treats tool selection as retrieval over an evolving state. The core claim is plausible and the effect size is large, but the evaluation relies entirely on synthetic tools.
Strengths
- The state-conditioned query is a simple, well-motivated idea.
- Ablations isolate the contribution of each stage.
Concerns
- Synthetic tool descriptions may be easier to separate than real API documentation.
- Variance across seeds is not reported for the end-to-end success rates.
Authors' response
We added results on a registry of 600 real API descriptions (Section 4.3) and report standard deviations over five seeds in all tables.
- Approved
Prof. Amara Okeke
The paper makes a focused contribution and the released harness will be useful. Claims are proportionate to the evidence.
Strengths
- Honest discussion of overlapping tool descriptions.
- Harness and tool registry are released.
Concerns
- The oracle upper bound could be described in more detail.
Authors' response
Thank you. We expanded the oracle description in Section 4.1.
Reports on version 2Current version
- Approved
Dr. Henrik Solberg
The new real-API experiments and variance reporting address my main concerns. The conclusions now follow from the evidence.
Strengths
- Real-API results show the same trend as synthetic ones.
Concerns
- Minor: Figure 2 uses the same marker for two series.
- Approved
Dr. Linh Tran
I reviewed version 2 only. The method, evaluation and limitations are sound and clearly presented.
Strengths
- Clear threat-to-validity discussion.
- Reproducible setup.
Concerns
- None that affect the conclusions.
Versions
Version 2 · 27 February 2026Latest
Revised after review: real-API evaluation, variance reporting, oracle description.
10.xxxx/ctm.pb.2026.0001.v2
Version 1 · 10 November 2025
Posted; peer review requested.
10.xxxx/ctm.pb.2026.0001.v1
How to cite
Hartwell, L., Ibarra, T., & Tan, M. (2026). Retrieval-Augmented Tool Selection for Long-Horizon Language Agents. CONTINUUM Publishing, CTM-PB-2026-0001. doi:10.xxxx/ctm.pb.2026.0001
© 2026 The authors. Published by AEX CONTINUUM under the CC BY 4.0 licence.