Search-Based Context Engineering for AI Agents: Optimizing Token Usage and Task Performance
Alina Geiger, Lukas Twist, Giusy Annunziata, Ruizhen Gu, Franz Rothlauf, Dominik Sobania
Abstract
LLM-based agents rely on tools to retrieve the information needed to solve complex tasks. However, every retrieved token enlarges the context, increasing cost and energy consumption. Context engineering addresses this trade-off, yet its design space is too large to explore manually, and existing search-based approaches optimize only isolated aspects of an agent rather than its entire context. To fill this gap, we approach context engineering as a multi-objective search problem and use NSGA-II with accuracy and token usage as objectives to simultaneously optimize an agent's system prompt, its tool-call budget, and the parameters controlling how much content its tools return. We evaluate our approach with two open-weight LLMs on fact verification and question-answering benchmarks against the baseline configuration. On fact verification, NSGA-II finds configurations that reduce token usage by 8%-27% without any significant loss in accuracy. On question answering, token usage is reduced by up to 23%, and in most cases NSGA-II again finds configurations that reduce token usage without sacrificing accuracy. These results show that search-based optimization is an effective approach to design agents that are both accurate and efficient.
Create a lesson
Metadata
- Categories
- cs.NE, cs.AI
Related papers
Agentic Optimization: LLM Agents Select and Configure Algorithms for Engineering Design
Shared title terminologycs.NEDominic Mashak, Jacob Schrum
Is Chaotic Dynamics Enhancing Particle Swarm Optimization? An Anytime Performance Assessment
Shared title terminologycs.NEHendrik Richter
EpicCO: Evolving Frontier Solvers for Combinatorial Optimization with LLM Agents
Shared title terminologycs.NENi Zhang, Kuan Xu, Zhiguang Cao
TabDAG: Structured Evolutionary Search for Tabular Feature Engineering
Shared title terminologycs.NEAnastasia Volkova, Andrey Kuznetsov, Ivan Oseledets et al.
Maximizing Detection Probability in UAV Search Missions using Random-Key Optimizers
Shared title terminologycs.NEAntonio Dantas, Elcio Shiguemori, Antonio Chaves
AgenticEvolve: Evolutionary Program Search with Persistent Language Model Agents that Design and Run Experiments
Shared title terminologycs.NEZe-Yu Peng, Qing-Yu Lan, Zhan-He Wang et al.