TL;DR
When building multi-step LLM agent pipelines, picking the right model for each role (like planning vs. solving) is a massive combinatorial challenge where standalone model rankings often fail. This paper introduces AgentOpt, an open-source Python package that treats client-side agent configuration as a black-box optimization problem. By using sample-efficient search algorithms like Matrix UCB-E, AgentOpt finds near-optimal model combinations while slashing evaluation budgets by 62–76%.
What Problem Does This Paper Address?
Most research on AI agent efficiency focuses on the server side—things like KV cache management, request scheduling, and load balancing. However, developers actually build agents on the client side by stitching together local tools, remote APIs, and various LLMs into multi-step pipelines.
The core challenge is that model performance doesn't transfer cleanly across different roles. A model that excels as a standalone solver might be a terrible planner. Because choices at one stage sequentially affect downstream steps, finding the optimal pipeline configuration becomes an exponential, black-box combinatorial problem. Evaluating every single combination via brute-force testing on a dataset is prohibitively slow and expensive.
Methods
The authors present AgentOpt, a framework-agnostic, non-intrusive Python package designed to automate client-side optimization. It works by intercepting LLM calls at the HTTP transport layer (httpx), meaning it can optimize pipelines built in LangGraph, AutoGen, or CrewAI without requiring developers to rewrite their agent code. It also includes built-in response caching and parallel evaluation to minimize API spend during testing.
To navigate the combinatorial search space efficiently, AgentOpt implements ten search algorithms spanning multi-armed bandits, local search, and Bayesian optimization. The standout algorithm is Matrix UCB-E, which treats the combination-by-datapoint evaluation grid as a matrix. It uses Upper Confidence Bound (UCB) scoring to adaptively allocate the evaluation budget to the most promising model combinations, abandoning poor configurations early.
Datasets
The framework was evaluated across four distinct benchmarks representing different workflow structures:
- HotpotQA: A multi-hop question-answering task configured as a two-stage planner-solver pipeline (81 total combinations).
- MathQA: A mathematical reasoning task set up as an answerer-critic pipeline with up to three retry iterations (81 total combinations).
- GPQA Diamond: A graduate-level science benchmark evaluated as a single-model agent (9 total combinations).
- BFCL v3 Multi-Turn: A multi-turn function-calling benchmark evaluated as a single-model agent (9 total combinations).
Key Insights and Ideas
- The "Best" Model Can Be the Worst Choice: Standalone capabilities do not predict role-specific performance. On HotpotQA, Claude Opus 4.6 (the strongest standalone model tested) was part of the worst planner configurations. Because it was "too smart," it tried to answer questions directly from its parametric memory, completely bypassing the downstream solver and search tools, which caused the pipeline to fail.
- Massive Cost Gaps: At matched accuracy levels, the cost difference between the best and worst model combinations ranged from 13× to 32×. For instance, on the BFCL benchmark, Qwen3 Next 80B matched Claude Opus 4.6's accuracy while reducing costs by 32×.
- LLM Prompts Fail as Selectors: Asking a strong LLM to propose the best model combination based on text descriptions (the "LM Proposal" method) failed dramatically on complex pipelines. It simply couldn't anticipate non-obvious cross-model interactions, proving that empirical evaluation is mandatory.
Key Results
- Matrix UCB-E emerged as the most effective selector. By observing just 20% of the evaluation grid, it recovered near-optimal accuracy across all benchmarks, yielding 62% to 76% cost savings compared to a brute-force search.
- On HotpotQA, pairing the cheapest model, Ministral 3 8B (as planner), with Claude Opus 4.6 (as solver) achieved the highest overall accuracy (74.27%). Conversely, using the expensive Opus model for both roles yielded a miserable 31.71% accuracy.
Limitations and Future Work
The current iteration of AgentOpt primarily targets static model assignments across a fixed pipeline architecture. The authors note that future versions will extend the package to handle more dynamic client-side optimizations. This includes adaptive routing (changing models on the fly based on query difficulty), dynamic tool selection, scheduling, and personalized utility-aware policies that optimize the tradeoff between quality, latency, and cost in real-time.
Summary updated