Skip to content

optimize(detection-analysis-report): ~45 AIC/run savings via prompt compaction and script extraction#45820

Merged
pelikhan merged 3 commits into
mainfrom
copilot/agentic-token-optimizer-detection-analysis
Jul 15, 2026
Merged

optimize(detection-analysis-report): ~45 AIC/run savings via prompt compaction and script extraction#45820
pelikhan merged 3 commits into
mainfrom
copilot/agentic-token-optimizer-detection-analysis

Conversation

Copilot AI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

The detection-analysis-report workflow spent ~164 AIC/run with high output tokens (17,784) from runtime code generation and redundant prompt context. This implements four optimizer recommendations to cut ~45 AIC/run.

Changes

.github/scripts/detection_comparison.py (new)

Committed chart generation script that was previously written from scratch by the agent on every run (~100 lines of Matplotlib/Seaborn). Accepts --metrics and --output args; reads pre-computed metrics.json, emits a grouped bar + success-rate line overlay chart at 150 DPI.

Step 5 reduced from a code-generation instruction to:

python3 .github/scripts/detection_comparison.py \
  --metrics /tmp/gh-aw/python/data/metrics.json \
  --output /tmp/gh-aw/python/charts/detection_comparison.png

detection-analysis-report.md

  • Step 1: Removed inline MCP tool parameter documentation block — agent already receives this via tool-list injection (~300 redundant tokens, ~10 AIC)
  • Steps 2–4 → ### Analyze Runs: Merged three separately-headed sections (Classify, Misconfigured, Metrics) into one pass with a single field list and one output JSON schema — eliminates field re-enumeration across section boundaries (~80 tokens, ~5–8 AIC)
  • Step 6: Delegated historical trending (JSONL append + conditional trend chart) to a model: small sub-agent (update-detection-trending); small models cost 10–20× less than the parent claude-opus model

Skipped

  • Rec 1 (remove shared/otlp.md): Import is transitive through daily-audit-base.md and provides active OTLP endpoint config — removing it would silently drop telemetry
  • Rec 5 (trending-charts-simple cache hint): Requires compiler-level directive not yet supported in gh-aw

Copilot AI and others added 2 commits July 15, 2026 21:56
- Simplify Step 1: remove redundant inline MCP tool documentation block
- Merge Steps 2-4 into single 'Analyze Runs' section to reduce context duplication
- Extract chart generation to .github/scripts/detection_comparison.py; replace Step 5 with direct bash invocation
- Add sub-agent 'update-detection-trending' (model: small) for Step 6 historical trending
- Recompile lock file

Closes #45770

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
… side-effect)

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add optimization for AIC savings in detection analysis report optimize(detection-analysis-report): ~45 AIC/run savings via prompt compaction and script extraction Jul 15, 2026
Copilot AI requested a review from pelikhan July 15, 2026 21:59
@pelikhan pelikhan marked this pull request as ready for review July 15, 2026 22:07
Copilot AI review requested due to automatic review settings July 15, 2026 22:07
@pelikhan pelikhan merged commit f0a3dd2 into main Jul 15, 2026
1 check passed
@pelikhan pelikhan deleted the copilot/agentic-token-optimizer-detection-analysis branch July 15, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Optimizes the detection-analysis workflow by reducing prompt overhead and extracting deterministic chart generation.

Changes:

  • Compacts run-analysis instructions.
  • Adds a reusable Python comparison-chart script.
  • Delegates historical trending to a small-model sub-agent.
Show a summary per file
File Description
.github/workflows/detection-analysis-report.md Streamlines analysis and delegates trending.
.github/workflows/detection-analysis-report.lock.yml Updates generated workflow metadata.
.github/scripts/detection_comparison.py Generates the comparison chart.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 3/3 changed files
  • Comments generated: 5
  • Review effort level: Medium

### Step 1 — Fetch Logs

Use the `agentic-workflows` MCP `logs` tool to download workflow runs from the last 24 hours:
Call `agenticworkflows logs --start-date -1d` to download workflow run directories to `/tmp/gh-aw/aw-mcp/logs`. Each run's `aw_info.json` contains `features["gh-aw-detection"]` (boolean), `status`, `total_tokens`, and `engine_id`. Use `features.gh-aw-detection` directly — do not infer detection status from `.lock.yml` files.

Flag a workflow as **misconfigured** when any of the following apply:
**Flag a workflow as misconfigured** when any of the following apply:
1. `gh-aw-detection: false` on a workflow with >3 total runs in the last 7 days
Comment on lines +38 to +39
regular_success = regular_runs - regular_failure
detection_success = detection_runs - detection_failure
Comment on lines +30 to +33
regular_runs = int(m.get("regular_runs", 0))
detection_runs = int(m.get("detection_runs", 0))
regular_success_rate = float(m.get("regular_success_rate", 0.0))
detection_success_rate = float(m.get("detection_success_rate", 0.0))
{"timestamp": "<ISO-8601 UTC>", "regular_runs": N, "detection_runs": N, "regular_success_rate": X.X, "detection_success_rate": X.X, "regular_avg_tokens": X, "detection_avg_tokens": X, "misconfigured_count": N}
```

If the history file has ≥7 entries, generate a 30-day trend chart at `/tmp/gh-aw/python/charts/detection_trend.png`:
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.82.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[agentic-token-optimizer] [AIC Optimizer] Detection Analysis Report — 5 optimizations (~45 AIC/run savings)

3 participants