← Back to Blog

Tool Retrieval in the Gemini API: Tool Selection as a Retrieval Problem

Tool Retrieval in the Gemini API: Tool Selection as a Retrieval Problem

Your agent doesn't need all 200 tool schemas in every request.

This week Google shipped Tool Retrieval for the Gemini API (preview): instead of attaching every tool definition to each call, the API selects the relevant subset per query. Token usage drops, and the model stops choosing between dozens of near-identical schemas.

The interesting part is that this is RAG applied to tool definitions. Embeddings over chunks solved the same problem for documents a while ago. Tool schemas are just another source of context bloat.

If you are not on Gemini, the pattern is portable:

  • Embed your tool descriptions and store them in a vector index
  • Per user query, retrieve the top-k tools and attach only those
  • If the right tool is missing, retry with broader retrieval or fall back to the full list

Two details decide whether it works:

  • Tool descriptions become retrieval documents. Write them so search queries can hit them, not like internal comments.
  • Watch for collisions. Two tools with similar names and purposes will compete in the same index, and the wrong one will win silently.

My rule of thumb: below roughly 20 tools, just send them all. Past that, treat tool selection as a retrieval problem with its own evaluation, the same way you treat chunk retrieval.

Fewer tokens is the visible win. The bigger one is accuracy: a model picking from 10 relevant tools fails far less than one picking from 200.

Sources

← Back to Blog