optimize-agentic-workflow

Analyze and reduce token consumption in GitHub Agentic Workflows.

5.1k|530|Updated Aug 12, 2025
One-click install
npx skills add https://github.com/github/gh-aw --skill optimize-agentic-workflow
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: optimize-agentic-workflow
Source: https://github.com/github/gh-aw/tree/main/.github/skills/optimize-agentic-workflow
Command: npx skills add https://github.com/github/gh-aw --skill optimize-agentic-workflow

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Agentic workflows running through GitHub Actions can consume excessive AI tokens and credits, hit guardrails like max-ai-credits or max-turns, and incur unnecessary cost. This Skill diagnoses where tokens are spent and produces a prioritized optimization plan.

Core Features & Use Cases

  • Run Auditing: Uses gh aw audit and gh aw logs to inspect AI credits, input/output tokens, and cache-read tokens per run.
  • Guardrail-Specific Diagnosis: Provides targeted entry points for max-ai-credits, max-daily-ai-credits, max-tool-denials, and timeout/max-turns failures.
  • Optimization Planning: Applies quick wins such as DataOps pre-steps, prompt trimming, sub-agent delegation, prompt caching, and experiments with the aic metric.
  • Use Case: A scheduled triage workflow keeps exhausting its daily AI credit budget. Provide the run URL, and the Skill audits token usage, identifies the most expensive tool calls, and proposes batching and cheap-triage changes before recompiling the workflow.

Quick Start

Ask the agent to audit a GitHub Actions run URL and propose token optimizations for the workflow.

Frequently Asked Questions about optimize-agentic-workflow

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce token usage in GitHub Agentic Workflows?

Run gh aw audit <run-id> --json to inspect AI credits and per-call token breakdowns, then apply quick wins like DataOps pre-steps, prompt trimming, sub-agent delegation, and prompt caching. Recompile with gh aw compile and validate output quality.

How to fix max-ai-credits exceeded errors in gh-aw workflows?

Identify which tool calls dominated token usage in token-usage.jsonl, check whether large payloads are front-loaded instead of fetched on demand, and delegate repetitive extraction to small-model sub-agents instead of the frontier model.

What causes max-tool-denials failures in agentic workflows?

The Copilot SDK hit the tool-denial threshold because the prompt attempted actions outside the allowed tool policy. Check the last denied reason, verify the tool is in the workflow's permissions or firewall config, or revise the prompt to avoid the denied operation.

Can I compare token costs between two workflow runs?

Yes, run gh aw audit <base-run-id> <optimized-run-id> to compare runs. You can also add an experiments entry and use metric: "aic" to choose among equivalent-quality variants based on AI credit consumption.

Why does my agentic workflow time out or exceed max-turns?

The agent ran out of time or turns before completing the task. Decompose the task into smaller sub-tasks, replace long-running tool calls with DataOps pre-steps, or raise max-turns and timeout-minutes if the task cannot be split.