TL;DR
This paper introduces Trace, a framework that treats execution traces of general computational workflows as the equivalent of gradients in AutoDiff (like PyTorch). By framing optimization as Optimization with Trace Oracle (OPTO) and using an LLM-based optimizer called OptoPrime, the authors enable end-to-end tuning of non-differentiable systems—ranging from robot controllers to LLM agents—using rich, textual feedback instead of just numerical scores.
What Problem Does This Paper Address?
In the world of deep learning, we have "AutoDiff" (Automatic Differentiation). If you want to improve a neural network, you calculate a gradient that tells you exactly how to tweak every weight to reduce error. However, modern AI systems are increasingly "compound"—they are workflows involving Python code, prompts, simulators, and discrete logic.
These workflows are often non-differentiable. You can't take the derivative of a line of code or a natural language prompt. Currently, optimizing these systems requires "black-box" methods (like Bayesian Optimization or Reinforcement Learning) that only look at a final score. These methods are incredibly inefficient because they don't know why a system failed; they just know it did. The authors aim to bridge this gap by providing a way to propagate "rich feedback" (like error messages or user critiques) back through a complex workflow to the specific parameters that need changing.
Methods
The authors propose three core components to solve this non-differentiable optimization problem:
- OPTO (Optimization with Trace Oracle): A new mathematical framework where an optimizer doesn't just get a score, but an execution trace (a graph showing what happened) and feedback (textual or numerical) on the output.
- The
TraceLibrary: A Python library with a PyTorch-like syntax. Users mark parameters astrainable=Trueand wrap functions with a@trace.bundledecorator. As the code runs,Traceautomatically builds a Directed Acyclic Graph (DAG) of the execution. - OptoPrime: A general-purpose optimizer powered by an LLM (like GPT-4). When a workflow finishes,
Tracesends a "minimal subgraph" of the execution to OptoPrime. OptoPrime uses its reasoning capabilities to look at the trace and the feedback, then suggests updates to the parameters (which could be numbers, prompts, or even entire blocks of Python code).
Crucially, the Minimal Subgraph Propagator (MSP) is the "backprop" of this system. It identifies exactly which inputs and intermediate steps contributed to the final output, allowing the LLM to focus its "reasoning" only on the relevant parts of the workflow.
Datasets
The researchers evaluated Trace across a diverse set of benchmarks to prove its generality:
- Big-Bench Hard (BBH): Used for joint prompt and code optimization in LLM agents.
- LLF-Bench Meta-World: A robotics simulator where Trace was used to learn Python-based control logic for a Sawyer robot arm (tasks: Reach, Pick-place, Push).
- UXSim: A traffic flow simulator used for hyperparameter tuning of traffic light durations.
- Battleship: A custom environment where the system learned to write and improve its own game-playing strategy code.
- Synthetic Numerical Tasks: Complex mathematical graphs used to compare Trace against standard optimizers like Adam.
Key Insights and Ideas
- Traces are the New Gradients: The central "aha" moment is that an execution trace provides the same structural information as a gradient. It tells the optimizer the "pathway" from input to output, which is essential for assigning credit (or blame) for the final result.
- Joint Optimization: Unlike previous tools that only tune prompts or code, Trace can tune both simultaneously. It treats a Python function's source code as just another trainable parameter.
- Efficiency through Structure: By providing the LLM with a structured trace rather than just a history of past attempts, the optimizer finds solutions much faster.
- Modularity: The authors decoupled the tracing (the infrastructure) from the optimizer (the LLM). This means as LLMs get better, the optimization gets better without changing the underlying code.
Key Results
Trace demonstrated strong performance across multiple domains, often matching or beating specialized optimizers.
- Code Optimization (Battleship): As shown above, Trace successfully learned to write and improve its own Battleship strategy code, significantly outperforming the OPRO baseline by learning to balance unexplored squares and adjacent hits.
- Numerical Optimization: Trace matched the performance of Adam (the gold standard for neural nets) on complex numerical optimization tasks, despite only receiving "larger/smaller" text feedback.
- Prompt/Code Tuning: On Big-Bench Hard, Trace improved a DSPy-based agent's accuracy by 10% on algorithmic tasks compared to DSPy’s own specialized optimizer (COPRO).
- Robotics: Trace successfully learned sophisticated robot control logic from scratch. It was significantly more stable and successful than OPRO, a state-of-the-art LLM optimizer that doesn't use execution traces.
- Speed: Compared to TextGrad (a concurrent framework), OptoPrime was roughly 3x faster in wall-clock time because it makes a single, holistic LLM call for the entire trace rather than calling the LLM for every single node in the graph.
Limitations and Future Work
- Context Window Limits: Because the entire trace (as pseudo-code) must fit into an LLM's prompt, Trace currently struggles with extremely large graphs (thousands of nodes).
- Feedback Design: The system is only as good as the feedback it receives. Designing "informative" feedback is still a manual task, much like designing a loss function in deep learning.
- Stateful Logic: The current implementation has trouble tracing functions that modify objects "in-place" (though the authors suggest workarounds).
- Future Directions: The authors envision "Deep Agent Workflows" where agents fluidly mix tensors, LLMs, and programmable tools, all self-improving through Trace-based optimization. They also suggest incorporating non-textual feedback, such as images or video, in the future.
Summary updated