Skip to content

[agentic-token-optimizer] Optimize: Agentic Workflow AIC Usage Optimizer — Prompt Compression + Batched Data Reads #282

Description

@github-actions

Target Workflow

Agentic Workflow AIC Usage Optimizer (agentic-token-optimizer) — selected as the highest-AIC workflow (1,222.7 AIC over 5 runs) with the longest time since last optimization (7 days, 2026-07-07). All other top workflows were optimized within the past 6 days.

Analysis Period

2026-07-07 → 2026-07-13 · 5 completed runs · 0 errors

Spend Profile

Metric Value
Total AIC 1,222.7
Avg AIC / run ~244.5
AIC range 117.7 – 457.1
Total tokens (4 runs w/ data) ~3,130,879
Avg tokens / run ~782,720
Avg turns / run ~19.8 (range: 12 – 30)
Cache efficiency Unknown (cached_tokens not populated)
Avg action minutes ~10 min

The most striking signal is 2.5× AIC variance between the cheapest and most expensive run, driven entirely by turn count (12 vs 30 turns). All runs succeeded — the cost difference is structural, not failure-related.

Per-run breakdown
Run Date AIC Tokens Turns Minutes
§29261856115 2026-07-13 128.1 365,343 12 7
§29103043998 2026-07-10 117.7 9
§29029816674 2026-07-09 457.1 1,296,897 30 14
§28953250425 2026-07-08 353.6 1,008,833 24 11
§28877782118 2026-07-07 166.1 459,806 13 9

Ranked Recommendations

1. Add an explicit upfront data-load block at Phase 1 start

Estimated savings: ~25–40 AIC/run

The prompt currently documents batching in "Data Access Guidelines" but does not mandate it at execution time. High-turn runs (24–30 turns) suggest the agent reads all-runs.json, top-workflows.json, optimization-log.json, and daily snapshot files sequentially — one tool call per file. With ~30k tokens/turn average, 4 sequential reads instead of 1 batched block costs ~3 extra turns ≈ 90k tokens.

Action: Add an explicit instruction at the start of Phase 1:

Before any analysis, read all data sources in a single bash block: all-runs.json, top-workflows.json, optimization-log.json, and the most recent daily snapshot. Do not make separate tool calls for each file.

This should normalize turn counts toward the efficient end (12 turns) and is low-risk — it doesn't change what data is read, only when.

References: §29029816674 (30 turns, 457 AIC) vs §29261856115 (12 turns, 128 AIC)


2. Compress the "Data Access Guidelines" section

Estimated savings: ~8–12 AIC/run

The "Data Access Guidelines" section is ~1,200 bytes containing 5 fenced code-block examples. These examples are loaded into context on every turn (~20 avg). They show patterns the agent already follows when efficient — they do not appear to be referenced mid-run.

Action: Replace the 5 code examples with a 2-sentence rule:

Always use --jq to filter gh api responses inline. Read multiple files in a single bash block with &&; never make a separate tool call per file.

This removes ~800 bytes × avg 20 turns ≈ 16k tokens saved per run.


3. Compress Phase 4 scoring matrix and Phase 5 formatting requirements

Estimated savings: ~5–8 AIC/run

Phase 4 contains a 5-column scoring table with per-dimension explanations (~600 bytes). Phase 5 contains detailed formatting requirements with 6 bullet points (~400 bytes). Together ~1,000 bytes × 20 turns ≈ 20k tokens/run of repeated overhead.

Action: Condense Phase 4 scoring to a single line per dimension (keep only the score and criterion). Condense Phase 5 formatting rules to a 4-bullet list removing the "if you recommend sub-agents" clause (which already appears in Phase 4).


4. Inline Sub-Agent for Phase 4 Structural Analysis (moderate candidate)

Estimated savings: ~10–15 AIC/run

Phase 4 (structural optimization checks) is a bounded extractive task: read a workflow source, check for repeated setup prefixes, and score major sections on 4 dimensions. This is well-suited for a smaller model.

Dimension Score Notes
Independence 1 / 3 Needs Phase 3 workflow source
Small-model adequacy 3 / 3 Pattern-matching and scoring — no synthesis
Parallelism 0 / 2 Sequential after Phase 3
Size 2 / 2 Substantial enough to justify agent call
Total 6 / 10 Moderate candidate

The workflow has no existing ## agent: blocks and 10 major sections, satisfying the eligibility criteria.

Proposed invocation change: After Phase 3 completes (workflow source in context), delegate to:

## agent: haiku
Read the workflow source provided. Check each ## section for repeated opening setup instructions or shell calls. Score each major section on: Independence (0-3), Small-model adequacy (0-3), Parallelism (0-2), Size (0-2). Return a JSON object with keys: setup_prefix_sections (list of section names with shared setup), section_scores (list of {section, score, rationale}).

The main agent then uses this structured output to write Phase 4 findings without re-reading the source or doing its own scoring, saving 3–5 turns of exploratory analysis.

Caveats

  • Only 5 runs in the 7-day window; recommendations on turn-count outliers are based on 3 high-data-point runs.
  • cached_tokens is not populated in logs — cache efficiency cannot be assessed; if caching is already active for the prompt prefix, savings from prompt compression may be lower.
  • Turn-count variance may also reflect genuine complexity differences (longer target workflow sources require more Phase 3/4 analysis). The batching recommendation addresses the structural overhead independent of target complexity.
  • Sub-agent recommendation (Rec 4) introduces a new tool call per run; if Phase 3 target is a short workflow, the overhead may not pay off.

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

  • expires on Jul 21, 2026, 3:09 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    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