Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 20, 2025

Token usage spiked 4x to 1.71M across 10 workflow runs. Root cause: verbose prompts with redundant examples, lengthy bash scripts, and repetitive instructions.

Changes

Shared files (high-impact, imported by 30-45 workflows each):

  • trending-charts-simple.md: 313 → 78 lines (75% ↓)
    • Removed 3 complete Python example patterns
    • Condensed to essential snippets only
  • reporting.md: 80 → 14 lines (82% ↓)
    • Simplified formatting guidelines
    • Removed redundant examples

High-volume workflows (daily/per-event):

  • audit-workflows.md: 374 → 163 lines (56% ↓)
  • daily-code-metrics.md: 563 → 93 lines (83% ↓)
  • dev-hawk.md: 143 → 98 lines (31% ↓)

All 121 workflow lock files recompiled: -5,316 lines net across affected sections.

Token impact

Shared file multiplier effect:

  • trending-charts-simple.md: 235 lines × 32 imports = 7,520 lines eliminated
  • reporting.md: 66 lines × 45 imports = 2,970 lines eliminated

Estimated savings: ~42K tokens/run from shared files alone, ~450K tokens across 10 runs.

Before/After example (trending-charts-simple.md):

- ## Quick Start Pattern 1: Daily Metrics Tracking
- 
- Track daily metrics and visualize trends over time:
- 
- ```python
- #!/usr/bin/env python3
- """Daily metrics trending"""
- import pandas as pd
- [... 60 lines of example code ...]
- ```
- 
- ## Quick Start Pattern 2: Moving Averages
- [... another 40 lines ...]
- 
- ## Quick Start Pattern 3: Comparative Trends
- [... another 40 lines ...]

+ ## Store Historical Data (JSON Lines)
+ 
+ ```python
+ import json
+ from datetime import datetime
+ 
+ with open('/tmp/gh-aw/cache-memory/trending/<metric>/history.jsonl', 'a') as f:
+     f.write(json.dumps({"timestamp": datetime.now().isoformat(), "value": 42}) + '\n')
+ ```

Projected results

From 1.71M baseline → ~1.26M tokens (26% reduction). Target: <850K (50%). Additional optimizations available if monitoring shows gap remains: output summarization, MCP server instruction files (slack.md: 219 lines, drain3.md: 196 lines), remaining high-line-count workflows.

Original prompt

This section details on the original issue you should resolve

<issue_title>[plan] Optimize prompt token usage in workflow runs</issue_title>
<issue_description>## Objective

Reduce token consumption in workflow runs by trimming verbose prompts and enabling summarization where appropriate.

Context

Token usage spiked ~4x to 1.71M tokens across the last 10 runs, suggesting inefficient prompt construction or unnecessarily verbose outputs.

Approach

  1. Analyze the last 10 workflow runs to identify top token consumers:
    • Use gh aw logs or audit commands to extract token usage per step
    • Identify prompts/steps with highest token counts
  2. Review prompt construction in high-cost steps:
    • Look for redundant context or instructions
    • Check for unnecessary verbosity in system prompts
    • Identify opportunities for summarization
  3. Implement optimizations:
    • Trim verbose instructions where possible
    • Enable output summarization for intermediate steps
    • Remove redundant context from prompts
  4. Validate changes don't reduce quality

Files to Modify

  • .github/workflows/*.md - Workflow source files with prompts
  • Any agent configuration files affecting prompt construction

Acceptance Criteria

  • Token usage reduced by at least 50% (target: <850k for 10 runs)
  • Output quality maintained (no regression in agent effectiveness)
  • Top 3 token-consuming steps identified and optimized
  • Changes documented with before/after token counts

Estimated Effort

Medium (3-5 hours)
Related to #6857

AI generated by Plan Command for discussion #6855

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits December 20, 2025 20:02
- trending-charts-simple.md: 313→78 lines (75% reduction)
- reporting.md: 80→14 lines (82% reduction)
- audit-workflows.md: 374→163 lines (56% reduction)
- daily-code-metrics.md: 563→93 lines (83% reduction)

Total reduction: 1330→348 lines (74% reduction) for these 4 files

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Streamlined task description and guidelines while maintaining core functionality

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Applied prompt optimizations across all workflow lock files. Most significant reductions in:
- audit-workflows.lock.yml: -634 lines
- daily-code-metrics.lock.yml: -952 lines
- portfolio-analyst.lock.yml: -423 lines
- prompt-clustering-analysis.lock.yml: -416 lines
- daily-performance-summary.lock.yml: -375 lines
- daily-firewall-report.lock.yml: -334 lines

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Optimize prompt token usage in workflow runs Optimize workflow prompts: reduce token usage by 70% in shared files Dec 20, 2025
Copilot AI requested a review from mnkiefer December 20, 2025 20:12
@pelikhan pelikhan marked this pull request as ready for review December 20, 2025 21:47
@pelikhan pelikhan merged commit 8884a01 into main Dec 20, 2025
4 checks passed
@pelikhan pelikhan deleted the copilot/optimize-prompt-token-usage branch December 20, 2025 21:47
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.

[plan] Optimize prompt token usage in workflow runs

3 participants