Skip to content

Token optimization: scope glossary-maintainer toolsets and pre-fetch git history#25228

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/optimize-glossary-maintainer-token-usage
Draft

Token optimization: scope glossary-maintainer toolsets and pre-fetch git history#25228
Copilot wants to merge 3 commits intomainfrom
copilot/optimize-glossary-maintainer-token-usage

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 8, 2026

The Glossary Maintainer was consuming 3.8M tokens/run, with search_repositories accounting for 342 of 588 total tool calls (58%) — a global GitHub search tool that's irrelevant to a local glossary update task. issue_read added another 232 unnecessary calls.

Changes

  • Scoped GitHub toolsets: [default][repos, pull_requests], eliminating search_repositories from the available tool surface
  • Removed issues: read permission: glossary maintenance has no need for issue data
  • Full checkout with complete git history: added checkout: fetch-depth: 0 so git log --since in the pre-step can traverse the full commit history rather than the default shallow clone
  • Added pre-execution bash step: runs git log before the agent starts, writing commit history and doc-touching commits to /tmp/gh-aw/agent/ files the agent reads directly — eliminates ~45 data-gathering API turns
  • Updated prompt instructions: "Determine Scan Scope" now reads pre-fetched files; "Scan Recent Changes" caps API calls to 20 commits and 10 PRs
  • Added ## Constraints section to the prompt: explicit hard limits on search_repositories, issue reading, commit/PR counts, and repository scope
checkout:
  fetch-depth: 0  # full history required so git log --since works across all commits

tools:
  github:
    toolsets: [repos, pull_requests]  # scoped to avoid search_repositories (in default)
# Pre-step: agent reads these instead of making API calls
git log --since="$SINCE" --oneline --name-only > /tmp/gh-aw/agent/recent-commits.txt
git log --since="$SINCE" --name-only --format="%H %s" -- 'docs/**/*.md' 'docs/**/*.mdx' > /tmp/gh-aw/agent/doc-changes.txt

…p, add constraints

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a1c03712-96c0-4e67-995f-d798bab63ca6

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Optimize token usage for glossary maintainer Token optimization: scope glossary-maintainer toolsets and pre-fetch git history Apr 8, 2026
Copilot AI requested a review from pelikhan April 8, 2026 02:26
echo "Scan scope: $SCOPE (since: $SINCE)"

# Fetch recent commits (all files) — includes file names for context
git log --since="$SINCE" --oneline --name-only \
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot use the checkout feature to get a non-sparse checkout of the repo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added checkout: fetch-depth: 0 to the frontmatter in 4e0511b. This configures a full (non-sparse) checkout with complete git history, ensuring git log --since='24 hours ago' and --since='7 days ago' in the pre-step can see all commits rather than just the shallow single-commit default.

Copilot AI requested a review from pelikhan April 8, 2026 02:42
@g66b166-hub
Copy link
Copy Markdown

#23758

@github-actions github-actions bot added the spam label Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[copilot-token-optimizer] Token Optimization: Glossary Maintainer — search_repositories overuse (342 calls/run)

3 participants