Target Workflow
Daily XKCD Comic — selected as highest-AIC workflow not optimized in the last 14 days (last optimized 2026-07-13, 8 days ago). It accounted for 309 AIC / 152k tokens in the most recent 7-day window across 6 successful runs.
Analysis Period
| Metric |
Value |
| Snapshots analyzed |
15 daily snapshots (2026-07-01 → 2026-07-21) |
| Runs audited |
15 runs (all success) |
| Analysis window |
21 days |
Spend Profile
| Metric |
7-day window |
Full 21-day history |
| Runs |
6 |
15 |
| Total AIC |
309.3 |
1 466.2 |
| Avg AIC / run |
51.5 |
97.7 |
| Total tokens |
~957k |
~4.1M |
| Avg tokens / run |
~159 500 |
~273 400 |
| Avg turns / run |
6.5 |
10.1 |
| Max turns (single run) |
— |
33 (2026-07-06) |
| Errors / warnings |
0 / 0 |
0 / 0 |
Trend: A previous optimization (2026-07-13) dramatically reduced turn counts from 9–33 down to 5–9. The workflow now completes reliably, but further structural savings are available.
Ranked Recommendations
1 · Pre-compute comic selection inside the setup steps: block
Estimated savings: ~10–15 AIC/run (~20%)
The current setup step fetches only the latest comic number, leaving the agent to:
- Read
latest_num.txt (1 tool call)
- Optionally decide to check the latest comic (1
web_fetch)
- Compute
date +%j mod list-size to pick a curated number (1–2 tool calls)
- Fetch the selected comic JSON (1
web_fetch)
These 4–5 agent turns could run in the pre-step at near-zero marginal cost (bash only). Each saved agent turn eliminates not just the tool call itself but also its accumulated context overhead (the conversation grows quadratically).
Concrete action: Extend the existing steps: block to:
steps:
- name: Fetch latest XKCD and pre-select today's comic
run: |
set -euo pipefail
mkdir -p /tmp/gh-aw/agent/xkcd
# Latest comic
curl -sSf "(xkcd.com/redacted) -o /tmp/gh-aw/agent/xkcd/latest.json
LATEST=$(jq -r '.num' /tmp/gh-aw/agent/xkcd/latest.json)
echo "$LATEST" > /tmp/gh-aw/agent/xkcd/latest_num.txt
# Pre-select a curated comic by day-of-year rotation
CURATED="303 327 353 386 456 519 664 705 722 737 844 859 936 1068 1168 1205 1319 1425 1443 1537 1739 55 135 174 687 712 715 881 882 1236 1261 1379 1478 1754 2048 2100 1838 1875 2050 2173 2347 2440 2501 2545 2581 2674 2746 2785 2860 2916 2925"
COUNT=$(echo $CURATED | wc -w)
DOY=$(date +%j)
IDX=$(( DOY % COUNT ))
SELECTED=$(echo $CURATED | tr ' ' '\n' | sed -n "$((IDX + 1))p")
echo "$SELECTED" > /tmp/gh-aw/agent/xkcd/selected_num.txt
# Pre-fetch selected comic JSON
curl -sSf "(xkcd.com/redacted) -o /tmp/gh-aw/agent/xkcd/selected.json
echo "Pre-selected comic #$SELECTED for today (day $DOY of year)"
Then update the Comic Selection prompt section to:
The setup step has already:
- Fetched the latest comic to `/tmp/gh-aw/agent/xkcd/latest.json`
- Pre-selected today's curated comic and written its number to `/tmp/gh-aw/agent/xkcd/selected_num.txt`
- Pre-fetched the selected comic JSON to `/tmp/gh-aw/agent/xkcd/selected.json`
Read both files. If the latest comic is relevant (title/alt touches code, math, ML, AI, debugging, or tech culture), use it. Otherwise use the pre-selected comic from `selected.json`. If that comic is also irrelevant, pick the adjacent number from the list (max 1 additional `web_fetch`).
Evidence: Across 15 runs, the agent consistently spends 2–4 turns on the selection + fetch loop. The 2026-07-06 outlier reached 33 turns, likely from a relevance-retry spiral that could not have occurred if the pre-step had already resolved the selection.
2 · Remove expr from the allowed bash tools
Estimated savings: negligible AIC, but cleaner tool surface
expr is listed as an allowed bash tool alongside date and bash. Modern bash arithmetic ($(( ))) handles all the same operations without a subprocess. No run was observed using expr — it is dead configuration.
Concrete action: Remove expr from the tools.bash list in the workflow frontmatter:
tools:
web-fetch:
bash:
- "curl"
- "jq"
- "bash"
- "echo"
- "date"
# remove: "expr"
3 · Trim the curated comic list from the prompt body
Estimated savings: ~3–5 AIC/run (~6–8%)
The prompt embeds 50 comic numbers across three labeled categories. This block appears verbatim in every turn's context (as part of conversation history), adding ~600–800 prompt tokens per turn. At 6.5 turns/run that is ~4 000–5 000 extra tokens per run consumed entirely in context repetition.
Concrete action: After moving list rotation into the setup step (Rec. 1), the prompt no longer needs the full list. Replace the three category blocks with a single fallback line:
The full curated list is embedded in the setup step. For a fallback (if all pre-selected options fail), try comic #1205, #2347, or #936.
Evidence: The curated list section is ~350 characters (~90 tokens). Across 6.5 turns × 6 runs/week = ~39 context inclusions per week of unchanged list content.
Caveats
- Turn counts for runs prior to 2026-07-10 reflect pre-optimization behavior; recent steady-state is 5–9 turns.
- Cache efficiency is not broken down in available snapshot data; actual token savings may be partially offset by reduced cache hit rates if context structure changes significantly.
- The 2026-07-06 outlier (33 turns, 328 AIC) is a single data point; its root cause (likely a relevance-retry loop) is inferred, not confirmed from logs.
- All 6 recent runs completed successfully — no reliability risk is evident.
Full run history (15 snapshots)
References: §29820403487 · §29734221047 · §28785726911
Generated by Agentic Workflow AIC Usage Optimizer · 259.2 AIC · ⊞ 21.6K · ◷
Target Workflow
Daily XKCD Comic — selected as highest-AIC workflow not optimized in the last 14 days (last optimized 2026-07-13, 8 days ago). It accounted for 309 AIC / 152k tokens in the most recent 7-day window across 6 successful runs.
Analysis Period
success)Spend Profile
Trend: A previous optimization (2026-07-13) dramatically reduced turn counts from 9–33 down to 5–9. The workflow now completes reliably, but further structural savings are available.
Ranked Recommendations
1 · Pre-compute comic selection inside the setup
steps:blockEstimated savings: ~10–15 AIC/run (~20%)
The current setup step fetches only the latest comic number, leaving the agent to:
latest_num.txt(1 tool call)web_fetch)date +%jmod list-size to pick a curated number (1–2 tool calls)web_fetch)These 4–5 agent turns could run in the pre-step at near-zero marginal cost (bash only). Each saved agent turn eliminates not just the tool call itself but also its accumulated context overhead (the conversation grows quadratically).
Concrete action: Extend the existing
steps:block to:Then update the Comic Selection prompt section to:
Evidence: Across 15 runs, the agent consistently spends 2–4 turns on the selection + fetch loop. The 2026-07-06 outlier reached 33 turns, likely from a relevance-retry spiral that could not have occurred if the pre-step had already resolved the selection.
2 · Remove
exprfrom the allowed bash toolsEstimated savings: negligible AIC, but cleaner tool surface
expris listed as an allowed bash tool alongsidedateandbash. Modern bash arithmetic ($(( ))) handles all the same operations without a subprocess. No run was observed usingexpr— it is dead configuration.Concrete action: Remove
exprfrom thetools.bashlist in the workflow frontmatter:3 · Trim the curated comic list from the prompt body
Estimated savings: ~3–5 AIC/run (~6–8%)
The prompt embeds 50 comic numbers across three labeled categories. This block appears verbatim in every turn's context (as part of conversation history), adding ~600–800 prompt tokens per turn. At 6.5 turns/run that is ~4 000–5 000 extra tokens per run consumed entirely in context repetition.
Concrete action: After moving list rotation into the setup step (Rec. 1), the prompt no longer needs the full list. Replace the three category blocks with a single fallback line:
Evidence: The curated list section is ~350 characters (~90 tokens). Across 6.5 turns × 6 runs/week = ~39 context inclusions per week of unchanged list content.
Caveats
Full run history (15 snapshots)
References: §29820403487 · §29734221047 · §28785726911