CAPE: Coordinating Calibration and Search for Tool-Use Policies

Jiahao Wang, Xiaoxuan Chen, Aijun Yang, Xiaohua WangarXiv 2026

TL;DR

Even when an AI agent writes functionally flawless logic, a tool call can still crash because the receiving system silently expects semicolons instead of commas, or DD/MM instead of MM/DD. Rather than letting an LLM blindly guess-and-check at runtime, CAPE compiles an optimal, contingent "decision tree" beforehand—smartly balancing its strict time budget between testing how the tool behaves and searching for the best strategy. It finds optimal tool-use policies significantly faster than exhaustive methods and crushes online LLM retry loops at execution time.

What Problem Does This Paper Address?

Picture this: an agent needs to upload a table of Seattle weather records to an external data-ingestion tool. The agent’s data transformation is spot-on, yet the upload fails. Why? Because behind the scenes, the deployed parser is configured in one of dozens of hidden ways—varying in delimiters, date orders, or missing-value markers—and the agent only gets to see a generic error or parsed output, with a strict limit of $C$ calls (say, 3 or 5) to get the job done.

When candidate configurations can be mocked up in a sandbox before deployment, we can pre-compile a policy: a branching plan that dictates which action to send next based on the tool's previous response. Building this policy requires two things that compete for the same compilation clock ($\tau$):

  1. Calibration: Running test queries in the sandbox to see what happens under different configurations.
  2. Search: Piecing those recorded outcomes together into a winning decision tree.

If you calibrate everything upfront ("eager exact"), you waste precious time testing scenarios your final policy never visits—and if the clock runs out early, you walk away with nothing better than your starting baseline. Conversely, if you re-solve the entire search tree from scratch after every single test query, computation grinds to a halt.

Figure 1. Calibration and search share a compilation allowance. Eager exact completes acquisition before search; CAPE updates executable policies during acquisition. Both retain the validated initial policy; deployment has a separate C-call limit.

Methods

The authors introduce CAPE, a training-free policy compiler built around one core realization: an action is ready to use on a branch as soon as you know how it behaves on the specific configurations that actually reach that branch (which the authors call being locally closed).

CAPE operates over two types of actions: programs (actual data submissions in a specific serialization format that finish the job if accepted) and probes (tiny diagnostic fixtures, like sending 05/04/2026 just to see whether the parser reads it as April 5 or May 4 without publishing anything).

Figure 2. A locally closed probe is optimal on the reached scope. With two calls left, Q13 completes all three configurations in V ; any program-first continuation completes at most two. The table shows the three programs that commit on V ; dates abbreviate the full response; DMY/MDY denote date order. The acquisition mask is illustrative.

Unlike standard lazy graph search—which only evaluates edges along a purely optimistic path on a fixed graph—tool responses actively change how configurations split, reshaping the tree below them. CAPE coordinates calibration and search through a persistent policy graph:

  • Persistent Executable "Witness": At every state, CAPE maintains the best working policy built strictly from known, tested effects (giving a guaranteed lower bound) alongside an optimistic upper bound assuming untested probes split configurations cleanly and untested programs succeed.
  • Dual-Frontier Acquisition: CAPE directs new sandbox queries to where the working policy and optimistic bound disagree, following both the current executable policy and the best optimistic alternative. It prioritizes preserving baseline coverage first, then maximizing completed configurations per missing test, and finally saving calls.
  • Selective Bound Tightening: Computing tighter upper bounds via a two-call lookahead ($T_2$) can prune dead-end queries early, as shown in Figure 3. However, computing $T_2$ everywhere often costs more CPU time than the sandbox queries it saves. CAPE applies $T_2$ selectively—only to the action currently being calibrated.
Figure 3. A local observation updates a persistent policy graph. Acquisition stops on closure, infeasibility or domination. Composition additionally requires feasible child witnesses; witness and bound changes propagate to the affected parents.

Because CAPE updates a valid witness in place, it is an anytime algorithm: if interrupted when time $\tau$ expires, it immediately returns a policy guaranteed not to lose a single configuration that the initial baseline policy could solve. When the lower and upper bounds meet at the root, CAPE certifies mathematical optimality.

Datasets

Because CAPE is training-free, there is no training dataset. For evaluation, the authors construct workflows from eight Vega dataset source files (up to 256 records each) paired with eight data operations (such as projection, filtering, and grouped counts), totaling 64 requests proposed by LLMs (primarily DeepSeek-V4-Pro, plus a 14-model panel). These requests are tested against two realistic ingestion tools:

  • A CSV tool built on DuckDB with 64 configurations (scaled up to 128 and 256 configurations by adding date encodings in scaling studies).
  • A JSON tool built on pandas.read_json with 88 configurations varying orientation, quoting, and encodings.

Key Insights and Ideas

  • Local closure saves massive effort: In a recorded JSON case study across 88 configurations, an initial failed call narrows one branch down to just 8 remaining configurations. CAPE evaluates the next candidate on just those 8 to make the branch executable, whereas full-row calibration burns 88 evaluations before moving on.
  • Diagnostic probes shine under tight call budgets: When an agent only gets $C=3$ tries, blindly firing formatted tables one by one hits a ceiling. Spending one call on a clever probe to split the ambiguity boosts CSV completion from 76.76% (program-only) to 85.16%.
  • Smart math only pays off if queries are pricier: At $C=3$ on CSV, tightening bounds everywhere saves net time by cutting ~434 queries. At $C=5$, it barely avoids any queries while ballooning bound-computation time over 60x—justifying CAPE's selective approach.

Key Results

Under a 30-second compilation allowance across CSV and JSON tasks:

  • Near-universal optimality, faster: CAPE hits the independently verified global optimum in 502 of 504 compilations (certifying 498 at runtime) while cutting mean compilation time by 22.0% compared to eager exact search (11.45s vs. 14.67s).
  • Graceful scaling: When the CSV configuration space expands to 128 configurations (outgrowing the 30-second budget for exhaustive methods), CAPE achieves 88.28% completion—beating eager exact search by 21.88 percentage points and a matched AND/OR lazy scheduler by 14.06 percentage points in the same ~27-second window.
  • Crushing runtime LLM retries: In live execution, CAPE's compiled policies achieve 15.38 to 34.66 percentage points higher completion than an online DeepSeek-V4-Pro controller that revises its serialization from error feedback, while also using fewer calls on JSON at $C=5$ (1.475 vs. 2.682 calls).

Limitations and Future Work

The authors do not include a dedicated "Limitations and Future Work" section, though the problem formulation defines clear scope boundaries:

  • Pre-deployment assumptions: CAPE assumes the finite family of candidate tool configurations ($H$) is known in advance and can be faithfully reproduced in a test environment.
  • Deterministic, rollback-safe semantics: The framework relies on deterministic tool effects where failed calls leave the underlying task state unchanged (non-committing calls are rolled back), addressing data representation after the semantic operation has already been chosen. Future directions beyond this setup are not discussed in the paper.

Summary updated

BibTeX
@misc{wang2026cape,
  author = {Jiahao Wang and Xiaoxuan Chen and Aijun Yang and Xiaohua Wang},
  title = {{CAPE: Coordinating Calibration and Search for Tool-Use Policies}},
  year = {2026},
  eprint = {2611.31938},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.31938},
}
Figure