Target Workflow: smoke-copilot-byok-aoai-entra
Source report: #7850
Estimated cost per run: $0.00 (Copilot enterprise billing; token volume is the real cost driver)
Total tokens per run: ~130K (avg of 3 runs: 102,056 / 183,487 / 104,155)
Cache hit rate: Poor — average rebuild_factor 4.9x (peak input ~25K vs. cumulative input 100K–176K), meaning ~77% of input tokens per run are re-sent context that isn't served from cache
LLM turns (invocations): avg 5 (range 4–7)
Current Configuration
| Setting |
Value |
| Tools loaded |
bash: ["*"] (unrestricted), github: toolsets: [pull_requests] |
| Tools actually used |
bash (cat, curl already done in pre-step), github-list_pull_requests (1 call), safe-outputs add_comment/add_labels/noop |
| 网络 groups |
defaults, github, login.microsoftonline.com (all required — Entra OIDC token exchange) |
| Pre-agent steps |
Yes — fetches PR data, HTTP check, file write/read, writes results to /tmp/gh-aw/agent/*.txt |
| Post-agent steps |
Yes — validates safe outputs and BYOK firewall traffic |
| Prompt size |
~10,408 chars / 206 lines (mostly narrative explaining BYOK/Entra mechanics) |
Recommendations
1. Cut agent turns from ~5 to ~2 by trusting pre-computed results instead of re-verifying them live
Estimated savings: ~55K tokens/run (~42%), based on rebuild_excess_tokens averaging ~100K/run across 4–7 invocations — each extra turn re-sends the growing conversation.
The pre-agent step already writes smoke-file-content.txt, smoke-http-code.txt, and smoke-pr-data.txt to disk. The current prompt still instructs the agent to (a) call github-list_pull_requests live and compare, and (b) run cat on the file path to "confirm it exists" — both are redundant verification round-trips on top of the pre-computed data, and each one is a separate tool-call turn that forces the full context to be re-sent.
Change the prompt (### 1. GitHub MCP Testing and ### 3. File Write/Read Test sections) to:
### 1. GitHub MCP Testing
Use the Pre-Fetched PR Data below (from `/tmp/gh-aw/agent/smoke-pr-data.txt`, already read into this prompt). No live tool call is needed — the pre-agent step already exercised MCP-equivalent connectivity. Mark ✅ if data was successfully fetched (non-empty, no "(PR fetch failed)" marker), ❌ otherwise.
### 3. File Write/Read Test
Pre-step wrote and read back the file content shown above. Trust this result without an additional `cat` call — the pre-agent step already performed and validated the write/read cycle. Mark ✅.
This drops the two live-verification tool calls that are currently driving turns 2–4 (and the associated 25K-token context resend per turn).
2. Trim prompt narrative to reduce fixed cost of every turn
Estimated savings: ~4K tokens/run (~3%), ~800 tokens/turn × 5 turns
The "Purpose" section (3 dense paragraphs explaining BYOK/Entra/OIDC mechanics) is documentation-oriented, not needed by the agent to complete the checklist. Replace:
## Purpose
This smoke test validates that Copilot CLI runs in **direct BYOK mode against Azure OpenAI (Foundry) using Microsoft Entra authentication**...
[3 paragraphs]
with:
## Purpose
Validates direct BYOK mode against Azure OpenAI (Foundry) via Microsoft Entra (GitHub OIDC → Azure AD). Sibling workflows: `smoke-copilot-byok-aoai-apikey` (api-key path), `smoke-copilot-byok` (CAPI path).
Keep the detailed narrative in the workflow's description: frontmatter field (already present) and/or README — it doesn't need to be re-sent to the model every turn.
3. Restrict bash tool to only the commands actually needed
Estimated savings: Minimal direct token savings (bash tool schema token cost is fixed regardless of allowlist), but reduces attack surface and avoids the agent wandering into unnecessary exploratory bash calls that add turns.
Current: bash: ["*"]. The agent only needs to cat a known file path (if recommendation #1 above is not applied) — no need for unrestricted bash. Replace with:
tools:
bash:
- "cat *"
github:
toolsets: [pull_requests]
If recommendation #1 is applied (dropping the live cat check), bash can likely be removed from tools: entirely, since all deterministic work already happens in the pre-agent steps: block.
4. Investigate driver_exit failure separately (reliability, not token, issue)
Run 33188200632 failed with failure_kind: driver_exit and error_count: 1 while still consuming 104K tokens — failed runs still cost the full token budget without producing a usable result. This doesn't reduce tokens directly but is worth flagging: a driver crash mid-run wastes the entire run's token spend. timeout-minutes: 15 is already set at the workflow level, which is reasonable; no change recommended here beyond monitoring.
Expected Impact
| Metric |
Current |
Projected |
Savings |
| Total tokens/run |
~130K |
~70K |
-46% |
| LLM turns |
~5 |
~2 |
-3 |
| Cache rebuild excess |
~100K/run |
~20K/run |
-80% |
| Session time |
4.5–8.8 min |
~2–3 min (est.) |
~-50% |
Implementation Checklist
Generated by Daily Copilot Token Optimization Advisor · copilot · auto · 37.8 AIC · ⊞ 10.7K · ◷
Target Workflow:
smoke-copilot-byok-aoai-entraSource report: #7850
Estimated cost per run: $0.00 (Copilot enterprise billing; token volume is the real cost driver)
Total tokens per run: ~130K (avg of 3 runs: 102,056 / 183,487 / 104,155)
Cache hit rate: Poor — average
rebuild_factor4.9x (peak input ~25K vs. cumulative input 100K–176K), meaning ~77% of input tokens per run are re-sent context that isn't served from cacheLLM turns (invocations): avg 5 (range 4–7)
Current Configuration
bash: ["*"](unrestricted),github: toolsets: [pull_requests]bash(cat, curl already done in pre-step),github-list_pull_requests(1 call), safe-outputsadd_comment/add_labels/noopdefaults,github,login.microsoftonline.com(all required — Entra OIDC token exchange)/tmp/gh-aw/agent/*.txtRecommendations
1. Cut agent turns from ~5 to ~2 by trusting pre-computed results instead of re-verifying them live
Estimated savings: ~55K tokens/run (~42%), based on
rebuild_excess_tokensaveraging ~100K/run across 4–7 invocations — each extra turn re-sends the growing conversation.The pre-agent step already writes
smoke-file-content.txt,smoke-http-code.txt, andsmoke-pr-data.txtto disk. The current prompt still instructs the agent to (a) callgithub-list_pull_requestslive and compare, and (b) runcaton the file path to "confirm it exists" — both are redundant verification round-trips on top of the pre-computed data, and each one is a separate tool-call turn that forces the full context to be re-sent.Change the prompt (
### 1. GitHub MCP Testingand### 3. File Write/Read Testsections) to:This drops the two live-verification tool calls that are currently driving turns 2–4 (and the associated 25K-token context resend per turn).
2. Trim prompt narrative to reduce fixed cost of every turn
Estimated savings: ~4K tokens/run (~3%), ~800 tokens/turn × 5 turns
The "Purpose" section (3 dense paragraphs explaining BYOK/Entra/OIDC mechanics) is documentation-oriented, not needed by the agent to complete the checklist. Replace:
with:
Keep the detailed narrative in the workflow's
description:frontmatter field (already present) and/or README — it doesn't need to be re-sent to the model every turn.3. Restrict
bashtool to only the commands actually neededEstimated savings: Minimal direct token savings (bash tool schema token cost is fixed regardless of allowlist), but reduces attack surface and avoids the agent wandering into unnecessary exploratory bash calls that add turns.
Current:
bash: ["*"]. The agent only needs tocata known file path (if recommendation #1 above is not applied) — no need for unrestricted bash. Replace with:If recommendation #1 is applied (dropping the live
catcheck),bashcan likely be removed fromtools:entirely, since all deterministic work already happens in the pre-agentsteps:block.4. Investigate driver_exit failure separately (reliability, not token, issue)
Run
33188200632failed withfailure_kind: driver_exitanderror_count: 1while still consuming 104K tokens — failed runs still cost the full token budget without producing a usable result. This doesn't reduce tokens directly but is worth flagging: a driver crash mid-run wastes the entire run's token spend.timeout-minutes: 15is already set at the workflow level, which is reasonable; no change recommended here beyond monitoring.Expected Impact
Implementation Checklist
### 1. GitHub MCP Testingand### 3. File Write/Read Testsections in.github/workflows/smoke-copilot-byok-aoai-entra.mdto trust pre-computed results instead of re-verifying live## Purposesection to 1–2 sentencesbash:tool entry once livecatverification is droppedgh aw compile .github/workflows/smoke-copilot-byok-aoai-entra.mdnpx tsx scripts/ci/postprocess-smoke-workflows.ts