Glean 拾遗
Daily /2026-08-04 / Improving token efficiency in GitHub Agentic Workflows

Improving token efficiency in GitHub Agentic Workflows

Source github.blog Glean’d 2026-08-04 06:00 Read 18 min
AI summary

GitHub's team instrumented its own fleet of Agentic Workflows through an API proxy, emitting a normalized token-usage.jsonl per run and building two daily agentic workflows—a usage Auditor and an Optimizer—that read those logs, flag anomalies, and file concrete optimization issues. The biggest wins came from pruning unused MCP tool registrations (each request can carry 10–15KB of schema overhead), replacing GitHub MCP calls with deterministic GitHub CLI invocations, and moving fixed data-gathering into pre-agentic setup steps. To compare across models they define Effective Tokens: ET = m×(1.0×I + 0.1×C + 4.0×O) with model multipliers. Of 12 production workflows, nine received optimizer changes; measured reductions were 62% for Auto-Triage Issues (109 runs), 43% for Security Guard, and 59% for Smoke Claude. One workflow regressed 5% due to workload shift, and one misconfigured bash allowlist caused a 64-turn fallback loop. The post argues for episode- and portfolio-level efficiency analysis.

Original · 18 min
github.blog ↗
§ 1

Agentic workflows that run on every pull request can quietly accumulate large API bills. Here’s how we instrumented our own production workflows, found the inefficiencies, and built agents to fix them.

GitHub Agentic Workflows is like a team of street sweepers that clean up little messes in your repo. These teams significantly improve repo hygiene and quality, but as with all agentic work, cost is a growing concern for developers. And because CI jobs like agentic workflows are automatically scheduled and triggered, costs can accumulate out of view.

Thankfully, making automations more efficient is easier than doing the same for interactive desktop sessions. Work done during a developer session can be hard to predict, but agentic workflows’ work is fully specified in YAML and repeats every execution.

Because we maintain and use GitHub Agentic Workflows in our own GitHub repositories, we worry about token efficiency as much as our users. That is why in April 2026, we began to systematically optimize the token usage of many of the workflows that we rely on every day. This post describes what we instrumented, the optimizations we applied, and our preliminary results.

在每个 pull request 上运行的代理工作流(agentic workflows)会悄无声息地累积大量 API 费用。本文将介绍我们如何为自己的生产工作流增加埋点、发现低效点,并构建代理来修复它们。

GitHub Agentic Workflows 就像一队街道清扫车,负责清理仓库里的小垃圾。这些“车队”显著改善了仓库的卫生与质量,但与所有代理工作一样,成本正成为开发者越来越关心的问题。而且,由于 agentic workflows 这类 CI 任务是自动调度、自动触发的,成本可能在视线之外悄然堆积。

幸好,让自动化变得更高效,比让交互式桌面会话更高效要容易得多。开发者在会话中的工作难以预测,而 agentic workflows 的执行内容完全由 YAML 定义,并且每次执行都会重复。

因为我们既维护又在自己的 GitHub 仓库中使用 GitHub Agentic Workflows,所以我们和用户一样关心 token 效率。正因如此,2026 年 4 月,我们开始系统性地优化许多日常依赖工作流的 token 用量。这篇文章介绍了我们做了哪些埋点、应用了哪些优化,以及初步结果。

§ 2

We rely on hundreds of agentic workflows in our repos for maintenance and CI. All workflows run as GitHub Actions against real API rate limits. We are building the plane as we fly it and burning jet fuel as we go.

Before we could optimize our token consumption, we needed to know how tokens were consumed. The first challenge we faced was that each agent framework (Claude CLI, Copilot CLI, Codex CLI) emitted logs in a different format, and usage data could be incomplete for historical runs. Thankfully, the agentic-workflows security architecture uses an API proxy to prevent agents from directly accessing authentication credentials. This proxy gave us a way to capture token usage across all runs in a single normalized format, regardless of agent framework.

Every workflow now outputs a token-usage.jsonl artifact with one record per API call that contains input tokens, output tokens, cache-read tokens, cache-write tokens, model, provider, and timestamps. Combining this data with the rest of the workflow’s logs gave a historical view of how tokens were typically spent and allowed us to optimize for future runs.

我们在仓库中依赖数百个 agentic workflows 来做维护和 CI。所有工作流都以 GitHub Actions 的形式运行,并受真实 API 速率限制约束。我们一边飞行一边造飞机,同时也在一路消耗燃油。

在优化 token 消耗之前,我们需要先知道 token 是怎么消耗的。我们面对的第一个挑战是:每个代理框架(Claude CLI、Copilot CLI、Codex CLI)产出的日志格式都不一样,而且历史运行的用量数据可能不完整。幸运的是,agentic-workflows 的安全架构使用 API 代理,防止代理直接接触认证凭据。这个代理让我们能以统一的标准化格式捕获所有运行的 token 用量,无论底层是哪个代理框架。

现在,每个工作流都会输出一个 token-usage.jsonl 产物,每条记录对应一次 API 调用,包含输入 token、输出 token、缓存读取 token、缓存写入 token、模型、提供方和时间戳。将这些数据与工作流的其余日志结合起来,就能看到历史上 token 通常花在了哪里,从而为未来的运行做优化。

§ 3

With token data in hand, we built two daily optimization workflows.

A Daily Token Usage Auditor reads token usage artifacts from recent workflow runs, aggregates consumption by workflow, and posts a structured report. Its job is to flag any workflow that has significantly increased its recent usage, surface the most expensive workflows, and take note of anomalous runs (e.g., a workflow that normally completes in four LLM turns taking 18).

When an Auditor flags a workflow, a Daily Token Optimizer looks at the workflow’s source and recent logs to create a GitHub Issue describing concrete inefficiencies and proposing specific optimization. The Optimizer has found many inefficiencies that we would have otherwise missed.

Of course, the Auditor and Optimizer are agentic workflows themselves, and their token usages also appear in daily reports to create a small virtuous cycle.

拿到 token 数据后,我们构建了两个每日优化工作流。

Daily Token Usage Auditor(每日 token 用量审计器)会读取近期工作流运行的 token 用量产物,按工作流汇总消耗,并发布一份结构化报告。它的职责是标记那些近期用量显著上升的工作流、列出最贵的工作流,并记录异常运行(例如某个通常四轮 LLM 就能完成的工作流,这次却用了 18 轮)。

当审计器标记某个工作流后,Daily Token Optimizer(每日 token 优化器)会查看该工作流的源码和近期日志,创建一个 GitHub Issue,描述具体的低效之处并提出针对性优化。优化器已经发现了许多我们本来会漏掉的低效点。

当然,审计器和优化器本身也是 agentic workflows,它们的 token 用量同样会出现在每日报告中,形成一个小的良性循环。

§ 4

Based on our initial Auditor and Optimizer results, the most common inefficiency is unused MCP tool registrations.

Because LLM APIs are stateless, agent runtimes typically include the MCP tool function names and JSON schemas with each request. In practice, this means the full set of tools can become part of every call’s context. For a GitHub MCP server with 40 tools, this can add 10–15 KB of schema per turn. If the agent only uses two tools, the remaining 38 are pure overhead added to every request.

Workflow authors naturally start with a full tool-set since it is the path of least resistance, and the agent can figure out which tools it needs. But as time goes on, most workflows rely on a narrow, stable set of tools. The Optimizer identifies this pattern by cross-referencing tool manifests against actual tool calls and recommends pruning unused tools from the configuration.

In our smoke-test workflows, removing unused tools from the MCP configuration reduced per-call context size by 8–12 KB, saving several thousand tokens per run with no change in behavior.

根据审计器和优化器最初的结果,最常见的低效是未使用的 MCP 工具注册。

由于 LLM API 是无状态的,代理运行时通常会在每个请求中携带 MCP 工具的函数名和 JSON schema。实际上,这意味着全部工具都会成为每次调用的上下文的一部分。对于一个包含 40 个工具的 GitHub MCP server,每轮对话可能因此多出 10–15 KB 的 schema。如果代理实际只用两个工具,其余 38 个就是叠加在每次请求上的纯开销。

工作流作者自然一开始就配置完整工具集,因为这是阻力最小的路径,代理自己会判断需要哪些工具。但随着时间推移,大多数工作流只依赖一个狭窄且稳定的工具子集。优化器通过把工具清单与实际工具调用交叉对照来识别这种模式,并建议从配置中剪掉未使用的工具。

在我们的 smoke-test 工作流中,从 MCP 配置里移除未使用的工具,使每次调用的上下文体积减少了 8–12 KB,每次运行节省几千个 token,且行为没有任何变化。

§ 5

Removing unused MCP tools is a relatively simple win. A larger structural opportunity was replacing GitHub MCP calls for data-fetching operations like retrieving pull request diffs, file contents, and review comments with calls to the GitHub CLI.

This change did more than reduce the overhead of unused tools because an MCP tool call is a reasoning step in addition to data retrieval. The agent must decide to call the tool, formulate its arguments, and receive its output as part of the context. That’s a full round-trip LLM API call, consuming tokens for the tool-use JSON schema, the argument block, and the response. Calling gh pr diff, by contrast, is a deterministic HTTP request to GitHub’s REST API with no LLM involvement.

We used two strategies for this migration:

Pre-agentic data downloads. For data that an agent will always need like a pull request diff or the list of changed files, we added setup steps in the workflow that run gh commands before the agent starts and writes the results to workspace files. The agent reads those files instead of making MCP calls. This eliminates tool-call overhead and allows the agent to take advantage of its extensive training in bash scripting to efficiently process the data.

In-agent CLI proxy substitution. Pre-downloading isn’t possible in cases where the agent determines what to fetch at runtime. In these cases we rely on a lightweight transparent HTTP proxy that routes CLI traffic to GitHub’s API servers without exposing an authentication token to the agent. The agent runs gh pr view –json and gets structured data back, just as a user would from a terminal. This reduces token usage without compromising our zero-secrets security requirement for the agent.

Together, these techniques move the majority of GitHub data-fetching out of the LLM reasoning loop.

移除未使用的 MCP 工具是一个相对简单的胜利。更大的结构性机会,是把获取 PR diff、文件内容、review 评论等数据抓取操作从 GitHub MCP 调用换成 GitHub CLI 调用。

这个改变不只是减少了未使用工具的额外开销,因为一次 MCP 工具调用除了取数以外,本身还是一个推理步骤。代理必须决定调用哪个工具、组织参数,并把输出作为上下文的一部分接收。这是一次完整的 LLM API 往返,会消耗工具 JSON schema、参数块和响应三部分的 token。相比之下,调用 gh pr diff 是对 GitHub REST API 的一次确定性 HTTP 请求,完全不涉及 LLM。

我们用了两种迁移策略:

代理前的数据下载。对于代理永远需要的数据,比如 PR diff 或变更文件列表,我们在工作流中增加 setup 步骤:在代理启动之前运行 gh 命令,把结果写入工作区文件。代理读取这些文件,而不是调用 MCP。这样既消除了工具调用开销,又能让代理利用其丰富的 bash 脚本训练来高效处理数据。

代理内 CLI 代理替换。在代理运行时才决定要获取什么的情况下,无法预先下载。这时我们依赖一个轻量级透明 HTTP 代理,把 CLI 流量路由到 GitHub 的 API 服务器,同时不向代理暴露认证 token。代理运行 gh pr view –json,得到结构化数据,就像用户在终端里操作一样。这降低了 token 用量,也没有损害代理“零密钥”的安全要求。

这两项技术合在一起,把绝大多数 GitHub 数据抓取移出了 LLM 推理循环。

§ 6

Once we began to optimize our workflows, we ran into a more nuanced problem: how do you know whether a change made things more efficient, or just made the workflow do less (and perhaps worse) work?

There are three confounding factors.

开始优化工作流后,我们遇到了一个更微妙的问题:你怎么知道某个改动是让事情变得更高效,还是只是让工作流做得更少(甚至更差)?

这里有三个干扰因素。

§ 7

Not all tokens are created equal. Running the same workflow on Claude Haiku versus Claude Sonnet produces similar token counts but cost very differently. Haiku costs roughly 4× less per token than Sonnet, so a workflow that switches models appears unchanged in raw token count but represents a significant cost reduction. To account for this, we use an Effective Tokens (ET) metric that applies model multipliers to each token type:

ET = m × (1.0 × I + 0.1 × C + 4.0 × O)

where m is a model cost multiplier (Haiku = 0.25×, Sonnet = 1.0×, Opus = 5.0×), I is newly-processed input tokens, C is cache-read tokens, and O is output tokens. Output tokens carry 4× weight because they are the most expensive token type across all major providers. Cache-read tokens carry only 0.1× weight because they are served from cache at a fraction of the cost of fresh input. This formula normalizes consumption across model tiers so that a 10% ET reduction means a genuine 10% cost reduction regardless of which model is in use.

并非所有 token 都平等。在 Claude Haiku 和 Claude Sonnet 上运行同一个工作流,token 数量可能差不多,但成本差异巨大。Haiku 每 token 的成本大约只有 Sonnet 的 1/4,所以一个工作流如果切换了模型,原始 token 数看起来没有变化,实际成本却显著下降。为了把这一点纳入考量,我们使用有效 token(Effective Tokens,ET)指标,为每种 token 类型套用模型乘数:

ET = m × (1.0 × I + 0.1 × C + 4.0 × O)

其中 m 是模型成本乘数(Haiku = 0.25×,Sonnet = 1.0×,Opus = 5.0×),I 是新处理的输入 token,C 是缓存读取 token,O 是输出 token。输出 token 权重为 4 倍,因为它们在所有主流 provider 中都是最贵的 token 类型。缓存读取 token 权重只有 0.1 倍,因为它们从缓存读取,成本只有新输入的几分之一。这个公式把消耗按模型档次归一化,使得 ET 降低 10% 就意味着真实成本降低 10%,无论使用哪个模型。

§ 8

The workload is a live repository. As far as we know, there is no agentic-workflow benchmark that we can use to optimize our token usage. When we began looking at token usage by our workflows, we found that in one run a workflow would handle a five-line fix, and in the next run it would handle a 200-line pull request. The first run naturally uses fewer tokens, but the difference is not due to a sudden change in efficiency. Raw token counts can confuse workload variation with fluctuations in efficiency. We try to normalize this by tracking LLM API call counts alongside token counts; constant LLM turns-per-run and falling tokens-per-call indicate genuine efficiency improvement. Both falling together may indicate that less work is being done.

工作负载是一个活仓库。据我们所知,目前没有可用于优化 token 用量的 agentic-workflow 基准。当我们开始观察各工作流的 token 用量时,发现某次运行处理的是一个五行修复,下一次运行处理的是一个 200 行的 pull request。第一次运行自然用更少 token,但差异并非来自效率的突变。原始 token 数很容易把工作负载的变化和效率波动混为一谈。我们尝试通过同时记录 LLM API 调用次数来归一化:每次运行的 LLM 轮数不变、每调用 token 数下降,才说明效率真正提升;如果两者同时下降,可能说明实际做的工作变少了。

§ 9

Does quality change? Understanding output quality is the hardest consideration. A lighter model running a more constrained workflow might produce lower-quality output. We looked at the process-level signals like output tokens per LLM call, turn counts per run, and tool-call completion rates to approximate quality. For our optimized Smoke Copilot workflow, all three remained stable across the optimization period even as token consumption fell. The workflow completes in roughly five LLM turns every run, before and after the optimizations. Of course, these are process signals, not outcome signals. We cannot directly observe whether the quality improved, degraded, or was stable, because there is no ground-truth “correctness.” Measuring tokens-per-unit-of-correct-work requires additional instrumentation and thought.

质量变了吗?理解输出质量是最难的一环。一个更轻量的模型跑一个约束更强的工作流,可能会产生更低质量的输出。我们观察了每 LLM 调用的输出 token、每次运行的轮数、工具调用完成率等过程信号,来近似判断质量。在我们优化后的 Smoke Copilot 工作流中,这三项指标在整个优化期间都保持稳定,即使 token 消耗在下降。优化前后,该工作流每次运行都稳定在约五个 LLM 轮。当然,这些都是过程信号,而不是结果信号。我们无法直接观察质量是变好、变差还是保持不变,因为没有“正确性”的真实答案。要度量“每单位正确工作的 token 数”,还需要额外的埋点和思考。

§ 10

After deploying the auditor and optimizer across a dozen production workflows in the gh-aw and gh-aw-firewall repos, we downloaded token-usage artifacts for runs before and after each was optimized and computed ET for each run. Nine of the 12 workflows received optimizer-recommended changes. We include results only for workflows with at least eight runs in both the pre- and post-optimization periods. These are: Auto-Triage Issues, Daily Compiler Quality, Community Attribution, Security Guard, and Smoke Claude.

Graph showing token savings across Auto-Triage Issues, Daily Compiler Quality, Community Attribution, Security Guard, adn Smoke Claude.

Auto-Triage Issues shows a clear, sustained reduction of 62% across 109 post-fix runs. Daily Compiler Quality shows 19% improvement over 12 post-fix runs, and Daily Community Attribution shows 37% improvement over eight post-fix runs. In the gh-aw-firewall repo, Security Guard, which audits every pull request for security-sensitive changes, and Smoke Claude an integration test that exercises the firewall’s Claude CLI path, had the most post-fix runs and show improvements of 43% and 59%, respectively.

在 gh-aw 和 gh-aw-firewall 两个仓库的十几个生产工作流中部署审计器和优化器之后,我们下载了每个工作流优化前、后运行的 token 用量产物,并计算每次运行的 ET。12 个工作流中有 9 个采用了优化器建议的改动。我们只纳入那些在优化前、后各至少有 8 次运行的工作流结果,它们是:Auto-Triage Issues、Daily Compiler Quality、Community Attribution、Security Guard 和 Smoke Claude。

图表显示了 Auto-Triage Issues、Daily Compiler Quality、Community Attribution、Security Guard 和 Smoke Claude 的 token 节省情况。

Auto-Triage Issues 在修复后的 109 次运行中显示出明确、持续的 62% 下降。Daily Compiler Quality 在修复后的 12 次运行中改善了 19%,Daily Community Attribution 在 8 次运行中改善了 37%。在 gh-aw-firewall 仓库中,Security Guard(审计每个 pull request 的安全敏感改动)和 Smoke Claude(一个测试防火墙 Claude CLI 路径的集成测试)的修复后运行次数最多,分别改善了 43% 和 59%。

§ 11

Run frequency matters as much as per-run savings. Auto-Triage Issues fires on every new issue (averaging 6.8 runs per day with a max of 15) while Daily Compiler Quality runs at most once per day. 62% savings and 6.8 runs/day compounds quickly: over the observation period, Auto-Triage’s optimization saved roughly 7.8 M ET in aggregate, assuming the pre-optimization rate. Security Guard and Smoke Claude run even more frequently. When prioritizing which workflows to optimize, run frequency is as important as per-run consumption.

运行频率和单次节省同样重要。Auto-Triage Issues 在每个新 issue 上触发(平均每天 6.8 次,最高 15 次),而 Daily Compiler Quality 最多每天一次。62% 的节省叠加每天 6.8 次,复利效应很快:在观察期内,按优化前的速率估算,Auto-Triage 的优化累计节省了约 780 万 ET。Security Guard 和 Smoke Claude 运行得更频繁。在决定优先优化哪些工作流时,运行频率与单次消耗一样重要。

§ 12

It is important to note that not every optimization that the agent recommends translates into measurable ET savings, especially over short observation windows on a live repository where workload varies day to day. For example, the Contribution Check workflow experienced a 5% increase in ET, and we will discuss it in greater detail below.

需要指出的是,并非优化器建议的每个优化都能转化为可衡量的 ET 节省,尤其是在活仓库中、短观察窗口内、工作负载每天都在变化的情况下。例如,Contribution Check 工作流的 ET 反而上升了 5%,我们稍后会详细讨论。

§ 13

Based on these results, we highlight three patterns.

Many agent turns are deterministic data-gathering. Auto-Triage Issues shows the strongest sustained improvement in gh-aw (−62% across 109 post-fix runs) because the optimization eliminated structural inefficiency: many agent turns were spent on reads that required no inference, such as fetching issue metadata and scanning labels. Moving those reads into pre-agentic CLI steps before the agent starts removed them from the LLM reasoning loop entirely. The same pattern drove Security Guard’s −43% reduction in gh-aw-firewall: a relevance gate now skips the LLM entirely for pull requests that don’t touch security-sensitive files. The cheapest LLM call is the one you don’t make.

基于这些结果,我们重点强调三个模式。

许多 agent 回合是在做确定性的数据收集。Auto-Triage Issues 在 gh-aw 中展现出最强劲的持续改善(修复后 109 次运行中下降 62%),因为优化消除了结构性低效:大量 agent 回合花在不需要推理的读取上,比如获取 issue 元数据、扫描标签。把这些读取移到 agent 启动前的 CLI 步骤中,就彻底把它们移出了 LLM 推理循环。同样的模式也带来了 gh-aw-firewall 中 Security Guard 43% 的下降:现在,一个相关性闸门会让不涉及安全敏感文件的 pull request 完全跳过 LLM。最便宜的 LLM 调用,就是你根本没有发起的那个。

§ 14

Contribution Check illustrates a confounding factor: 82–83% of input tokens were cache reads (data-gathering), but average ET increased 5%. This is due to a workload shift rather than optimization failure: in the pre-optimization period 41% of runs processed small pull requests (ET < 100K) and 39% processed large pull requests (ET > 300K). The post-optimization period coincided with a burst of development activity, and the workflow processed 9% small pull requests and 65% large pull requests. Output tokens, which carry a 4× weight in the ET formula, rose 14% as the agent reviewed bigger diffs. The optimization likely improved per-turn efficiency, but the shift toward heavier workloads masks that gain in the aggregate numbers.

Contribution Check 正好说明了一个干扰因素:82%–83% 的输入 token 都来自缓存读取(即数据收集),但平均 ET 却增加了 5%。这是工作负载变化造成的,而不是优化失败:在优化前,41% 的运行处理的是小型 pull request(ET < 100K),39% 处理的是大型 pull request(ET > 300K)。优化后这段时间恰好赶上开发活动高峰,工作流处理了 9% 的小型 pull request 和 65% 的大型 pull request。由于代理要审查更大的 diff,在 ET 公式中权重为 4 倍的输出 token 增加了 14%。优化很可能确实提升了单轮效率,但更重的工作负载在总量上掩盖了这部分收益。

§ 15

Unused tools are expensive to carry. Among the excluded gh-aw workflows, the Glossary Maintainer is an instructive case. A single tool—search_repositories—was called 342 times in one run, accounting for 58% of all tool calls, despite being completely unnecessary for a workflow that only scans local file changes. Removing it from the toolset was the optimizer’s recommendation. In gh-aw-firewall, Smoke Claude’s −59% reduction was driven in part by aggressive MCP tool pruning combined with a model-tier switch to Haiku. The Daily Community Attribution workflow illustrates the limits of this approach: it was configured with eight GitHub MCP tools and made zero calls to any of them across an entire run, but removing them did not reduce ET. Tool manifests were a small fraction of this workflow’s overall context.

闲置工具带着很贵。在被排除的 gh-aw 工作流中,Glossary Maintainer 是一个很有教育意义的案例。一个名为 search_repositories 的工具在一次运行中被调用了 342 次,占所有工具调用的 58%,而这个工作流只需要扫描本地文件变更,完全用不到它。优化器给出的建议就是把它从工具集中移除。在 gh-aw-firewall 中,Smoke Claude 59% 的下降部分来自激进的 MCP 工具修剪,加上把模型档次切换到 Haiku。Daily Community Attribution 工作流则展示了这种做法的局限:它配置了八个 GitHub MCP 工具,但整整一次运行中一个都没调过,移除它们也没有让 ET 下降。工具清单只占该工作流总上下文的一小部分。

§ 16

A single misconfigured rule can cause runaway loops. Also among the excluded workflows, Daily Syntax Error Quality was the highest-ET workflow in the project before optimization. The root cause was a one-line misconfiguration: the workflow copied test files to /tmp/ then called gh aw compile*, but the sandbox’s bash allowlist only permitted relative-path glob patterns. Every compile attempt was blocked. Unable to use the tool it needed, the agent fell into a 64-turn fallback loop in which it manually read source code to reconstruct what the compiler would have told it. One fix to the allowed bash patterns eliminated the loop. We did not have enough baseline runs to precisely quantify the improvement, but the pathology was clear and the fix was unambiguous.

一行错误的配置就可能引发失控循环。同样在被排除的工作流中,Daily Syntax Error Quality 在优化前是整个项目里 ET 最高的工作流。根因是一行配置错误:工作流先把测试文件复制到 /tmp/,然后调用 gh aw compile*,但沙箱的 bash 允许列表只允许相对路径的 glob 模式。结果每次编译尝试都被阻止。由于无法使用它需要的工具,agent 陷入了一个 64 轮的 fallback 循环:它手动阅读源码,去重建编译器本来会告诉它的信息。只需修复允许的 bash 模式,循环就消失了。我们没有足够的基线运行来精确量化改进幅度,但病根很清晰,修复也是明确的。

§ 17

The tools we use to optimize our workflows including API-level observability, automated auditing workflows, MCP tool pruning, and CLI substitution are all available today in the GitHub Agentic Workflows framework. Another upcoming optimization is refactoring monolithic agents into teams of subagents using smaller and cheaper models.

我们用来优化工作流的这些工具,包括 API 级可观测性、自动化审计工作流、MCP 工具修剪和 CLI 替换,今天在 GitHub Agentic Workflows 框架中都已可用。另一个即将到来的优化,是把单体代理重构为使用更小、更便宜模型的子代理团队。

§ 18

The next step is to move from workflow-level optimization to system-level optimization. A workflow run is not really one flat sequence of API calls. It is a chain of episodes: short phases of work like gathering context, reading artifacts, retrying after a failure, or synthesizing a final answer. Once you can see those episodes clearly, you can ask much better questions. Which episode actually caused a costly run? Which episodes are mostly repeated work, blocked work, or failed work? Which ones should stop being agentic entirely and become deterministic pre-steps?

下一步是从工作流级优化走向系统级优化。一次工作流运行并不是一条扁平的 API 调用序列,而是一串 episode:比如收集上下文、读取产物、失败后重试、或合成最终答案等短小的工作阶段。一旦你能清楚地看到这些 episode,就可以提出好得多的问题:到底是哪个 episode 导致了一次昂贵的运行?哪些 episode 主要是重复工作、被阻塞的工作或失败的工作?哪些应该完全停止采用 agent 方式,变成确定性的前置步骤?

§ 19

That same logic applies at the portfolio level. Repositories do not run one workflow in isolation. They run a fleet of agentic automations that often trigger on the same events, inspect the same diffs and logs, and produce adjacent judgments. That means cost is not just a property of a single workflow, but also of overlap across the portfolio. The next analyses we want are portfolio-level ones: where workflows are duplicating reads, where several workflows should be consolidated, and where shared intermediate artifacts should be cached instead of rediscovered by each run.

同样的逻辑也适用于组合层面。仓库并不是孤立地运行一个工作流,而是运行一整套 agentic 自动化任务。这些任务常常被同一批事件触发、检查同一个 diff 和日志、产出相邻的判断。这意味着成本不只是单个工作流的属性,也是整个组合中重叠部分的属性。我们接下来想要的分析是组合级的:哪些工作流在重复读取数据?哪些工作流应该合并?哪些共享中间产物应该缓存,而不是每次运行都重新发现?

§ 20

Those open questions are genuinely hard. Measuring goodput still requires outcome instrumentation that does not yet exist at scale for agentic CI workflows, and understanding episode and portfolio efficiency requires richer lineage data than most systems collect today. But that is the direction that matters. The proxy-level observability and optimizer workflows have already changed how we develop and deploy new agentic automations. We add token monitoring from day one rather than retrofitting it later, and increasingly we think in terms of avoidable work across the whole automation fleet, not just expensive runs in isolation.

这些开放问题确实很难。度量有效产出(goodput)仍然需要结果层面的埋点,而这类埋点在 agentic CI 工作流中还没有大规模落地;理解 episode 和组合级效率,则需要比今天大多数系统所收集的更丰富的血缘数据。但这是值得前进的方向。代理级可观测性和优化器工作流已经改变了我们开发和部署新 agentic 自动化的方式。我们从第一天就加入 token 监控,而不是事后补救;而且我们越来越习惯于从整个自动化机队的角度看“可避免的工作”,而不只是孤立地看某次昂贵运行。

§ 21

If you’re running agentic workflows in CI and wondering whether you’re spending more than you need to, the first step is the same as ours: add the API proxy, turn on logging, and let the data tell you where to look.

如果你正在 CI 中运行 agentic workflows,并怀疑自己是不是花了不该花的钱,第一步和我们一样:加一个 API 代理、打开日志,让数据告诉你该往哪里看。

§ 22

If you want to add the workflows mentioned here, you can simply drop them into your repo using the gh-aw CLI:

gh extensions install github/gh-aw
gh aw add githubnext/agentic-ops/copilot-token-audit githubnext/agentic-ops/copilot-token-optimizer

Running them alongside your existing CI will give you immediate visibility into usage and help continuously optimize your workflows over time.

如果你想添加这里提到的工作流,只需用 gh-aw CLI 把它们装进仓库:

gh extensions install github/gh-aw
gh aw add githubnext/agentic-ops/copilot-token-audit githubnext/agentic-ops/copilot-token-optimizer

将它们与现有 CI 一起运行,你就能立刻看到用量,并随时间持续优化工作流。

§ 23

We’d love to hear how others are approaching this problem. Share your thoughts in the community discussion or join the #agentic-workflows channel of the GitHub Next Discord.

我们很想知道其他人如何处理这个问题。欢迎在社区讨论中分享你的想法,或加入 GitHub Next Discord 的 #agentic-workflows 频道。

Open source ↗