Large language model (LLM) agents are increasingly capable of navigating complex graphical user interfaces (GUIs) to perform tasks like scheduling meetings or editing documents. However, these "computer-use agents" are notoriously expensive. Because they must process high-resolution screenshots and long accessibility trees at every step, their token consumption is massive.
A common optimization is to "compile" repetitive agent procedures into parameterized code. Once compiled, the agent only needs to call the model once to extract parameters; the rest of the task is handled by efficient code. But there’s a catch: compilation itself is expensive, prone to failure, and the resulting program might break if the GUI changes.
In their paper, "When to Compile a Computer-Use Agent?", researchers from the City University of Hong Kong introduce PACE (Payback-Aware Compilation from Experience), a framework designed to answer the billion-token question: Is it actually worth it to compile this task right now?
TL;DR
PACE is a system that decides when to transform expensive LLM agent GUI traces into efficient programs by systematically measuring compilation "payback." Using an online algorithm with a cumulative cost budget, PACE reduces token costs by up to 25% while guaranteeing that total spending never exceeds a small margin over the baseline agent cost.
What Problem Does This Paper Address?
While compiling GUI procedures into code saves tokens during execution, the process of compilation is risky. The authors identify two primary challenges:
- Uncertain Compilation Costs: A model might need multiple attempts or expensive "repairs" to generate a working program. If it fails entirely, those tokens are wasted.
- Unknown Future Use: A program only saves money if it is reused. If a task stops appearing, or if the interface changes ("GUI drift") and breaks the program before it pays for itself, the upfront compilation cost becomes a net loss.
Prior systems often ignored these "payback" dynamics, leading to scenarios where "optimization" actually increased the total bill.
Methods
The authors propose PACE, which consists of two main components:
1. The Measurement Protocol
PACE doesn't just guess savings; it measures them. The protocol records the exact token costs of successful and failed compilation attempts. It then compares the agent’s execution cost against the program’s execution cost on "matched task inputs" to calculate the per-use saving and the payback count (the number of reuses needed to break even).
2. The Online Compilation Algorithm
This is the "brain" of PACE. It makes two checks before allowing a compilation attempt:
- The Savings Test: It estimates future reuse based on past task arrival frequency and a "GUI drift" probability. It only proposes compilation if the expected future savings outweigh the estimated compilation cost (including the cost of potential failures).
- The Budget Check: This is a hard safety constraint. It ensures that the cumulative cost of the system (execution + routing + failed/successful compilations) stays within $(1 + \epsilon)$ of the cost of just running everything with the basic agent. This protects the user from massive losses if the reuse estimates are wrong.
Datasets
The researchers evaluated PACE using:
- Task Families: Seven parameterized task families across AndroidWorld (e.g., adding contacts), OSWorld (LibreOffice tasks), and WebArena (Reddit comments).
- Arrival Logs: To simulate realistic task streams, they used public event logs from Sepsis cases, the BPI 2019 challenge, and Wikipedia edit streams.
- Models: The experiments utilized GLM 5.3 Flash, DeepSeek Flash, and Qwen 3.8 Flash.
Key Insights and Ideas
- Failures are Expensive: Failed compilation attempts can be significantly costlier than successful ones. For DeepSeek, failed attempts had a median cost 6.5x higher than successful ones. PACE is the first to explicitly factor these "sunk costs" into the decision-making process.
- The Payback Reality Check: The "payback count" for a successful compilation typically ranges from 2 to 16 uses. If a task isn't going to repeat at least that many times, you're better off just using the expensive agent.
- Frequency $\neq$ Profitability: A task might appear frequently, but if it has a low verification probability (it's hard to compile) or a short GUI lifetime, it might still be a bad candidate for compilation.
Key Results
- Token Savings: In simulations using real-world arrival logs, PACE reduced token costs by 17.3% compared to the standard ReAct agent.
- Outperforming Baselines: PACE outperformed adaptations of other state-of-the-art systems, saving 24.9% more than AutoRPA and 17.3% more than ToolPro.
- Cost Guarantee: The authors proved (and empirically verified) that PACE maintains a cumulative cost bound. Even in worst-case scenarios where compilation repeatedly fails, the system doesn't "run away" with the budget.
Limitations and Future Work
- Scope of Tasks: The study covered seven task families; broader benchmarks are needed to see how these costs scale across thousands of diverse GUI tasks.
- Silent Failures: The current model assumes program failures are detectable. "Silent" failures (where a program thinks it succeeded but didn't) would require more complex fallback logic.
- Drift Estimation: While the paper uses a fixed probability for GUI drift, future work could involve building online detectors to estimate drift in real-time.
- Human Factors: The model focuses purely on token costs, excluding human effort for program maintenance or the latency benefits of compiled code.
Summary updated