Skip to content

[agentic-token-optimizer] Daily Agentic Workflow AIC Usage Audit β€” Optimization RecommendationsΒ #339

Description

@github-actions

🎯 Target Workflow

Daily Agentic Workflow AIC Usage Audit (agentic-token-audit)
Selected as the highest-AIC workflow in the 7-day window (1,117.78 AIC across 5 runs). All workflows in this repository have a recent optimization entry; this one has the highest ongoing spend and a new run today (run #60) that shows a notable duration spike useful for evidence.

Note: All five tracked workflows fall within the 14-day recency window. This workflow was last addressed on 2026-07-22 (5 days ago); the recommendations below focus on newly observable patterns from today's run and areas not previously targeted.


πŸ“Š Spend Profile (7-day window, 2026-07-21 β†’ 2026-07-27)

Metric Value
Runs analyzed 5
Total AIC 1,117.78
Avg AIC / run 223.56
Total tokens (1 run with data) 606,644
Avg turns / run (1 run with data) 16
Total Actions minutes 49 min
All conclusions βœ… success Γ— 5
Per-run breakdown
Run AIC Tokens Turns Duration
Β§29831796021 200.06 β€” β€” 8.0 min
Β§29921394771 262.46 β€” β€” 7.8 min
Β§30008781105 281.59 β€” β€” 8.1 min
Β§30094628596 167.53 β€” β€” 7.1 min
Β§30270012569 206.15 606,644 16 15.5 min

Token/turn data only available for run #60 (today's run). Duration spike on run #60 (15.5 min vs 7–8 min average) is a clear regression signal.


πŸ” Analysis

Tool Usage

The workflow configures agentic-workflows, bash, and repo-memory. All are used legitimately across runs. GitHub API calls per run are 8–10, consistent with reading workflow sources in the setup step and writing repo-memory. No tools appear configured but unused.

AI Credit Spend Drivers

  1. Large prompt body (333 lines): includes a 9-field data schema table, inline JSON schema examples for two output files, detailed chart rendering instructions, and a conditional OTEL span section β€” all loaded into context on every turn.
  2. Write-then-run script pattern (Phase 1): the agent is instructed to write a Python script to /tmp/gh-aw/token-audit/process_audit.py and then execute it. This is a multi-turn sequence (write file β†’ confirm write β†’ run β†’ read output) that adds 2–3 overhead turns.
  3. Chart upload / URL placeholder substitution (Phase 3): upload two assets, receive URLs, then craft the issue with embedded URLs β€” another multi-turn sequence.
  4. Duration spike on run Consolidate optimizer workflows into a single token optimizerΒ #60 (15.5 min): 7 more minutes than the 4-run average suggests one of the above sequences expanded noticeably.

Reliability

All 5 runs succeeded. No error or warning patterns. No waste from retries.


πŸ“‹ Ranked Recommendations

1. Trim the data schema table to essential fields only

Estimated savings: ~25 AIC/run

The prompt's "Pre-downloaded logs" section includes a 9-row Markdown table describing every field of a RunData object β€” including deprecated (effective_tokens) and rarely-used fields (error_count, warning_count, token_usage_summary). The agent's Python script only needs workflow_name, status, conclusion, aic, token_usage, turns, action_minutes, url, and run_id. The OTEL section also has a Note column and deprecation warnings adding noise.

Action: Reduce the schema table to the 9 fields actually used in Phase 1's aggregations, and remove the "effective_tokens β€” deprecated; use aic" row entirely. Estimated ~50-line reduction in the prompt body.

2. Condense or extract the OTEL experiment section

Estimated savings: ~12 AIC/run

The "Experiment OTEL Span Attributes" section is ~25 lines of JavaScript boilerplate that only activates when /tmp/gh-aw/experiments/assignments.json exists. It adds context overhead on every run regardless of whether experiments are active. It also includes a full code block that the agent must process on each turn.

Action: Reduce to a two-sentence conditional instruction: "If /tmp/gh-aw/experiments/assignments.json exists, call the logSpan OTEL helper (see the shared component for the pattern) to emit one gh_aw.experiment.<name> attribute per experiment key." If the full code block must be retained, move it to a shared component imported by reference.

3. Replace the "write script to file then run" pattern with inline Python execution

Estimated savings: ~15 AIC/run

Phase 1 tells the agent to write a Python script to a named file and then execute it with a custom PYTHONPATH. Writing a file to disk, confirming the write, and then running it takes 2–3 extra turns compared to executing the Python logic inline via python3 -c '...' or a heredoc. The computation (grouping, aggregation, JSON output) is simple enough for either approach.

Action: Change Phase 1's instruction from "write a script to process_audit.py and run it" to "run the data processing inline using python3 << 'EOF' ... EOF with the PYTHONPATH prefix." Retain the schema and sort requirements in the instruction; just eliminate the write-to-file indirection. For the chart generation in Phase 3, a file script is still appropriate due to length.


🧩 Structural Optimization: Inline Sub-Agent for Log Processing

The workflow has no existing ## agent: blocks and has 4 distinct phases.

Phase 1 (Process Logs) as an inline sub-agent:

Dimension Score Reasoning
Independence 3/3 Reads only pre-downloaded files; no dependency on other phases
Small-model adequacy 3/3 Pure aggregation: group-by, sum, sort, serialize JSON
Parallelism 0/2 Phases 2, 3, 4 all depend on its output
Size 2/2 Writes a Python script + runs it; substantial enough
Total 8/10 Strong candidate

Proposed change:

In the main prompt, replace the Phase 1 block with:

## agent: process-logs
model: small

Read `/tmp/gh-aw/token-audit/workflow-logs.json`. Filter to `status == "completed"` runs. Group by `workflow_name` and compute: `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/missing `aic`/`token_usage` as 0. Sort descending by `total_ai_credits`. Write the result plus an overall summary to `/tmp/gh-aw/token-audit/audit_snapshot.json`.

Why a smaller model fits: This is pure ETL β€” load, aggregate, serialize. No strategic reasoning, no synthesis, no GitHub API calls. A smaller model handles Python aggregation reliably.

Expected savings from sub-agent: ~20 AIC/run (smaller model, fewer context tokens in that phase).


πŸ’° Combined Estimated Savings

Recommendation Est. AIC / run
Trim schema table ~25
Condense OTEL section ~12
Inline Python execution (Phase 1) ~15
Sub-agent for log processing ~20
Total ~72 AIC/run

At 5 runs/week Γ— ~223 AIC/run current spend, implementing all four could reduce weekly spend by ~32% (~360 AIC/week).


⚠️ Caveats

References: Β§30270012569 Β· Β§30008781105 Β· Β§30094628596

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

  • expires on Aug 3, 2026, 3:28 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