Uh oh!
There was an error while loading. Please reload this page.
feat: add "Optimize token consumption" section to agent failure issues when a guardrail triggers - #39069
Conversation
…for guardrail failures Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds an “Optimize token consumption” path to guardrail-triggered agent failure issues, so users can reduce AI cost/turn usage directly (instead of only debugging). This extends the agent-failure issue template, adds a rendered details block template, and introduces new optimization prompt/skill content that can be loaded via fallback files.
Changes:
- Add an
optimize_token_consumption_contextdetails section (template + renderer) and wire it into agent-failure issue creation when guardrails trigger. - Introduce new optimization prompt content (
optimize.md,.github/aw/optimize-agentic-workflow.md) and a dedicated skill (.github/skills/optimize-agentic-workflow/SKILL.md). - Sync the new
.github/aw/optimize-agentic-workflow.mdinto the fallback file list and reference it from the router skill.
Show a summary per file
| File | Description |
|---|---|
| pkg/cli/data/agentic_workflows_fallback_aw_files.json | Adds optimize-agentic-workflow.md to the fallback .github/aw file set. |
| optimize.md | New root-level loader prompt that installs gh aw and delegates to the optimization prompt. |
| actions/setup/md/optimize_token_consumption_context.md | New issue-template snippet rendered when a guardrail triggers. |
| actions/setup/md/agent_failure_issue.md | Inserts {optimize_token_consumption_context} before the existing debug section. |
| actions/setup/js/handle_agent_failure.cjs | Adds buildOptimizeTokenConsumptionContext(...) and threads it into issue template context. |
| actions/setup/js/handle_agent_failure.test.cjs | Adds unit tests for buildOptimizeTokenConsumptionContext guardrail rendering and priority. |
| .github/skills/optimize-agentic-workflow/SKILL.md | New skill describing a guardrail-aware token/cost optimization workflow. |
| .github/skills/agentic-workflows/SKILL.md | Adds .github/aw/optimize-agentic-workflow.md to the router’s load list. |
| .github/aw/optimize-agentic-workflow.md | New optimization prompt with guardrail entry points and a structured improvement plan. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 9/9 changed files
- Comments generated: 3
| - `.github/aw/messages.md` | ||
| - `.github/aw/network.md` | ||
| - `.github/aw/optimize-agentic-workflow.md` | ||
| - `.github/aw/patterns.md` |
| - GitHub CLI (`gh`) is installed and authenticated | ||
| - The installation script completed without errors | ||
| - `~/.local/share/gh/extensions` is in your PATH |
| After measuring token usage, produce a prioritized plan: | ||
| 1. **Measure** — run `gh aw audit <run-id>` and summarize AI Credits and per-call token breakdown | ||
| 2. **Identify top cost drivers** — list the three most expensive phases/tool calls | ||
| 3. **Apply quick wins first** — DataOps pre-steps, `gh-proxy`, `cli-proxy`, prompt trimming |
| **Assign this issue to an agent** to debug and fix the issue. | ||
| <details> | ||
| {optimize_token_consumption_context}<details> |
There was a problem hiding this comment.
Fixed in the latest commit — {optimize_token_consumption_context} now occupies its own line before the <details> block.
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent failure issues caused by guardrail limits (
max-ai-credits,max-daily-ai-credits,max-tool-denials,max-turns/timeout) previously only offered a "Debug" path. This adds an "Optimize token consumption" details section inserted before the debug section, giving a direct path to reduce costs rather than just re-investigate the failure.New files
optimize.md— Root-level self-contained loader (mirrorsdebug.md): installsgh aw, then delegates to.github/aw/optimize-agentic-workflow.md.github/aw/optimize-agentic-workflow.md— Optimization prompt with guardrail-specific entry points (max-ai-credits,max-daily-ai-credits,max-tool-denials,max-turns/timeout), a structured analysis plan (measure → identify top cost drivers → quick wins → sub-agents → experiment → validate), and editing workflow.github/skills/optimize-agentic-workflow/SKILL.md— Proper skill (withname:+description:frontmatter) exposing the same optimization guidance; referenced by the agentic-workflows router for "Optimize token usage and cost" tasksactions/setup/md/optimize_token_consumption_context.md— Template rendered into the issue section:Optimize the agentic workflow token consumption using https://raw.githubusercontent.com/github/gh-aw/main/optimize.md
The workflow run is at {run_url}