Compiling Agent Traces into Typed Workflows for Cheaper and Faster Execution of Recurring Tasks

Jorge Garcia-Carrasco, Javier Sanchis, Sandra Garcia-Ponsoda, Alejandro Mate, Juan TrujilloarXiv 2026

TL;DR

LLM agents are wonderfully flexible at handling everyday digital chores, but having them rethink a routine task from scratch every single time is like hiring a master architect just to turn off a light switch. This paper introduces a "compiler agent" that reads the logs of successful LLM agent runs and distills them into fast, reusable, inspectable workflow graphs. By turning mechanical steps into plain code and isolating only the moments that truly require AI judgment, these compiled workflows execute recurring tasks 76 times faster and at 98 times lower cost—paying off their own compilation price in a few dozen runs.

What Problem Does This Paper Address?

When you ask an LLM agent to "move my wake-up alarm 30 minutes later and disable the rest," it reads API docs, explores your phone's state, reasons step-by-step, and fixes its own mistakes. That flexibility is magical the first time. The fiftieth time you ask a slight variation of the same thing, paying for tens of thousands of tokens and waiting nearly a minute feels absurd.

Conversely, a rigid Python script is virtually free to run, but breaks the moment you phrase your request slightly differently. While recent systems have tried turning agent logs ("traces") into reusable programs, they typically treat model calls like opaque black boxes and rarely account for the upfront cost of compiling the program in the first place. The authors ask: What exact shape should a compiled workflow take so that code handles the mechanics, AI handles only bounded ambiguity, and when does compiling actually pay off?

Methods

The authors propose two main pieces: a strict Intermediate Representation (IR) for workflows, and a Compiler Agent that builds it.

Instead of a conversational loop, a compiled workflow is a directed graph executed by a lightweight engine (with zero prompt context carried around). Every node in the graph is strictly typed by its output space:

  • EXECUTE: Pure deterministic code and API calls (e.g., fetching songs, shifting a timestamp). Requires zero AI models.
  • DECIDE: A bounded semantic choice over a closed set of candidates declared by the graph or read from live state (e.g., picking which existing alarm matches "wake-up"). Answered by a small, structured decision model (Jev), with routing strictly owned by the engine—never free-form text.
  • GENERATE: An escape hatch for open-ended text or unenumerated extraction, handled by a standard generative LLM.

To build this package, a Compiler Agent (DeepSeek V4.1 Flash) is placed in a sandbox with successful execution traces, the IR specification, and a live test database of only those traced runs. Crucially, it isn't told what the task is in plain English—it must infer the procedure purely from the traces, write the graph and Python operations, test them against the sandbox database, and repair its work until the final database state matches the traces.

Datasets

The authors evaluate on AppWorld, a realistic benchmark featuring nine simulated everyday apps (like Spotify and a phone alarm app), 457 APIs, and state-based grading tests that check both goal completion and collateral damage. They test three multi-step task families that vary in how much ambiguity lives in the user's phrasing vs. the database:

  1. Artists: Follow Spotify artists of a given genre above a follower threshold.
  2. Alarms: Shift a specific alarm ("wake-up" or "go-to-sleep") earlier/later and disable others.
  3. Songs: Remove songs from library and playlists based on release year comparisons.

Using AppWorld's task generators, they created 76 distinct instances: 46 used for tracing/compilation, and 30 held-out instances featuring entirely unseen user databases, dates, and records.

Key Insights and Ideas

  • Removing the agent loop beats shrinking the model: In an ablation where the authors swapped out the cheap decision model for a large generative LLM inside the compiled graph, per-run costs went up 7x—yet the workflow was still 20x cheaper than the native agent. The massive savings come from stripping away the 90,000-token conversational loop, not from penny-pinching on model size.
  • What lowers to code depends on the world, not workflow length: The Songs workflow compiled down to 13 pure EXECUTE nodes—zero AI calls!—because years and operators ("before 2021") can be parsed with regexes. Artists required one DECIDE call because you can't know what string is a valid musical genre without checking the database's live genres first.
  • Graceful degradation under scarce data: When given only 3 traces instead of ~15, the compiler lacked confidence to write rigid regex parsers for instructions, so it smartly fell back to GENERATE nodes as an escape hatch—and still passed 100% of held-out tests.

Key Results

  • Accuracy: Compiled workflows solved 30/30 held-out instances (matching the native agent's 29/30).
  • Cost & Speed: Median cost dropped 98x (from $0.002276 to $0.000023 per run; mean cost dropped 139x). Median wall-clock latency dropped 76x, from 46 seconds down to 0.6 seconds. Model calls dropped from 10.1 per run to 1.0.
  • Break-even Economics: Compiling a workflow took 3.3 to 4.8 minutes and cost $0.04–$0.07 (plus trace generation costs). Total upfront investment paid for itself after 31 executions (Songs), 41 executions (Alarms), and 50 executions (Artists).
  • Data Efficiency: Just 3 traces were enough to hit 10/10 held-out accuracy across all three task families.

Limitations and Future Work

The authors candidly note that their train/test split keeps request templates visible while withholding unseen worlds (databases, users, dates), meaning generalization is tested over data variation rather than wild new phrasings. Additionally, sample sizes (10 held-out runs per family) bound the statistical precision of accuracy claims, all input traces were pre-filtered successes, and multi-turn user interaction wasn't evaluated.

For future work, they point to three missing pieces needed for a complete production system: a selector to match incoming requests to existing trace families, a runtime dispatcher to route familiar tasks to compiled graphs and novel ones to a full agent, and compiler optimization passes to shrink graphs further as more traces arrive.

Summary updated

BibTeX
@misc{garciacarrasco2026compiling,
  author = {Jorge Garcia-Carrasco and Javier Sanchis and Sandra Garcia-Ponsoda and Alejandro Mate and Juan Trujillo},
  title = {{Compiling Agent Traces into Typed Workflows for Cheaper and Faster Execution of Recurring Tasks}},
  year = {2026},
  eprint = {2611.36322},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.36322},
}
Figure