Token Optimization: PR Sous Chef
Selected because: Highest total tokens in the 7-day window (6.71M across 2 runs, 3.35M avg/run) with no prior optimization on record.
Analysis Period
- Window: 2026-05-22 → 2026-05-29 (7 days)
- Runs analyzed: 2 (both on 2026-05-29)
- References: §26645226969 (success, 154 turns), §26641067714 (failure, 220 turns)
Token Profile
| Metric |
Value |
| Total tokens (7-day) |
6,711,514 |
| Avg tokens / run |
~3,355,757 |
| Total turns (2 runs) |
374 |
| Avg turns / run |
187 |
| Successful runs |
1 (50%) |
| Failed runs |
1 (50%) |
| Avg action minutes |
29.5 min |
| Engine |
Copilot (gpt-5-mini) |
| Schedule |
every 15 minutes |
Ranked Recommendations
1. Reorder steps: move candidate prefilter before heavy setup + add early-exit conditional
Estimated savings: ~400–600k tokens/run when no eligible PRs exist
Currently the workflow runs these expensive steps unconditionally before discovering how many eligible PRs exist:
actions/setup-go (with deps cache)
actions/setup-node
npm ci (in actions/setup/js)
make deps-dev (~5–8 min per AGENTS.md docs)
- (then)
Fetch open non-draft PR queue
When the prefilter returns zero eligible PRs, steps 1–4 were wasted. The Fetch open non-draft PR queue step only needs gh CLI and jq — no Go/Node toolchain.
Action: Move Fetch open non-draft PR queue to be the first step. Emit the eligible count as a step output:
echo "eligible_count=$(jq '.prs | length' "$eligible_file")" >> "$GITHUB_OUTPUT"
Then guard the remaining heavy setup steps:
if: steps.fetch_prs.outputs.eligible_count != '0'
2. Replace make deps-dev with targeted formatter dependencies
Estimated savings: ~200–400k tokens/run + 4–6 action-minutes on runs with eligible PRs
make deps-dev installs the full development toolchain including golangci-lint and other heavy tools (~5–8 min). The only formatter the agent invokes is make fmt, which uses go fmt and npm format — not the full linter suite.
Action: Replace make deps-dev with a targeted install step:
- name: Install formatter dependencies
if: steps.fetch_prs.outputs.eligible_count != '0'
run: npm ci --prefix actions/setup/js
Go's go fmt is already available after actions/setup-go, so no additional Go tool install is needed for basic formatting.
3. Cap per-run PR processing at 5 (down from 10)
Estimated savings: ~600–900k tokens/run (~30–40% reduction in agent turns)
Avg turns/run is 187, very high for a nudge workflow. With up to 10 PRs each going through pr-processor (sub-agent call + checkout + make fmt + git diff + potential push + comment), per-PR overhead is ~15–20 turns. The failed run reached 220 turns before dying.
Since the workflow runs every 15 minutes, PRs skipped in one run are handled within 15 minutes. There is no operational need to process 10 at once.
Action: Change the prompt instruction from:
Process at most 10 PRs per run.
to:
Process at most 5 PRs per run. Remaining eligible PRs will be handled in the next scheduled run.
4. Add hard turn/tool-call limit to pr-processor sub-agent to prevent runaway failures
Estimated savings: prevents ~1.6M token losses from failed runs
The failed run §26641067714 accumulated 220 turns before the Execute GitHub Copilot CLI step failed — more turns than the successful run despite fewer action minutes, indicating an expansion loop before a hard limit was hit.
Action: Append to the pr-processor sub-agent prompt:
Make at most 4 tool calls total. Return compact JSON only — a single object, no prose.
If you cannot determine a field, set it to null.
And add a defensive guard in the main prompt loop:
If a pr-processor call returns non-JSON or an error, record skip_reason: "sub_agent_error" and move to the next PR without retrying.
Supporting run data
- Both runs used Copilot engine (
gpt-5-mini), classified as baseline
- Failure point:
Execute GitHub Copilot CLI step in the agent job
- High turns on the failure run with fewer action minutes suggests a loop hitting a hard limit
Estimated Cumulative Savings
| Recommendation |
Tokens saved / run |
Confidence |
| Early-exit guard (no eligible PRs) |
~400–600k |
Medium |
Replace make deps-dev |
~200–400k |
High |
| Cap PRs per run at 5 |
~600–900k |
High |
| Sub-agent turn guard |
Prevents ~1.6M failure losses |
High |
| Conservative total |
~1.2–1.9M tokens/run |
— |
Caveats
- Only 2 runs available for analysis; conclusions should be validated across more runs once the workflow has higher frequency.
- Token field in run-level data was null; total tokens sourced from pre-aggregated
top-workflows.json snapshot — per-run cache efficiency could not be assessed.
- The
make deps-dev replacement requires verifying exactly which tools make fmt depends on before removing the full install.
- Reducing PR cap to 5 assumes reliable 15-minute schedule execution; if runs skip or queue up, some PRs may be delayed.
Generated by Agentic Workflow Token Usage Optimizer · sonnet46 2M · ◷
Add this agentic workflows to your repo
To install this agentic workflow, run
gh aw add githubnext/agentic-ops/workflows/agentic-token-optimizer.md@e10687ae8f19a5b37b061db524be27948568c411
Token Optimization: PR Sous Chef
Selected because: Highest total tokens in the 7-day window (6.71M across 2 runs, 3.35M avg/run) with no prior optimization on record.
Analysis Period
Token Profile
gpt-5-mini)Ranked Recommendations
1. Reorder steps: move candidate prefilter before heavy setup + add early-exit conditional
Estimated savings: ~400–600k tokens/run when no eligible PRs exist
Currently the workflow runs these expensive steps unconditionally before discovering how many eligible PRs exist:
actions/setup-go(with deps cache)actions/setup-nodenpm ci(inactions/setup/js)make deps-dev(~5–8 min per AGENTS.md docs)Fetch open non-draft PR queueWhen the prefilter returns zero eligible PRs, steps 1–4 were wasted. The
Fetch open non-draft PR queuestep only needsghCLI andjq— no Go/Node toolchain.Action: Move
Fetch open non-draft PR queueto be the first step. Emit the eligible count as a step output:echo "eligible_count=$(jq '.prs | length' "$eligible_file")" >> "$GITHUB_OUTPUT"Then guard the remaining heavy setup steps:
2. Replace
make deps-devwith targeted formatter dependenciesEstimated savings: ~200–400k tokens/run + 4–6 action-minutes on runs with eligible PRs
make deps-devinstalls the full development toolchain includinggolangci-lintand other heavy tools (~5–8 min). The only formatter the agent invokes ismake fmt, which usesgo fmtand npm format — not the full linter suite.Action: Replace
make deps-devwith a targeted install step:Go's
go fmtis already available afteractions/setup-go, so no additional Go tool install is needed for basic formatting.3. Cap per-run PR processing at 5 (down from 10)
Estimated savings: ~600–900k tokens/run (~30–40% reduction in agent turns)
Avg turns/run is 187, very high for a nudge workflow. With up to 10 PRs each going through
pr-processor(sub-agent call + checkout +make fmt+git diff+ potential push + comment), per-PR overhead is ~15–20 turns. The failed run reached 220 turns before dying.Since the workflow runs every 15 minutes, PRs skipped in one run are handled within 15 minutes. There is no operational need to process 10 at once.
Action: Change the prompt instruction from:
to:
4. Add hard turn/tool-call limit to pr-processor sub-agent to prevent runaway failures
Estimated savings: prevents ~1.6M token losses from failed runs
The failed run §26641067714 accumulated 220 turns before the
Execute GitHub Copilot CLIstep failed — more turns than the successful run despite fewer action minutes, indicating an expansion loop before a hard limit was hit.Action: Append to the
pr-processorsub-agent prompt:And add a defensive guard in the main prompt loop:
Supporting run data
gpt-5-mini), classified asbaselineExecute GitHub Copilot CLIstep in theagentjobEstimated Cumulative Savings
make deps-devCaveats
top-workflows.jsonsnapshot — per-run cache efficiency could not be assessed.make deps-devreplacement requires verifying exactly which toolsmake fmtdepends on before removing the full install.Add this agentic workflows to your repo
To install this agentic workflow, run