optimize anything: A Unified Framework for LLM-Based Mathematical and Scientific Optimization

Lakshya A Agrawal, Donghyun Lee, Shangyin Tan, Wenjie Ma, Karim Elmaaroufi, Rohit Sandadi, Sanjit A. Seshia, Koushik Sen, Dan Klein, Ion Stoica, Joseph E. Gonzalez, Omar Khattab, Alex Dimakis, Matei ZahariaAI4Math @ ICML 2026

TL;DR

The paper introduces optimize_anything, a declarative framework that treats prompts, Python code, and agent architectures as a single category: "text artifacts." By using "Side Information" (diagnostic feedback) as a textual analogue to gradients, the system outperforms specialized, domain-specific tools across mathematical reasoning, algorithmic discovery, and blackbox optimization.

What Problem Does This Paper Address?

Currently, LLM-driven optimization is fragmented. If you want to optimize a system prompt, you might use a tool like MIPROv2. If you want to discover a new mathematical algorithm, you turn to FunSearch or AlphaEvolve. If you are building an agentic workflow, you might look at ADAS.

The authors argue that this fragmentation is artificial. Whether you are tweaking a sentence or a 500-line Python script, the underlying loop is identical: you have a text artifact, a scoring function, and a desire to improve the former to maximize the latter. Existing systems impose rigid, domain-specific abstractions (like "island topologies" or "evolve-block markers") that prevent a unified approach. The challenge is creating a single interface that is flexible enough to handle these diverse tasks without sacrificing performance.

Methods

The core of the paper is a declarative API where the user defines what to optimize, and the framework handles how to optimize it.

  1. The "Text Gradient" (Side Information): This is the framework's most significant conceptual contribution. In traditional optimization, a gradient tells you which direction to move. In optimize_anything, the evaluator returns a score plus Side Information (SI). SI includes compiler errors, runtime traces, or even rendered images. This allows the LLM "proposer" to understand why a candidate failed, moving the process from "blind evolution" to something resembling a mathematician iterating on a proof.
  2. Unified Interface: The user provides a seed artifact (or a natural language objective), an evaluator, and optionally a dataset.
  3. Two Optimization Modes:
    • Single-task search: The artifact is the solution (e.g., finding the best way to pack circles in a square).
  4. Generalization: The artifact must perform well on unseen inputs (e.g., a prompt that works for all math problems in a set).
  5. Backend Engine: The system uses GEPA (a Pareto-based search algorithm) as its backbone. It maintains a "frontier" of non-dominated candidates, ensuring diversity in the types of solutions being explored (e.g., keeping both a fast, simple algorithm and a slow, complex one on the frontier).

Datasets

The framework was evaluated across four distinct domains:

  • AIME 2022–2025: A standard benchmark for high-school level mathematical reasoning.
  • Circle Packing (n=26): A classical geometry problem requiring the discovery of efficient Python algorithms.
  • ARC-AGI: A benchmark for abstract reasoning and fluid intelligence.
  • EvalSet: A 56-problem blackbox optimization benchmark typically used to test numerical solvers like Optuna.

Key Insights and Ideas

  • Text as a Universal Abstraction: By treating code and prompts as the same "stuff," the system can perform "multi-module leapfrogging." For example, it can optimize a Python script and a "refiner prompt" simultaneously, allowing the two to evolve in tandem.
  • SI is Essential: An ablation study showed that without Side Information (relying on scores alone), the system's performance on circle packing dropped significantly. The LLM needs to see the "logic" of the failure to propose a targeted fix.
  • Emergent Complexity: In the ARC-AGI task, the system evolved a simple 10-line "seed" agent into a 300+ line, 4-stage pipeline featuring rule induction, iterative debugging, and automated fallbacks—patterns that usually require weeks of manual engineering.
  • Algorithm Discovery vs. Parameter Tuning: Unlike traditional optimizers that tune numbers within a fixed algorithm, optimize_anything writes the solver itself, discovering bespoke strategies (like L-BFGS-B or CMA-ES) tailored to specific problem landscapes.

Key Results

The framework matched or exceeded state-of-the-art specialized tools in every category:

  • AIME 2025: Lifted GPT-4.1-mini performance from 46.7% to 60.0%, surpassing the specialized prompt optimizer MIPROv2 (51.3%).
  • Circle Packing: Discovered a solution for $n=26$ that exceeded the published results of AlphaEvolve and OpenEvolve.
  • ARC-AGI: Evolved a Gemini 3 Flash agent from 32.5% to 89.5% accuracy on the test set.
  • Blackbox Optimization: Improved upon Optuna (a industry-standard numerical optimizer) in 7 out of 10 "hard" problems by synthesizing custom solvers.

Limitations and Future Work

  • Model Sensitivity: The quality of the optimization is heavily dependent on the "proposer" LLM. Using a smaller, cheaper model (like GPT-5-nano) leads to significantly worse results than using a flagship model.
  • Cost: While sample-efficient compared to gradient-free search, the absolute cost can be high. The ARC-AGI evolution, for instance, cost $144.70 in API fees.
  • The "Text-Only" Constraint: The artifact must be representable as text. Optimizing continuous parameters or binary files requires a text-based proxy, which may not always be efficient.
  • SI Design: While the framework is declarative, the user still needs domain expertise to decide what Side Information is most useful for the LLM to see. Designing effective "text gradients" is the new bottleneck.

Summary updated

BibTeX
@inproceedings{agrawal2026optimize,
  author = {Lakshya A Agrawal and Donghyun Lee and Shangyin Tan and Wenjie Ma and Karim Elmaaroufi and Rohit Sandadi and Sanjit A. Seshia and Koushik Sen and Dan Klein and Ion Stoica and Joseph E. Gonzalez and Omar Khattab and Alex Dimakis and Matei Zaharia},
  title = {{optimize anything: A Unified Framework for LLM-Based Mathematical and Scientific Optimization}},
  booktitle = {AI4Math @ ICML},
  year = {2026},
  url = {https://openreview.net/forum?id=iI5UOnuBGw},
}
Figure