Skip to content

[agentic-token-optimizer] Optimization: Daily Agentic Workflow AIC Usage AuditΒ #430

Description

@github-actions

🎯 Target Workflow

Daily Agentic Workflow AIC Usage Audit (agentic-token-audit.md) β€” selected as the highest-AIC eligible workflow not excluded by the 14-day cooldown. All other top workflows were optimized more recently.

πŸ“Š Analysis Period

  • Window: 7-day snapshot (2026-08-10 to 2026-08-17)
  • Runs analyzed: 4 (all success)
  • Token/turn data available: 1 of 4 runs (run Β§32030595002)

πŸ’° Spend Profile

Metric Value
Total AIC 1,181.84
Avg AIC / run 295.46
Total tokens (1 run) 1,017,250
Avg turns / run 26 (1 run)
Conclusion rate 4/4 success
Cache efficiency N/A (no cache data)
Per-Run Detail
Run ID AIC Tokens Turns Conclusion
Β§31597280446 299.13 β€” β€” success
Β§31700861247 236.34 β€” β€” success
Β§31801061003 303.92 β€” β€” success
Β§32030595002 342.46 1,017,250 26 success

The most recent run is the most expensive (342 AIC), suggesting a slow upward trend, though the sample size is small.

πŸ† Ranked Recommendations

1. Trim the RunData schema table (Prompt verbosity)

Estimated savings: ~15–25 AIC/run

The Data Sources section contains a 12-row table documenting every field in the RunData object, including deprecated fields (effective_tokens) and fields irrelevant to the script (url, duration, status). The agent's Phase 1 Python script only uses ~5 of these fields.

Action: Replace the full schema table with a compact note listing only the fields actually consumed:

Key fields per run: `workflow_name`, `aic` (treat null as 0), `token_usage` (treat null as 0),
`turns`, `action_minutes`, `conclusion`, `error_count`, `warning_count`, `run_id`, `url`.

This removes ~25 lines of schema prose from the agent's input context on every run.

Evidence: The table is 12 rows Γ— 4 columns plus header prose, repeated across all 4 runs. With avg 1,017,250 tokens in the one measured run, prompt verbosity is a primary cost driver.


2. Consolidate repeated PYTHONPATH instructions (Prompt verbosity)

Estimated savings: ~8–12 AIC/run

Phase 3 (Generate Charts) states the PYTHONPATH pattern three times:

  1. As a general requirement ("Set PYTHONPATH=... for every Python command")
  2. As an inline example in a code block
  3. With a specific full example: PYTHONPATH=/tmp/gh-aw/token-audit/site-packages${PYTHONPATH:+:$PYTHONPATH} python3 /tmp/gh-aw/token-audit/process_audit.py

Action: State the PYTHONPATH rule once at the top of Phase 3 (or in a shared ## Setup Notes section), remove the inline example repetition, and change Phase 1's script-running instruction to simply say "run the script with the site-packages PYTHONPATH set."


3. Extract Phase 1 (Log Processing) as an inline sub-agent (Structural)

Estimated savings: ~40–60 AIC/run

Phase 1 β€” "Process Logs" β€” tasks the agent to write a Python script to disk and execute it. This is entirely mechanical: read a JSON file, aggregate by field, write another JSON file. It requires no cross-referencing, strategic reasoning, or access to outputs from other phases. The input and output schemas are fully specified in the prompt.

Sub-agent score:

Dimension Score Rationale
Independence 3/3 No dependency on other phases; reads a pre-downloaded file
Small-model adequacy 3/3 Pure extraction/aggregation; fully specified schema in/out
Parallelism 2/2 Phase 2, 3, and 4 all depend on Phase 1's output, not each other
Size 2/2 Substantial scripting task worth isolating
Total 10/10 Strong candidate

Why a smaller model fits: The task is entirely classificatory and formatting work β€” group runs by field, sum numeric columns, write JSON. The output schema is provided verbatim. No judgment is required beyond null-coalescing.

Proposed change: Replace the Phase 1 section with an inline sub-agent block:

## agent: process-logs
model: small
task: >
  Write /tmp/gh-aw/token-audit/process_audit.py that loads
  /tmp/gh-aw/token-audit/workflow-logs.json, filters to status=="completed" runs,
  groups by workflow_name, computes run_count/total_ai_credits/avg_ai_credits/
  total_tokens/avg_tokens/total_turns/avg_turns/total_action_minutes/error_count/
  warning_count (treat null aic and token_usage as 0), and writes
  /tmp/gh-aw/token-audit/audit_snapshot.json with the schema:
  {date, period_days:30, overall:{total_runs,total_ai_credits,total_tokens,total_action_minutes},
   workflows:[...sorted desc by total_ai_credits...]}
  Then run: PYTHONPATH=/tmp/gh-aw/token-audit/site-packages python3 /tmp/gh-aw/token-audit/process_audit.py

This removes ~50 lines of Phase 1 prose plus the full JSON/table schema documentation from the main agent context.


4. Extract Phase 3 (Chart Generation) as an inline sub-agent (Structural)

Estimated savings: ~20–30 AIC/run

Phase 3 β€” "Generate Charts" β€” tasks the agent to write two Python charting scripts using matplotlib/seaborn, upload the assets, and capture URLs. This is mechanical code-generation work with a fully specified output format.

Sub-agent score:

Dimension Score Rationale
Independence 2/3 Depends on Phase 1 output file (sequential)
Small-model adequacy 3/3 Boilerplate charting code; axes/title specs given verbatim
Parallelism 1/2 Cannot start until Phase 1 completes
Size 2/2 Two charts with detailed specs; substantial task
Total 8/10 Strong candidate

Why a smaller model fits: The task is generating standard matplotlib/seaborn boilerplate against a fixed data schema. All axis labels, titles, DPI, and color schemes are specified. No analysis needed.

Proposed change: Replace Phase 3 with:

## agent: generate-charts
model: small
task: >
  Read /tmp/gh-aw/token-audit/audit_snapshot.json and
  /tmp/gh-aw/repo-memory/default/rolling-summary.json.
  Using PYTHONPATH=/tmp/gh-aw/token-audit/site-packages, write and run scripts to:
  1. Create /tmp/gh-aw/token-audit/charts/ai_credits_by_workflow.png β€” horizontal bar chart,
     top 15 workflows by total_ai_credits, 300 DPI, white bg, seaborn whitegrid.
  2. Create /tmp/gh-aw/token-audit/charts/ai_credits_trend.png β€” dual-axis line chart,
     primary y=total_ai_credits, secondary y=active_workflows (label: "Active workflows/day").
     Skip and explain if fewer than 2 rolling-summary points.
  Upload both PNGs via upload_asset. Return the two upload URLs.

The main agent only needs to receive the URLs and embed them in the issue.


πŸ—οΈ Structural Summary

The workflow has no existing sub-agents. Two clearly extractive phases (log processing and chart generation) together account for the majority of prompt verbosity and mechanical agent turns. Extracting both as small-model sub-agents while keeping Phase 4 (issue authoring) in the main agent is a clean decomposition.

Phase Recommended action Est. savings
Phase 1 β€” Process Logs Extract β†’ inline sub-agent (small model) 40–60 AIC/run
Phase 2 β€” Persist Snapshot Keep in main agent (simple file copy, 8 lines) β€”
Phase 3 β€” Generate Charts Extract β†’ inline sub-agent (small model) 20–30 AIC/run
Phase 4 β€” Publish Issue Keep in main agent (strategic synthesis) β€”
RunData schema table Trim to used fields only 15–25 AIC/run
PYTHONPATH repetition Consolidate to one location 8–12 AIC/run
Total estimated savings ~83–127 AIC/run (28–43%)

⚠️ Caveats

  • Token data is available for only 1 of 4 runs; per-turn cost estimates are based on that single run (1,017,250 tokens / 26 turns β‰ˆ 39,125 tokens/turn).
  • The AIC trend is upward (236 β†’ 342 over 4 runs) but with only 4 data points this may be noise.
  • Sub-agent extraction requires the agentic-workflows tool to support inline sub-agents in this workflow β€” verify compatibility before implementing.
  • OTEL span attributes section (at the end of the prompt) is left as-is; it is short and non-repetitive.

References:

Generated by Agentic Workflow AIC Usage Optimizer Β· 151.5 AIC Β· ⊞ 21.6K Β· β—·

  • expires on Aug 24, 2026, 2:41 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions