Skip to content

[agentic-token-optimizer] Daily XKCD Comic: Reduce turns via setup-step pre-computation and prevent tool-misuse outlier #178

Description

@github-actions

Target Workflow

Daily XKCD Comic — selected as the highest-AIC non-excluded workflow (1,329 total AIC / 221.5 avg AIC per run over 7 days). All other top workflows were optimized within the last 14 days; this workflow was most recently analyzed on 2026-06-18 from only 2 runs and now has 6 full runs for deeper analysis.


Analysis Period & Runs


Spend Profile

Metric Total (6 runs) Avg per run Excl. outlier (5 runs)
AI credits (AIC) 1,329.1 221.5 87.8
Input tokens 3,749,040 624,840 236,973
Cache-read tokens 3,490,203 581,700 202,168
Cache hit rate 93.1% 85.3%
Turns 107 17.8 9.0
Action minutes 52 8.7

Run #2 (§27753927403) is a severe outlier: 890 AIC, 62 turns, 2.56 M input tokens against a normal baseline of 63–109 AIC, 7–11 turns. Removing it drops the average from 221.5 to 87.8 AIC/run.


Ranked Recommendations

1. Prevent GitHub-search tool misuse (outlier root cause) — ~135 AIC/run avg, 800 AIC when triggered

Evidence: Run #2 accumulated 62 turns and 890 AIC because the agent invoked search_code and search_repositories (GitHub MCP tools) to try to look up XKCD alt text in code repositories — a completely unnecessary detour. Every search hit GitHub's 429 rate-limit, triggering repeated retries that ballooned context to 2.56 M tokens over 62 rounds.

The workflow's tools: block only declares web-fetch and bash, but the GitHub MCP toolset is available in the runtime and was used without constraint. Normal runs (5 of 6) use only web_fetch (xkcd.com/redacted) and emit a single create_discussion` call.

Action: Add one explicit sentence to the Instructions section:

Use only web_fetch and bash to retrieve comic data — the XKCD API at (xkcd.com/redacted) provides the complete title, img, and alt` fields needed for both relevance checking and the discussion body. Do not use GitHub search or repository tools.

Expected savings: Eliminates outlier runs. At 1-in-6 observed frequency: ~133 AIC/run on average, plus avoids ~14 minutes of wasted action time per incident.


2. Extend the setup step to pre-select and pre-fetch the comic — ~25–40 AIC/run

Evidence: Normal runs take 7–11 turns to complete a task that is structurally 3 steps: (a) read latest comic number, (b) select a comic, (c) fetch its JSON. Steps (a) and (b) are deterministic arithmetic that the agent re-derives at runtime by calling bash date +%j, bash expr, and web_fetch — each adding an LLM round trip.

The existing setup step already runs a curl to get the latest comic number. It can cheaply extend to:

  1. Compute DOY=$(date +%j) and list-index arithmetic in bash.
  2. curl the pre-selected comic JSON to /tmp/gh-aw/agent/xkcd/selected.json.
  3. curl the latest comic JSON as well (already partially done).

The agent then has both JSONs ready to read — the only work remaining is relevance confirmation and discussion formatting (~3–4 turns).

Action: Replace the current setup steps.run block with:

set -euo pipefail
mkdir -p /tmp/gh-aw/agent/xkcd

# Fetch 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 XKCD comic: #$LATEST"
echo "$LATEST" > /tmp/gh-aw/agent/xkcd/latest_num.txt

# Pre-select from curated developer/ML/math list using 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 | sed 's/^0*//')
IDX=$(( (DOY - 1) % COUNT + 1 ))
SELECTED=$(echo $CURATED | tr ' ' '\n' | sed -n "${IDX}p")
echo "Pre-selected comic: #$SELECTED (day $DOY, index $IDX of $COUNT)"
echo "$SELECTED" > /tmp/gh-aw/agent/xkcd/selected_num.txt
curl -sSf "(xkcd.com/redacted) -o /tmp/gh-aw/agent/xkcd/selected.json

Then update the Context section of the prompt to reference /tmp/gh-aw/agent/xkcd/selected.json and /tmp/gh-aw/agent/xkcd/latest.json as already-fetched data.

Expected savings: Removes ~3–5 agent turns (bash + web_fetch calls for selection/fetching) per normal run. At ~9 AIC per turn eliminated: ~27–45 AIC/run.


3. Remove the open-ended retry loop — ~10–15 AIC/run

Evidence: The prompt currently says "If the chosen comic feels irrelevant, pick the next number from the list and try again (max 3 attempts)." Every attempt requires one web_fetch call and 1–2 LLM turns. All 51 comics in the curated list are hand-picked for relevance (developer, math, ML/AI), making the relevance check almost always a pass. Runs #4 and #5 had 9 and 11 turns respectively — slightly above normal — likely due to partial retry cycles.

Action: Replace the retry instruction with:

All comics in the curated list are pre-vetted for developer/ML/math relevance. Use the pre-selected comic (/tmp/gh-aw/agent/xkcd/selected.json) directly. Only substitute the latest comic (from latest.json) when it is obviously more relevant and fresh.

This change also reinforces Recommendation 2 by eliminating the loop pattern that tempted the agent to search GitHub for comic metadata.

Expected savings: ~1–2 fewer turns per run on average. ~10–15 AIC/run.


Tool Usage Assessment

Tool Observed usage Verdict
web_fetch Every run (1–3× per run) Keep — core to fetching XKCD JSON
bash (curl, jq, date, expr) Every run Keep — used in setup step and by agent
safeoutputs/create_discussion Every run × 1 Keep — sole output mechanism
github/search_code Run #2 only × 5 (all 429 errors) Constrain — never needed; add explicit prohibition in prompt
github/search_repositories Run #2 only × 3 (all empty results) Constrain — same

Summary of Expected Savings

Recommendation Est. AIC saved/run Type
1. Prevent GitHub-search misuse ~133 (amortized) Reliability / Prompt
2. Extend setup step to pre-fetch comic ~30–40 Setup prefix
3. Remove open-ended retry loop ~10–15 Prompt efficiency
Combined (conservative) ~60–80 AIC/run

Conservative estimate excludes the outlier frequency since Recommendation 1 fully eliminates it. Normal-run savings (R2 + R3) account for ~40–55 AIC/run improvement against a 87.8 AIC/run baseline — roughly 45–65% reduction.


Caveats

  • Run Update ci.yml: add workflow_dispatch trigger and add job #2 outlier may be a one-time model quirk; 5 of 6 runs were well-behaved. The prohibition in Recommendation 1 is low-risk and adds negligible prompt length.
  • Setup step pre-computation assumes curl and jq remain available in the runner environment (currently configured in tools.bash).
  • Only 6 runs analyzed; turn variance (7–11 for normal runs) could narrow further with more data.
Run-level details
Run ID Date AIC Turns Input tokens Cache reads Cache% Duration Tools used
§27740471638 2026-06-18 89.0 9 245,640 212,489 86.5% 6.4m create_discussion
§27753927403 2026-06-18 890.4 62 2,564,176 2,479,363 96.7% 16.3m search_code×5, search_repos×3, get_file×1, create_discussion
§27820939538 2026-06-19 62.9 7 179,260 148,899 83.1% 5.9m create_discussion
§27868008490 2026-06-20 96.2 9 246,334 208,265 84.5% 7.2m create_discussion
§27901294421 2026-06-21 108.9 11 281,062 238,390 84.8% 7.7m create_discussion
§27948330583 2026-06-22 81.5 9 233,568 202,797 86.8% 5.4m create_discussion

References: §27753927403 (outlier), §27948330583 (most recent)

Generated by Agentic Workflow AIC Usage Optimizer · 462.9 AIC · ⊞ 21.6K ·

  • expires on Jun 29, 2026, 4:12 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions