An agent that answers the same question a hundred times plans the answer a hundred times. It should plan it once.
Every app built in Sycamore Build comes with its own agent. Take a support desk. Its agent answers questions about customers and resolves tickets by calling the app’s data tools. Ask it what’s open for a customer and it makes a short plan on the spot: look up the customer, find their account, list their open tickets, then fetch the context for each ticket. Each step is a model decision followed by a tool call.
The hundredth time that question arrives, the agent makes the same plan again. It pays the same latency and tokens, and gets another chance to get a step wrong. People turn this kind of repetition into habit. “Civilization advances,” Alfred North Whitehead wrote in 1911, “by extending the number of important operations which we can perform without thinking about them.” In Enterprise Software Should Keep Up we argued that the fiftieth change should cost less than the first. The fiftieth answer should too.
The fix is well known. Anthropic’s advice on writing tools for agents is to fold steps like these into one tool: a single get_customer_context in place of separate tools for the customer, their transactions and their notes. The hard part is choosing which plans deserve it. Every tool you add is one more the agent has to read and weigh: in one example setup, Anthropic counted 58 tools taking about 55,000 tokens before a conversation starts. A tool that saves nothing still costs something.
We built a prototype that makes this choice from the agent’s own run records. It follows one rule: compile a procedure only when the tool calls it removes outweigh the cost of defining the new tool. On a test support desk, the rule passed over the agent’s most common pattern and picked a less common one. For the customer lookups it picked, data-tool calls per turn fell from 5.5 to 1.0 and average latency from 31 seconds to 18. That was on synthetic traffic, with six runs after the change, so the numbers show a direction and will move.

The plan the agent made fresh on every lookup became one tool with one parameter.
The test desk
We specified a support desk in Sycamore Build, seeded it with synthetic customers and tickets, and held synthetic conversations with its agent, several turns each. That gave us 149 usable runs, one per agent turn. 143 came before we compiled anything: 93 questions about customers, 34 ticket briefings and 16 one-off requests. The other six came after.
How the miner works
The miner turns run records into candidate tools in five steps.

The miner’s five steps. Only the last one decides.
First, it cleans the records. It drops failed calls, counting a call as failed when its response says so, even if the transport reported success.
Second, it folds repetition. When the agent makes the same call several times and every changing argument comes from one earlier response, as when it fetches each ticket in a list, the miner writes it down once, as a step that repeats for each item.
Third, it groups runs whose cleaned call sequences match exactly. The 93 customer questions fell into 18 shapes. The largest, 26 runs, was the customer lookup.
Fourth, it works out what each argument is by comparing its values across a group. A value that never changes is a constant, written into the tool. A value that appeared in an earlier response in the same run is derived, and the tool passes it along itself. A value that walks through an earlier list becomes a repeated step. Anything left over becomes a parameter. The customer lookup needed one: the customer’s name.
This is anti-unification. You take several expressions and find the most specific pattern that fits all of them, turning whatever differs into a variable. Gordon Plotkin described it in 1970 as a way to generalize from examples in logic, and program synthesis uses it today. We apply it to tool calls.
Fifth, it scores each candidate by compression: the tool calls it would remove across every matching run, minus the cost of defining it, also counted in tool calls. A candidate is compiled only if the score is positive. There is no frequency threshold.
For the customer lookups, the miner produced open_tickets_for(customer_name). It returns the customer, their open tickets and each ticket’s context in one result. We wired it into the app by hand, in four edits: the tool’s code, the tool registry, the agent’s skill guidance and the list of read tools the agent may use.
Savings beat frequency
The most common shape in the records was the ticket briefing. All 34 briefing runs had the same shape, more than the 26 in the largest customer shape. A rule that ranked by frequency would have compiled the briefing first.
The compression rule turned it down. A briefing was already a single call. Wrapping it in a new tool would remove nothing and give the agent one more tool to choose from.
The customer lookup was less common, but it took about five and a half calls each time. Compiled, it takes one. That removes about four and a half calls from each of its 26 runs, far more than the cost of one definition.

Count runs and the briefing wins. Count the calls a tool would remove and the lookup wins.
Frequency tells you what repeats. Compression tells you whether turning the repetition into a tool removes any work, and that is the question that pays.
Others mine agent traces for composite tools too. AWO, from Abuzakuk and colleagues at EPFL, keeps only the transitions that a set number of runs took and merges the busiest first. Experts decide which steps count as the same, and the authors pick which tools the agent gets. Our rule has no count threshold and charges every candidate for being one more tool, so a pattern that saves nothing never becomes a tool, however often it shows up.
What changed
First we checked that the tool does what the agent did. We replayed each of the 26 mined runs through open_tickets_for with that run’s input. In all 26, the tool made the same underlying calls the agent had made.
Then we measured, on the six runs after the change. On customer lookups, data-tool calls fell 82% and average latency 42%.

Customer lookups before and after compiling, on synthetic traffic. The after set is six runs.
Total tool calls fell by less, from 5.5 to 3.2. The difference is the cost of finding the new tool. Before calling it, the agent searched its tool list and read the tool’s description, about two extra calls a turn. That cost grows with every tool you add, so any measurement of compiled tools should count it. A tool that saves one call and takes two to find is a loss.
Across all customer questions, including the ones the new tool doesn’t cover, data calls fell from 3.8 to 1.3 per turn, total calls from 3.8 to 3.3, and latency from 26 seconds to 19.

All customer questions, compiled tool or not. The after set is six runs.
The records found a bad description
The records showed us something else. In 34 of the 93 customer questions, 37%, the agent guessed the same wrong column name, got an error and tried again. The miner drops failed calls before grouping, so these retries didn’t distort the patterns.
When an agent makes the same mistake on more than a third of runs, the gap is in what we told it. So the records that show what to compile also show what to document. Anthropic found the same in its own transcripts: when Claude kept adding the year to its search queries, the fix was a better tool description.
Writes need more evidence
The tool we compiled only reads. If it gets something wrong, someone sees a wrong answer and asks again. A procedure that refunds a customer or closes a ticket takes the model’s judgment out of a step that changes something, so it should need more evidence than 26 matching runs, and a person’s approval. TraceCompiler, the closest work to ours, refuses to compile when the traces leave an irreversible step unclear. We’d go further and treat a compiled write like any other change to an agent: it earns its autonomy on evidence.
Old ideas in a new place
Most of this is old. Library learning systems such as DreamCoder, Stitch and LILO choose abstractions by how much they compress a body of programs, and LILO found that having a language model document each abstraction helps it get used. In reinforcement learning, LOVE learns reusable skills with a penalty on how long they take to describe.
TraceCompiler (El Yadouni and Li, 2026) sorts tool-call arguments much as our miner does, into constants, user inputs, copied outputs, transforms and leftover model decisions, and tests on public benchmarks. Its abstract opens with the problem this post is about: “Tool-using language-model agents repeatedly rediscover procedures they have already executed.” Its authors count the calls compiling removes but not what compiling costs, so they claim no net saving.
Anthropic’s work on code execution comes at it from the other side: an agent that calls its tools from code can save that code as a reusable function. A savings rule is one way to decide which functions are worth keeping.
What we add is a worked case on an app builder’s own run records, where a savings rule overruled frequency, and an after measurement that counts what it costs the agent to find the new tool.
The case is small. Its value is in what it tells us to measure next. Does a compression rule keep picking the right tools on real traffic? Do compiled tools give the same final answers, beyond making the same calls? How much does finding tools cost once an app has several compiled tools?
An agent should get faster at the work it does most. The way to get there is to count what each shortcut saves, including what it costs to find.

