agent-jit

A tracing-JIT runtime for tool-using LLM agents

View the Project on GitHub Rayyan-Oumlil/agent-jit

I tried to compile an LLM agent into code. Here is what worked and what didn’t.

Many production agents do the same multi-step job over and over: look up an order, check its state, issue a refund, say so in one sentence. Every run pays an LLM to re-discover the same tool sequence. agent-jit is a small library that watches an agent do this, and after it has seen a task shape twice, compiles it into a guarded Python function. One cheap routing call picks the function, the function makes the tool calls, and if any guard fails mid-run the job is handed back to the agent as already-executed tool history. The agent is never replaced, only skipped when it is safe to skip it.

How it works, in four steps

  1. Trace. Record each run’s tool calls and results (SQLite).
  2. Bind. For every tool argument, find where it came from: the request text, an earlier tool’s output, or a constant. Anything that cannot be explained is refused, not guessed.
  3. Guard. Record facts that held in every trace (types, non-null, a status string, a list length). At run time a violated guard stops the skill before the next tool call.
  4. Route and fall back. A single LLM call chooses a skill and its parameters; plain text checks verify the choice. On failure the agent resumes from the completed steps and nothing is executed twice, because a write-ahead journal sits at the tool boundary.

What I measured

All numbers are from scripts in benchmarks/ and are reproduced in the README with their commands.

On a support-desk workload built to repeat (6 request types, 36 requests, Haiku 5.5, 3 seeds), agent-jit and the plain agent both got 108/108 right. Tokens were 99,326 vs 75,016 on average, a 24% saving (range 19% to 33%). The compiler itself costs no tokens, since it is deterministic code.

The honest dollar figure is smaller: about 6%. Most of the plain agent’s tokens are cheap cache reads, while agent-jit’s router prompt is not cached. If you only look at token counts you overstate the saving.

On AppWorld, a benchmark where tasks do not repeat, agent-jit saved nothing. It compiled zero skills. Variants of a scenario differ in logic and length (11 distinct tool sequences in 12 successful runs), and the one pair that did repeat needed a computed answer that cannot be traced to a tool output. A tool like this only pays off when traffic actually repeats, and I can tell you how well it does when it does, not how often that happens in your system.

When wording stops repeating, the saving is not guaranteed. I reworded 0 to 100% of the desk’s requests (mock policy, three seeds). Success stayed 36/36, but the token change against the plain agent ranged from about -29% to +10%: requests that match no skill still pay the router call. One seed used 10% more tokens than the plain agent.

The cheap alternatives are wrong, not just worse. A semantic cache and a replay-the-first-run baseline hit on 83% of the workload and were correct on 22%: “refund order 7867” is lexically close to “refund order 2688”, so they act on the old id.

What went wrong along the way

What I do not claim

Try it

pip install -e ".[dev]" then python -m agent_jit.demo runs a toy end to end with no API key. The README lists every measured result with the command that reproduces it.