Free · Daily brief + weekly playbookDaily 60-sec AI Voice Brief + Weekly Production AI Agent PlaybookGet the brief →
ReleaseAPI / Product · ActionableApple ML Research→ original

Apple: Planning Before API Retrieval Doubles the Cost but Wins on Complex Tasks

An agent may have tens of thousands of APIs, but a prompt can only fit a few descriptions, so the right tools have to be selected in advance. Apple compared two methods: searching APIs by the text of the query, or letting the model first sketch the functions it needs and searching by those sketches. For a single tool, plain search is better. For a chain of several tools, sketching wins, but it adds an extra LLM call and doubles the price. Choose the scheme based on how complex the query is.

AI-processed from Apple ML Research; edited by Hamidun News
Apple: Planning Before API Retrieval Doubles the Cost but Wins on Complex Tasks
Source: Apple ML Research. Collage: Hamidun News.
Listen to article
Article Fact Sheet & Key Figures
ParameterDetails
Primary sourceApple ML Research ↗
Editor-in-Chief
Tested on ToolBench46,984 APIs across 50 categories
Key metric #2The result is the same for Gemini 2.5 Flash and gpt-oss-120b
Key metric #3The switch is the top-1 confidence score of plain retrieval

Imagine an agent connected to tens of thousands of APIs: exchange rates, email, booking, maps. The descriptions of all these functions won't fit into one prompt, so a few relevant ones have to be selected before the work begins. Apple researchers tested two orders of operations on a real set of 46,984 APIs and found that for simple queries plain search works better, while for complex ones planning first is the better choice. However, planning roughly doubles the inference cost, meaning the expense of running the model. Let's look at how this works and what to do in practice.

Two Orders of Operations

The standard approach the authors call Retrieve-then-Plan (RtP): "find first, then plan." The user's query is turned into a vector, the registry is searched for the closest API descriptions by meaning, and only those are shown to the model during planning. It is fast and cheap: one search, one LLM call.

The alternative is Plan-then-Retrieve (PtR): "plan first, then search." Without looking at the registry, the model writes "tool stubs" (Abstract Tool Stubs): sketches of function signatures it thinks it will need. The simplest way to picture this is a shopping list before a trip to the store: "need a function that gets an exchange rate; need a function that sends an email." Each such sketch then serves as a search query against the registry.

The test was run on ToolBench: 46,984 unique APIs across 50 categories. The queries were split into three groups: one tool (G1), several tools from one category (G2), and several tools from different categories (G3).

Where Each Approach Wins

The result depends on query complexity. For tasks with one tool, plain search works better. For tasks with several tools, planning ahead wins. This held for any number of retrieved tools (from 1 to 20), for registry sizes from 1 thousand to 47 thousand APIs, and on two models: Gemini 2.5 Flash and gpt-oss-120b.

The explanation is tied to hallucinations. When drafting sketches, the model invents plausible but nonexistent API names. For a simple query this hurts: such a query often contains a proper noun, such as a service name, and plain search finds it by direct match, while the sketch "erases" that name into an abstract function description. For a complex query the same technique helps: the model breaks a vague "organize a trip for me" into separate needs like "find tickets," "book a hotel," "calculate a route," and each one is found by its own search.

What It Costs and What to Do

PtR requires an extra LLM call at the retrieval stage, which roughly doubles the inference cost. On queries with several tools the extra cost pays off in quality; on queries with one tool it does not: you pay twice for a result that is worse.

The authors' practical conclusion is adaptive routing, that is, choosing the scheme for each query. It does not need a separate classifier: the signal is already in the pipeline. It is the similarity score of the best result (top-1) from plain search. If the best candidate matched the query confidently, the query is most likely simple and RtP is sufficient. If there is no confident match, the query is probably compound, and it is worth enabling planning. Nothing extra needs to be computed.

What this means for those building agents:

  • Don't pick a single tool-retrieval scheme for the whole product; look at the mix of queries;
  • If most traffic consists of simple calls to a single API, the expensive planning stage will only increase the bill;
  • If the agent assembles chains across several services, function sketches pay off;
  • Check that the model isn't slipping nonexistent APIs into the sketches: registry search filters out fabrications, but they can still degrade selection.

Limitations

The description of the study gives no ready-made threshold for routing: the top-1 score value at which to switch will have to be tuned on your own data. There is one benchmark (ToolBench) and two models, so on closed enterprise registries with different names and descriptions the picture may shift. Finally, "twice as expensive" refers to the additional call at the retrieval stage. The real difference in the bill depends on the length of the descriptions and the model's price.

Still, the work offers rare engineering specifics for this topic: two clear options, a measured cost, and a cheap way to choose between them on the fly.

Story

Key Questions Answered

What are the key details on Two Orders of Operations?

The standard approach the authors call Retrieve-then-Plan (RtP): "find first, then plan." The user's query is turned into a vector, the registry is searched for the closest API descriptions by meaning, and only those are shown to the model during planning. It is fast and cheap: one search, one LLM call. The alternative is Plan-then-Retrieve (PtR): "plan first, then search." Without looking at the registry, the model writes "tool stubs" (Abstract Tool Stubs): sketches of function signatures it thinks it will need.

Where Each Approach Wins?

The result depends on query complexity. For tasks with one tool, plain search works better. For tasks with several tools, planning ahead wins. This held for any number of retrieved tools (from 1 to 20), for registry sizes from 1 thousand to 47 thousand APIs, and on two models: Gemini 2.5 Flash and gpt-oss-120b. The explanation is tied to hallucinations. When drafting sketches, the model invents plausible but nonexistent API names.

What It Costs and What to Do?

PtR requires an extra LLM call at the retrieval stage, which roughly doubles the inference cost. On queries with several tools the extra cost pays off in quality; on queries with one tool it does not: you pay twice for a result that is worse. The authors' practical conclusion is adaptive routing, that is, choosing the scheme for each query. It does not need a separate classifier: the signal is already in the pipeline. It is the similarity score of the best result (top-1) from plain search.

ZK
Zhemal Khamidun — Head of AI at Alpina Digital · MIPT (academic supervisor of the Tech Entrepreneurship department). Building AI products since 2019. Hamidun News is a pet project that grew into a production aggregator with 6,000+ readers.
✦ Unified AI Workspace · Nomad

Test Frontier LLMs & Autonomous Agents in One Workspace

Run Claude Opus 5.5, GPT-6, Gemini 3.1, and DeepSeek side-by-side in Nomad AI (nomadnet.ai) — unified model routing, deep research, and multimodal workflows under one subscription.

Try Nomad AI →Launch Nomad Agent
Jemal Hamidun

Editor-in-chief · Cite this analysis

Jemal Hamidun

Head of AI at Alpina Digital · Academic Supervisor of the Tech Entrepreneurship Department at MIPT

Head of AI & CPO of AlpinaGPT at Alpina Digital, Academic Lead of Tech Entrepreneurship at MIPT. Founder of Hamidun News and Vibe Academy.

Ready-to-paste citation for journalists, blogs and Telegram channels

Source: Hamidun News — Apple: Planning Before API Retrieval Doubles the Cost but Wins on Complex Tasks https://news.hamidun.com/en/news/16659/apple-planning-before-api-retrieval-doubles-the-cost-but-win

What do you think?
Loading comments…