« All posts

How Compiling an AI Agent's Workflow Cut Token Use by 94%

An engineer compiled a recurring AI agent workflow into deterministic code, cutting token use 94% and latency 87% with no quality loss.

The author examines a daily AI agent workflow that drafts LinkedIn posts from a blog archive, showing how a natural-language 'skill' file crystallizes over repeated runs. The original version forced a large language model to re-interpret search, filtering, and selection logic from scratch on every execution—even though most of that behavior had stopped being exploratory.

The fix was feeding historical execution traces and the original natural-language instructions to a powerful model, asking it to distinguish which steps genuinely required an LLM from those that had become stable enough to express as deterministic code. The resulting specialized harness only calls a model for candidate selection and draft writing; everything else runs as plain Python. The measured outcome: 94% fewer tokens, 87% lower latency, and comparable output quality.

The engineering takeaway is that keeping recurring agent workflows entirely in natural language means paying a model to rediscover the same plan every time. The piece also argues that frontier model vendors, whose revenue scales with token consumption, have little incentive to promote this kind of optimization—leaving the opportunity to independent builders and users.