Skip to content

⚡ Token optimization for pelis-agent-factory-advisor (~151K tokens/run, −11%)#1718

Merged
lpcox merged 3 commits intomainfrom
copilot/optimize-pelis-agent-tokens
Apr 6, 2026
Merged

⚡ Token optimization for pelis-agent-factory-advisor (~151K tokens/run, −11%)#1718
lpcox merged 3 commits intomainfrom
copilot/optimize-pelis-agent-tokens

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

The pelis-agent-factory-advisor workflow costs ~$2.02/run (1,399K tokens, 11 turns) due to oversized GitHub MCP toolset, sequential file reads on early turns, and a bloated Phase 4 template repeated across all turns.

Changes

  • Restrict GitHub toolset to context only — drops GITHUB_TOOLSETS from context,repos,issues,pull_requests (25 tools) to context (~2 tools); saves ~88K tokens/run

    tools:
      github:
        toolsets: [context]   # was: auto-included repos,issues,pull_requests
  • Parallel file read instruction — adds an efficiency note at the top of Phase 1 directing the agent to cat all four pre-fetched files in a single batched turn; collapses the turn-2 +19K token jump caused by sequential reads

  • Parallel status+audit instruction — top-level note + Phase 2.3 rewrite direct the agent to call agentic-workflows status and audit in the same turn instead of sequentially

  • Condense Phase 4 output template — reduces from ~103 lines to ~50 lines (~14K tokens/run saved); replaces repeated placeholder blocks with a compact 7-item numbered list

  • Recompile — regenerated pelis-agent-factory-advisor.lock.yml via gh aw compile + postprocess-smoke-workflows.ts

Projected outcome: ~1,248K tokens/run (−151K), ~$1.80/run (−$0.22), 8–9 LLM turns vs 11.

…arallel hints, condense Phase 4

Agent-Logs-Url: https://github.com/github/gh-aw-firewall/sessions/88a7333b-1b4b-4b0f-ae2d-0bc182b4ad03

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Optimize token usage in Pelis Agent Factory Advisor ⚡ Token optimization for pelis-agent-factory-advisor (~151K tokens/run, −11%) Apr 6, 2026
Copilot AI requested a review from lpcox April 6, 2026 18:42
Copilot finished work on behalf of lpcox April 6, 2026 18:42
@lpcox lpcox marked this pull request as ready for review April 6, 2026 19:36
@lpcox lpcox requested a review from Mossaka as a code owner April 6, 2026 19:36
Copilot AI review requested due to automatic review settings April 6, 2026 19:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces token usage in the pelis-agent-factory-advisor agentic workflow by shrinking the GitHub MCP tool prompt, encouraging batched tool calls, and shortening the Phase 4 output template to avoid repeated boilerplate across turns.

Changes:

  • Restricts GitHub MCP toolsets to context only to reduce prompt/tooling token overhead.
  • Updates the workflow guidance to batch file reads and combine agentic-workflows status + audit in one turn.
  • Condenses the Phase 4 output template and recompiles the generated .lock.yml.
Show a summary per file
File Description
.github/workflows/pelis-agent-factory-advisor.md Narrows GitHub toolset + adds batching guidance + compacts output template.
.github/workflows/pelis-agent-factory-advisor.lock.yml Regenerated compiled workflow; reflects toolset restriction and other compile-time deltas.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment on lines 89 to +92
## Phase 1: Learn Pelis Agent Factory Patterns

> **Efficiency note:** Read all required files in a **single parallel batch** — call `bash:cat` for `.content-hash.txt`, `.pelis-agent-factory-docs.txt`, `.agentics-patterns.txt`, and `.repo-structure.txt` simultaneously in your first turn. Do not read them one at a time.

Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Phase 1 cache logic says to compare .content-hash.txt to pelis_docs_hash and skip reading docs/patterns when unchanged, but the new Efficiency note instructs reading .pelis-agent-factory-docs.txt and .agentics-patterns.txt in the first turn unconditionally. This can increase token usage on cache hits and contradicts the skip behavior. Consider batching only .content-hash.txt (and optionally .repo-structure.txt) first, then reading the doc/pattern files in a subsequent turn only when the hash differs.

See below for a potential fix:

> **Efficiency note:** Use **batched reads**, but preserve the cache gate. In your first turn, call `bash:cat` for `.content-hash.txt` and `.repo-structure.txt` together. Only if the hash is changed or missing should you make a second parallel batch to read `.pelis-agent-factory-docs.txt` and `.agentics-patterns.txt`. Do not read the doc/pattern files on cache hits.

Check cache-memory for `pelis_docs_hash`. Read the precomputed hash from
`.content-hash.txt` and compare it to the cached value.
If unchanged, skip reading `.pelis-agent-factory-docs.txt` and `.agentics-patterns.txt` and continue to Phase 2 using cached knowledge.
Otherwise read those files in a single parallel batch and update the hash in cache-memory.

Copilot uses AI. Check for mistakes.
Comment on lines 42 to 46
name: "Pelis Agent Factory Advisor"
"on":
schedule:
- cron: "26 21 * * *"
- cron: "29 10 * * *"
# Friendly format: daily (scattered)
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiled workflow’s daily cron time changed ("26 21" -> "29 10"). The PR description doesn’t mention a schedule shift; if this is unintentional (e.g., a recompile side effect), it will change when the advisor runs each day. Please confirm whether the new cron is intended and, if not, adjust the source .md/compile settings to keep the prior run time.

Copilot uses AI. Check for mistakes.
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented Apr 6, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 6, 2026

@copilot apply changes based on the comments in this thread

Applied in 899f815. The Phase 1 efficiency note now preserves the cache gate: the first turn batches only .content-hash.txt + .repo-structure.txt, and only if the hash is changed or missing does the agent make a second parallel batch to read .pelis-agent-factory-docs.txt and .agentics-patterns.txt. Doc/pattern files are not read on cache hits.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/github/gh-aw-actions/git/ref/tags/v0.67.1
    • Triggering command: /usr/bin/gh gh api /repos/github/gh-aw-actions/git/ref/tags/v0.67.1 --jq .object.sha (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of lpcox April 6, 2026 19:53
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 86.20% 86.29% 📈 +0.09%
Statements 86.07% 86.16% 📈 +0.09%
Functions 87.41% 87.41% ➡️ +0.00%
Branches 78.57% 78.62% 📈 +0.05%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/docker-manager.ts 86.6% → 87.0% (+0.39%) 86.1% → 86.5% (+0.38%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Smoke test results (run 24048276590)

Overall: PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

🔥 Smoke Test Results

Test Status
GitHub MCP connectivity
GitHub.com HTTP
File write/read

PR: ⚡ Token optimization for pelis-agent-factory-advisor (~151K tokens/run, −11%)
Author: @Copilot | Assignees: @lpcox @Copilot

Overall: PASS 🟢

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Security Review: PR #1718 — Pelis Agent Factory Advisor Token Optimization

Overall: One security regression, two security improvements, no critical issues.


⚠️ Security Regression: Unpinned Action References

File: .github/workflows/pelis-agent-factory-advisor.lock.yml (multiple locations, e.g. line 74, 301, 939, 1053, 1244)

Before:

uses: github/gh-aw-actions/setup@cde65c546c2b0f6d3f3a9492a04e6687887c4fe8 # v0.67.0

After:

uses: github/gh-aw-actions/setup@v0.67.1

Floating tags can be silently moved to point to a different commit (whether via accidental force-push or supply chain compromise). Pinning to a commit SHA guarantees the exact action code. This change appears to originate from the v0.67.1 compiler generating unpinned references — if that's intentional behavior in the new compiler, it should be documented as an accepted trade-off.

Suggested action: Re-pin to the v0.67.1 commit SHA, or document this as a deliberate compiler policy change in the lock file header.


✅ Security Improvements Noted

  1. Restricted GitHub toolsets (.lock.yml line 669, .md lines 17–18): GITHUB_TOOLSETS reduced from context,repos,issues,pull_requests (~25 tools) to context (~2 tools). This meaningfully reduces the agent's GitHub API blast radius and limits prompt-injection lateral movement opportunities.

  2. Token moved to env var (.lock.yml lines 358–359, 766–767): $\{\{ github.token }} is now set as GITHUB_TOKEN env var rather than interpolated inline in the shell run: block, reducing the risk of the token appearing in process arguments or debug logs.


No issues found in iptables rules, Squid config, container capabilities, seccomp profile, domain patterns, or other core firewall security components — this PR does not touch those files.

Generated by Security Guard for issue #1718 · ● 64K ·

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Smoke test results:

  • PR titles: Fix Secret Digger (Copilot): reframe prompt to avoid safety policy false positive
  • PR titles: ⚡ pelis-agent-factory-advisor: pre-fetch content, restrict tools, reduce prompt tokens (~21% token savings)
  • GitHub MCP (last 2 merged PRs): ✅
  • safeinputs-gh pr list --json ...: ❌
  • Playwright title contains "GitHub": ❌
  • Tavily search returned >=1 result: ❌
  • File write/read + bash cat: ✅
  • Discussion query/comment: ❌
  • npm ci && npm run build: ✅
    Overall status: FAIL

🔮 The oracle has spoken through Smoke Codex

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

Smoke Test: GitHub Actions Services Connectivity

Check Status Notes
Redis PING (host.docker.internal:6379) ❌ FAIL redis-cli not installed; could not install (no apt access)
pg_isready (host.docker.internal:5432) ❌ FAIL no response (exit 2)
psql SELECT 1 (smoketest db) ❌ FAIL timeout expired connecting to 172.17.0.1:5432

All checks failed. host.docker.internal resolves to 172.17.0.1 but services are not reachable from this environment (no sudo, no apt, and host ports appear firewalled).

🔌 Service connectivity validated by Smoke Services

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 6, 2026

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx All passed ✅ PASS
Node.js execa All passed ✅ PASS
Node.js p-limit All passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #1718 · ● 1.3M ·

@lpcox lpcox merged commit ba75642 into main Apr 6, 2026
58 of 60 checks passed
@lpcox lpcox deleted the copilot/optimize-pelis-agent-tokens branch April 6, 2026 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

⚡ Copilot Token Optimization2026-04-06 — Pelis Agent Factory Advisor

3 participants