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
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.
- Nov 26, 2026Magnitude Engine Pushes 180B-Parameter Qwen to 56 Tokens/s on a MacBook
- Nov 26, 2026Codex audit: reasoning cuts off at exactly 516 tokens, and quotas have nothing to do with it
- Nov 25, 2026Stores Take 35% of Brand Mentions in ChatGPT, But They Aren't Recommendations
- Nov 25, 2026PrismML Squeezes 27B Coding Model to 5.9 GB, Keeps 75.6% on SWE-bench Verified
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.
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.
Daily 60-sec AI Voice Brief + Weekly Production AI Agent Playbook
Listen to a 60-second AI news brief every morning and get a weekly hands-on playbook for shipping AI agents to production — tools, MCP servers and patterns that work. Curated by Jemal Hamidun, Head of AI at Alpina Digital.
