feat: add "Optimize token consumption" section to agent failure issues when a guardrail triggers#39069
Merged
Merged
Conversation
…for guardrail failures Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
feat: add "Optimize token consumption" section to agent failure issues for guardrail failures
feat: add "Optimize token consumption" section to agent failure issues when a guardrail triggers
Jun 13, 2026
Copilot created this pull request from a session on behalf of
pelikhan
June 13, 2026 11:50
View session
pelikhan
reviewed
Jun 13, 2026
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
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
Comment on lines
33
to
36
| - `.github/aw/messages.md` | ||
| - `.github/aw/network.md` | ||
| - `.github/aw/optimize-agentic-workflow.md` | ||
| - `.github/aw/patterns.md` |
Comment on lines
+61
to
+63
| - GitHub CLI (`gh`) is installed and authenticated | ||
| - The installation script completed without errors | ||
| - `~/.local/share/gh/extensions` is in your PATH |
Comment on lines
+93
to
+97
| 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 |
pelikhan
reviewed
Jun 13, 2026
| **Assign this issue to an agent** to debug and fix the issue. | ||
|
|
||
| <details> | ||
| {optimize_token_consumption_context}<details> |
Contributor
Author
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>
This was referenced Jun 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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}