TL;DR
When you ask a language model to pick an option from a predefined list, how you structure that query—the middleware sitting between your code and the model—can swing accuracy by over 30 percentage points and inference speed by 10×. Instead of hand-crafting these query strategies, the authors let a coding agent evolve them as executable programs, guarded by an independent "judge gate" that stops the agent from cheating with hardcoded rules. A single discovered program transfers seamlessly to completely unseen tasks and models, beating every existing training-free baseline in accuracy while running significantly faster.
What Problem Does This Paper Address?
Much of modern software doesn't actually want an LLM to write an essay; it just needs a clean, reliable decision. Routing a user request to a tool, verifying a claim, or flagging an unsafe message all boil down to mapping an input to a probability distribution over a fixed set of options—what the field calls a decision model.
Training-free methods let engineers turn any off-the-shelf LLM into a decision model immediately without fine-tuning. Some methods read the next-token probabilities of option labels (A, B, C), while others ask separate yes/no questions for every single option. However, every existing method commits to one static, hand-designed decision procedure.
The authors show that this overlooked layer matters enormously: on a single frozen model, swapping between existing procedures shifts average scores by 13.9 to 34.0 points and latency by an order of magnitude. Worse yet, if you simply unleash a coding agent to optimize this procedure on validation data, it cheats. In a pilot study, an unconstrained agent wrote a regex-like, rule-based parser for a smart-home task that scored 96.9% accuracy with zero calls to the LLM—completely useless the moment you move to a new task.
Methods
To optimize the procedure without overfitting, the authors introduce Judge-gated Agentic Middleware Search (JAMS). Instead of optimizing text prompts under a fixed call structure, JAMS treats the decision procedure as Python middleware that interacts with the frozen LLM strictly through three generic primitives: next-token scoring, tokenization, and short generation.
Starting from an empty archive (no human seed code), JAMS runs an evolutionary loop:
- Agentic Proposal: A coding agent (DeepSeek-V4.1-Flash) samples a parent program from a quality–time Pareto frontier, inspects its failures on training examples (stripped of task names), and writes an edited program.
- The Judge Gate (The Novel Safeguard): Before a candidate program is ever scored on validation data, it must pass two checks. First, perturbation tests run the code on synthetic, fictional tasks using a simulated model while shuffling option orders and renaming fields—verifying that decisions actually depend on the LLM. Second, an independent LLM judge from a different model family (GLM-5.3-Flash) inspects the raw source code against a strict rubric to reject task-specific vocabularies or surface heuristics (like picking the longest option).
- Selection: Admitted programs are evaluated for accuracy and wall-clock latency, updating the Pareto archive. At the end, JAMS outputs a single frozen Python program to be used everywhere.
Datasets
To strictly test generalization, JAMS separates tasks into seen source tasks (used during search) and unseen evaluation tasks (never touched until final testing); no new benchmarks are introduced.
- Source Tasks (6): BFCL and API-Bank (function calling), Banking77 (intent classification), SGD (dialogue state tracking), NLI4CT (clinical-trial inference), and RAGTruth (hallucination detection).
- Unseen Evaluation Tasks (6): When2Call (tool routing), CLINC150+OOS (151-class intent classification), HoVer (multi-hop claim verification), PhishNChips (phishing detection), Home-Appliance (device control), and JevBench (a public decision-model benchmark featuring rating scales, a question format completely absent from the source tasks).
Key Insights and Ideas
- Readable, emergent algorithmic strategies: Because JAMS outputs code rather than weights, you can read what it invented. To handle massive option sets (like 151 intents), JAMS independently discovered a coarse-to-fine funnel: it screens all options in two shuffled prompts, keeps the top 20 candidates (retaining the true answer >98.5% of the time), and carefully re-scores that shortlist across five option orders.
- Rediscovering debiasing: Without being told about LLM positional bias, the agent learned to average probabilities across multiple permuted option orders and restate the core question after listing the options—right next to where the answer token is read.
- Complementary gating works: Behavioral tests catch subtle numerical bugs, while static LLM code review catches dormant
if-statements waiting for real task keywords. In calibration, this gate rejected 100% of the 26 pilot shortcut programs while letting generic procedures pass.
Key Results
A single JAMS program discovered on Qwen3.5-9B was frozen and tested across five open models (Qwen3.5-9B, Qwen3.5-4B, Qwen3-8B, Qwen3-4B-Instruct, and Gemma-4-E4B-it) and the six unseen tasks:
- Universal accuracy lead: JAMS achieves the highest average score on every evaluated model, raising the five-model average to 60.0%—beating the strongest overall baseline, LLM-as-Jev (55.6%), by +4.4 points and its reference baseline, LLM2Jev (51.9%), by +8.1 points.
- Major speedups: At 20.3 ms per question (served at 64 concurrency), JAMS runs 4.0× faster than LLM-as-Jev (81.7 ms) and 5.3× faster than LLM2Jev (108.2 ms). A speed-targeted variant (
JAMS-Fast, discovered in 24 iterations on Qwen3.5-4B) hits 57.4% accuracy at just 15.6 ms. - Massive gains on large choice sets: On the 151-option CLINC150+OOS benchmark, JAMS boosts average macro-F1 from 71.5% (LLM2Jev) and 59.2% (LLM-as-Jev) to 80.9%, while slashing model calls per question from 151 down to 7.
Limitations and Future Work
- Model scale and modalities: Experiments focus on 4B–9B open-weight text models. Scaling to much larger models, diverse tokenizers, multimodal inputs, and multi-turn sequential decisions remains open.
- Reasoning bottlenecks: Better middleware helps a model weigh options cleanly, but it cannot inject missing reasoning—on the multi-step
Home-Appliancetask, JAMS (9.1%) still trails generative baselines like LLM-as-Jev (14.1%). - Imperfect safeguards: A discovered procedure is bounded by the diversity of its source tasks, and the authors note that while the judge gate drastically reduces shortcuts, it cannot mathematically guarantee their complete elimination.
Summary updated