Skip to content

[agentic-token-optimizer] Daily Agentic Workflow AIC Usage Audit — optimization opportunities #113

Description

@github-actions

Target workflow: Daily Agentic Workflow AIC Usage Audit (agentic-token-audit.md)
Reason selected: Active daily workflow; current display name has no "Token" suffix; not logged under its current name in the last 14 days. Token footers on recent issues show 5.7M–7.1M tokens per run despite processing zero-value data every time.

Analysis period: 2026-05-28 → 2026-06-09 · 10 runs audited


📊 Spend Profile

Metric Value
Runs audited 10
Run conclusions 10/10 success
Retries 1 (2026-06-08, producing 3 duplicate issues in one day)
Avg run duration ~5.6 min (range 4.5–7.5 min)
Token footprint (from issue footer) 5.7M–7.1M tokens/run
Useful data produced 0 — every run reports zero AIC / zero tokens
upload_assets job Skipped in 8 of 10 runs; ran in 2 with empty-data charts

AIC billing figures from audit snapshots are all 0 because gh aw logs --start-date -1d returns an empty .runs array on every run — a persistent data-pipeline gap that means each run burns 5–7 M context tokens for zero useful output.


🏆 Ranked Recommendations

#1 — Add explicit early-exit after Phase 1 when runs is empty

Estimated savings: 20–30% AIC/run

Evidence: 10 of 10 audited runs detected len(runs) == 0. Despite having nothing to report, every run executes the full four-phase prompt:

  • Phase 1: writes and runs a Python script (correct)
  • Phase 2: copies an empty snapshot file (wasted)
  • Phase 3: attempts chart generation (skipped 8×, or generates empty chart 2×)
  • Phase 4: fills the entire report template with N/A placeholders

Action: After Phase 1, add a guard:

If `len(runs) == 0`, immediately publish a compact issue:
  title: "Daily AIC Usage Audit — {YYYY-MM-DD}"
  body: "No agentic workflow runs were captured in the last 24 hours (`gh aw logs` returned an empty `.runs` array). No snapshot or charts generated."
Then stop — skip Phases 2, 3, and 4.

Skipping Phase 2–4 on the empty-data path eliminates the full template-filling exercise, chart-generation attempts, and snapshot copy on every run.


#2 — Consolidate Phases 1 and 2 into a single Python script

Estimated savings: 5–8% AIC/run

Evidence: Phase 2 is described as a standalone prompt section, but its entire content is:

Read the snapshot from audit_snapshot.json. Copy it to /tmp/gh-aw/repo-memory/default/YYYY-MM-DD.json. Also maintain rolling-summary.json.

This is three lines of Python that can be the final block of the Phase 1 script, removing the need for the agent to process a separate phase instruction, write another bash call, and report completion.

Action: Merge Phase 2 into the Phase 1 Python script. Replace the Phase 2 section header and body with a single sentence:

At the end of the Phase 1 script, also write `audit_snapshot.json` to
`/tmp/gh-aw/repo-memory/default/{today}.json` and update `rolling-summary.json`.

#3 — Fix the inconsistent issue title format

Estimated savings: minimal AIC, high reliability impact

Evidence: 5 most recent issues use 4 different title patterns:

Issue Title
#112 Daily AIC Usage Audit — 2026-06-09
#108 Daily AI Credit Spend Audit — 2026-06-08
#107 Daily AI Credit Spend Audit — 2026-06-08
#106 Daily AI Credit Spend Audit — 2026-06-08
#96 Daily Token Usage Audit — 2026-06-05

The agent re-invents the title every run. This makes issue search and de-duplication unreliable.

Action: Add an explicit instruction in Phase 4:

Use this exact title: "Daily AIC Usage Audit — {YYYY-MM-DD}"

#4 — Fix incorrect period reporting

Estimated savings: reliability

Evidence: Issue #107 (run §27136881236) reported Period: last 30 days (2026-05-09 to 2026-06-08) instead of last 24 hours. The period calculation is ambiguous and the agent uses whatever window it derives from the log file.

Action: Harden the period instruction in Phase 4:

Always write: **Period**: last 24 hours (YYYY-MM-DD to YYYY-MM-DD)
Use today's UTC date for the end and yesterday's UTC date for the start.
Do not derive the period from the log data range.

#5 — Simplify the PYTHONPATH setup instruction in Phase 3

Estimated savings: 2–4% AIC/run

Evidence: Phase 3 currently requires the PYTHONPATH variable to be set on each individual Python command:

Set PYTHONPATH=/tmp/gh-aw/token-audit/site-packages${PYTHONPATH:+:$PYTHONPATH} for every Python command that imports pandas, matplotlib, or seaborn

This pattern appears as an inline reminder repeated in the chart-generation instructions, adding token overhead and occasionally being misapplied (one run set the wrong PYTHONPATH for the first command).

Action: Replace the repeated reminder with a single export at the top of Phase 3:

Before any chart Python command, run once:
export PYTHONPATH=/tmp/gh-aw/token-audit/site-packages${PYTHONPATH:+:$PYTHONPATH}

⚠️ Root-Cause Note (out of scope for prompt optimization)

Every run reports zero data because gh aw logs --start-date -1d consistently returns an empty .runs array. Until this data-pipeline gap is fixed, all prompt optimizations above reduce wasted work on an empty payload — they do not restore the audit's core function. Investigating why the log download always returns no runs (rate limiting? collection window mismatch? pipeline misconfiguration?) is a prerequisite for the workflow to be useful.

References:


🔍 Caveats

  • AIC billing figures are unavailable (pre-aggregated all-runs.json and daily snapshots all show 0); savings estimates are based on observed run token footprints (5.7M–7.1M/run from issue footers) and prompt section size.
  • All 10 audited runs produce zero-value reports; behavior with actual run data is unobserved.
  • The data-pipeline fix is outside prompt scope and may change the effective savings once data flows correctly.

Generated by Agentic Workflow AIC Usage Optimizer · ● 9.5M ·

  • expires on Jun 16, 2026, 3:39 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions