(This blog post is derived from this video on my YouTube channel, along with a short follow-up about the incentives involved.)(本文内容源自本人 YouTube 频道的视频,另附有一篇关于背后激励机制的短文。)

I’ve been writing about specialized agent harnesses and compiling them from task specifications for a while, and I realize the idea can sound abstract. So here’s a concrete example from a workflow I run every day.我钻研“专用代理工具”已有时日,常将任务规范编译为可执行的指令。这念头听来或许玄虚,且容我以每日运行的一套工作流为例,向各位细说分明。

I have a skill that looks through my back catalog of blog posts, finds something worth resurfacing, checks whether I’ve mentioned it recently, and drafts a short LinkedIn post linking back to it. The draft never gets posted automatically. Often I don’t post it at all. Sometimes I use it as a nudge and rewrite the whole thing in my own voice. But the workflow is useful: it nudges me to repost existing writing.我有一项“技能”,能翻检我过往的博客文章,寻出值得重见天日的佳作,核对近期是否提及,再草拟一段 LinkedIn 短文以作引荐。这草稿从不自动发布,我往往也不直接采纳,有时只将其当作灵感,用自己的笔触重写一遍。虽则如此,这套流程颇为受用,总能适时地推我一把,将旧作推陈出新。

The original version was written entirely as natural-language instructions in an Agent Skill. It described the sources to search, the recent-history checks, the selection criteria, and the shape of the final draft. On every run, my agent (currently Codex) had to interpret those instructions, make a plan, call tools, and keep track of the state of the workflow.起初,这套技能全靠自然语言指令驱动。它详述了搜索源、历史核对、筛选标准及草稿的形制。每逢运行,代理(目前用的是 Codex)便需费心研读指令、筹谋计划、调用工具,还要时刻盯着流程的状态。

That was a great way to build the first version. Natural language made the workflow easy to articulate and change. I’ve written before about these files as natlang code: executable SOPs that let an agent automate work without first turning every judgment into a conventional program.这法子在草创之初确是极好的。自然语言让工作流易于表述与变通。我曾写过这类“自然语言代码”:它们如同一份份可执行的标准作业程序(SOP),让代理无需将每一步判断都化作死板的程序,便能自动完成工作。

But after a skill has run many times, and trodden the same ground repeatedly, often most of its behavior is no longer exploratory.然而,当一项技能运行多次,早已轻车熟路,其行为大多已不再需要“探索”了。

The workflow had crystallized工作流已然定型。

This skill always looks in the same places. It builds the same content inventory. It applies the same recent-post filters. It saves the same intermediate state. None of that needs to be reasoned through from scratch each morning. A lot of it doesn’t even need an LLM!这技能寻访之处恒定,整理的素材库亦然,应用的过滤规则更是雷打不动,就连中间状态的保存也如出一辙。这些琐事,何须每日从头推演?甚至有大半,根本无需动用大语言模型!

There are really only two steps where LLMs are needed:真正非要大模型不可的,其实只有两步:

  1. Choosing a good candidate from the filtered inventory.一是从筛选后的素材库中,择出佳作;
  2. Writing the LinkedIn draft.二是撰写 LinkedIn 的草稿。

Everything else can be ordinary deterministic code.除此以外,尽可交给寻常的确定性代码去办。

So I “compiled” the skill into a specialized harness. The new skill is barely a skill at all—it has become a thin bootloader that invokes a Python program. That program fetches the known sources, constructs the inventory, checks recent posts, applies filters, and manages the workflow. It calls an LLM only for selection and generation.于是,我将这套技能“编译”成了一个专用工具。它如今已算不得复杂的技能,更像是一个轻便的引导程序,专门调用 Python 脚本。由脚本去抓取数据、构建库、查记录、做过滤、管流程。唯有在选材与生成时,才请大模型出手。

Not surprisingly, this resulted in massive token usage and latency improvements:果不其然,此举效果惊人,Token 消耗与响应延迟皆大幅改善:

  • 94% fewer tokensToken 消耗减少 94%
  • 87% lower latency延迟降低 87%
  • essentially the same output quality in my runs输出质量与往日几无二致

I didn’t get those gains by swapping in a smaller or cheaper model. The selection and generation steps still use the same model. The savings come from removing all the model calls that were doing work regular code could do more directly.我并非换了更小、更便宜的模型,选材与生成用的仍是原先那套。这省下的功力,全在于剔除了那些本可用普通代码直接处理的冗余模型调用。

A general-purpose coding agent is an extraordinarily capable reasoning and workflow engine. It’s also an expensive way to execute a procedure whose shape becomes known after introspecting on a few historical invocations.通用的编程代理固然是推理与流程编排的绝世高手,但若用它来执行一套早已烂熟于心的流程,未免有些大材小用,且耗费不菲。

What “compiling” means here何谓“编译”?

I had historical traces from running the skill previously (it was running daily as an automation in Codex). Those traces showed what the agent actually did, including the planning, tool calls, branching, and state it needed along the way. I gave those traces, the original skill, and my writing about specialized harnesses to a powerful model. I asked it to identify which steps genuinely required an LLM and which had become stable enough to express as code, then build the specialized harness.我手头留有该技能过往运行的轨迹(此前它作为自动化流程在 Codex 上每日运行)。这些轨迹记录了代理的一举一动,包括筹划、工具调用、分支判断及状态变迁。我将这些轨迹、原始技能及我关于专用工具的心得,一并喂给一个强大的模型,请它辨明哪些步骤真需模型参与,哪些已稳固到可化为代码,进而构建出这套专用工具。

In other words, the natural-language skill served as a high-level specification, while the traces supplied the operational detail that was the result of reasoning by the model.换言之,自然语言技能充当了高层规范,而运行轨迹则提供了模型推理后的实操细节。

This is why I think the compiler analogy is useful. We begin with a flexible, high-level representation of intent. After the workflow has been exercised enough to reveal its real shape, we lower the stable parts into a more efficient representation.这便是为何我推崇“编译”这一比喻。我们始于灵活的高层意图,待工作流运行足够多次、显露真身,便将那些稳定的部分“降维”为更高效的代码。

The model is still used where necessary. The goal of this whole exercise is differentiating between the workflow parts that can be deterministic code and those that need language understanding, generation or reasoning. We haven’t tried to turn language understanding into a pile of brittle rules. Candidate selection depends on what the source says and whether it would make an interesting post. Drafting obviously benefits from language generation. Those remain model calls because they are model-shaped problems.模型在必要之处依然大有用武之地。此举旨在区分:哪些是确定性的代码逻辑,哪些是需要语言理解、生成或推理的智能环节。我们并未试图将语言理解变成一堆僵硬的规则。候选选材取决于原文内容与是否引人入胜,撰写草稿显然离不开语言生成。这些环节依然由模型担纲,因为它们本就是“模型级”的难题。

Start fluid, then optimize先求灵动,再求精进

Writing the specialized harness from day one would have been premature. I didn’t yet know the exact workflow, which rules would matter, or where judgment would be required. The natural-language skill version let me discover those things by running the process repeatedly.若在第一天就强行构建专用工具,未免操之过急。那时我尚不清楚流程细节,不知哪些规则重要,亦不知何处需要人工判断。自然语言版本的技能,让我通过反复运行,摸清了门道。

But keeping the entire workflow in natural language forever would mean paying the model to rediscover the same plan on every run.但若永远将工作流困在自然语言里,便意味着每次运行都要花钱请模型重新推演一遍。

The useful pattern is:这才是正道:

  1. Express the workflow as a natural-language skill.先以自然语言技能表达流程;
  2. Run it enough times to gather traces and refine the behavior.运行多次,收集轨迹,磨砺行为;
  3. Find the parts that have become stable and deterministic.寻出那些已然稳固、确定性强的部分;
  4. Compile those parts into code.将其编译为代码;
  5. Keep LLM calls at the few points where semantic judgment matters.唯有在需语义判断的关键点,才调用 LLM。

There is a one-time cost to this compilation pass. I used a powerful model and a fair amount of context to inspect the traces and produce the new harness. But that cost is paid once. The compiled workflow can then run hundreds or thousands of times, saving tokens and time on every execution. This is standard optimization economics: spend once, amortize over repeated use.编译过程虽有一次性的开销——我用强大的模型和大量上下文来分析轨迹以生成工具——但这代价只付一次。此后,这套编译后的流程可运行成千上万次,次次都在省时省力。这便是优化之道:一次投入,长久受用。

I’ve grown to prefer local agents partly because they accumulate exactly this kind of history: skills, traces, state, and the artifacts of prior runs. That history doesn’t just help the agent remember. It gives us the raw material for making the harness itself better.我愈发偏爱本地代理,正因它们能积累这些历史:技能、轨迹、状态及运行的痕迹。这些历史不仅助代理“记忆”,更成了我们优化工具的宝贵原料。

The long-term economics of agents will depend on this. If every recurring workflow keeps using a frontier model as its planner, state machine, and glue code forever, the cost and latency never really settle down. A specialized harness lets the model concentrate on the small fraction of the workflow that benefits from intelligence.代理的长远经济效益,全系于此。若每个循环往复的工作流都死守着最强模型做规划、做胶水,成本与延迟便永远降不下来。专用工具,能让模型将精力集中在真正需要“智慧”的那一小部分上。

Follow the incentives洞察激励机制

There’s another reason I don’t expect these techniques to come primarily from the big model vendors: their business is selling tokens. Preferably lots of tokens from their most powerful and expensive models.我之所以不指望大模型厂商来推行这些技术,另有缘由:他们的生意是卖 Token。最好是卖出海量 Token,且出自他们最昂贵、最强大的模型。

There’s an old line: it’s very hard to convince someone of something when their salary depends on not understanding it. Incentives explain behavior and outcomes. A technique that preserves output quality while cutting token consumption by 94% goes straight against the current economics of a company whose revenue rises with token usage.古语有云:若一个人的薪水依赖于某种无知,那要让他明白道理,难如登天。激励机制决定了行为与结果。一种能在保持质量的同时削减 94% Token 消耗的技术,简直是砸了那些营收随 Token 消耗增长的公司的饭碗。

I’m not claiming that nobody inside those companies cares about efficiency. Obviously they do. Better inference, caching, and cheaper models make their products more useful. But there’s a difference between making each token cheaper and helping a customer discover that most of their workflow doesn’t need tokens at all.我并非说大厂里无人关心效率。他们当然关心。更好的推理、缓存与更便宜的模型,能让产品更易用。但“让每个 Token 更便宜”与“帮用户发现大部分工作流根本无需 Token”,这两者之间有着天壤之别。

At least right now, I don’t see much incentive for the major vendors to push that second idea hard. So it’s up to users and independent builders to find these optimization opportunities ourselves.至少眼下,我看不出大厂有何动力去推行后者。所以,还得靠我们这些用户与独立开发者,亲自动手去挖掘优化的机会。

And that’s also the opportunity. There’s a large open space for founders building specialized harnesses, compilers, and tools that examine recurring agent workflows and move the deterministic parts into code. The value proposition is unusually concrete: keep the output quality, while cutting the cost and latency of producing it.这恰恰是机遇所在。构建专用工具、编译器与分析工具的舞台广阔,只要能看清代理工作流的本质,将确定性的部分转化为代码,价值便实实在在:质量不变,成本与延迟骤降。

The model vendors will keep building more powerful engines. Someone still has to make sure we aren’t revving those engines to do simple, deterministic work.模型厂商会造出更强的引擎,但我们仍需把关,莫要让这些引擎被用在那些简单、确定性的琐事上。

Use natural language to discover the workflow. Use traces to understand it. Then compile what has crystallized.先以自然语言探索流程,以轨迹参悟逻辑,最后,将那些已然结晶的部分编译成器。

Want to try it yourself? Grab the full Token Shrinker prompt and drop it into your agent.想试上一试?拿去这份“Token 缩减”提示词,丢进你的代理里吧。