Grafy News
Try Grafy free

New Scaling Laws for Agent Memory in Verified Coding

Researchers have identified how in-context curricula can speed up verified code generation for AI agents, offering a new way to optimize search costs.

Illustration for the news story: New Scaling Laws for Agent Memory in Verified CodingSource: Grafy Research Lab

Researchers have identified a predictable relationship between the size of an in-context curriculum and the speed at which AI agents can generate verified code. This discovery suggests that providing agents with task-relevant examples—rather than just raw data—can significantly reduce the computational cost and time required to reach a correct, machine-checkable solution.

How do agent scaling laws differ from standard LLM laws?

Traditional scaling laws for large language models (LLMs) typically focus on predicting cross-entropy loss based on parameters, data, and compute. However, in settings where an agent's output is subject to a formal verifier, these metrics are less relevant. According to the research paper "Agent Memory Scaling Laws for Verified Trainium Kernel Generation," even a model with high loss can eventually produce a correct solution if given enough time.

In this verified setting, the primary metric of quality is the "time-to-solution," often measured by the number of output tokens required to reach an accepted answer. The study explores how this search cost scales as the agent is provided with increasing amounts of in-context information, or "curriculum."

What are the benefits of using a task-relevant curriculum?

In the study, the researchers used the generation of Trainium kernels (specialized hardware code) as a testbed. Because this hardware is relatively new, the models could not rely on pre-existing training data, making it a clean environment to test the impact of provided context.

According to the authors, providing a task-relevant curriculum follows an approximate power law. As the curriculum size NN increases, the speedup S(N)S(N) improves in a predictable manner. Specifically, the research found that teacher-curated curricula could achieve approximately a 2.9×2.9\times speedup in output tokens compared to having no curriculum at all. Furthermore, the lowest measured solve cost was 52%52\% lower when including the cost of the curriculum prefill.

Crucially, the research noted that curricula also benefit weaker agents. While some smaller models might fail to find a verified solution entirely when working from scratch, the addition of task-relevant examples allowed them to successfully reach accepted solutions.

What is spec lift and how does it optimize agent memory?

To avoid the inefficiency of feeding agents massive amounts of random data, the researchers introduced a method called "spec lift." This is an offline scoring mechanism designed to select the most effective examples for a curriculum before the agent begins its search task.

Spec lift measures how much a candidate piece of context increases a reference model's likelihood of producing the target specification. The study found that this score is a highly accurate predictor of downstream speedup, boasting a correlation of r=0.95r = 0.95. By selecting examples greedily based on this score, developers can build optimized curricula that maximize the agent's efficiency without the trial-and-error of random selection.

Why is formal verification important for coding agents?

While coding agents are increasingly capable, they often produce large volumes of code that may contain subtle bugs or logical errors, leading to issues with reliability and trust. Formal verification addresses this by requiring the agent to satisfy predetermined "contracts."

In the experimental setup, the agents generated Rust representations of kernels, which were then checked by Verus, a formal verifier for Rust programs. For a solution to be considered admissible, it must pass a proof-of-correctness check. This ensures that the code does not just look correct, but is mathematically proven to behave as intended. This approach is particularly vital for high-stakes environments like hardware kernel generation, where errors can be costly and difficult to debug.

How can developers apply these findings?

For developers building agentic workflows, these findings suggest that the quality of the "memory" or context provided to an agent is just as important as the model's raw reasoning power. Instead of simply increasing the context window with arbitrary data, focusing on a curated, task-specific curriculum can lead to massive savings in both token usage and time.

If you are working on complex programming tasks or exploring the limits of agentic reasoning, you can experiment with different model capabilities and prompt structures in Grafy Code. While the specific formal verification workflows described in this paper are specialized, the principle of providing high-quality, relevant context remains a cornerstone of effective AI-assisted development.

Frequently asked questions

Does a larger curriculum always lead to better results?

Increasing the curriculum size improves the speedup of verified code generation according to a power law, but it also increases the initial token cost (prefill). The research indicates there is an optimal curriculum size that minimizes the total economic cost, balancing the speedup gained against the cost of processing the extra context.

Can weaker AI models benefit from this approach?

Yes, the study demonstrated that curricula are especially beneficial for weaker agents. In several instances, agents that were unable to reach a verified solution without any context were able to successfully solve the tasks once task-relevant examples were provided in their context.

Is spec lift a real-time process?

No, spec lift is described as an offline score. It is used to evaluate and select the best possible examples for a curriculum before the agent actually begins the search process, allowing for more efficient resource allocation during the actual task execution.


Source: Grafy Research Lab — Agent Memory Scaling Laws for Verified Trainium Kernel Generation