Skip to content

[AHP/CLI:COGS] Grep Search Tool Output Optimization #322773

Description

@bhavyaus

The agent grep_search (findTextInFiles) tool was returning verbose, XML‑tagged results that dominated its tool‑call token usage. PRs #321601 and #321938 introduce a compact, grep‑style output format behind an experiment. Early results show the new format roughly halves the tokens returned by the tool with no loss of useful signal — a direct COGS win as we move CLI/AHP to the default agent.

What changed

  • New compact output format — A grep-style result (plain path followed by line:text, blank‑line separated) replaces the previous tag‑wrapped output. Gated by the experiment‑based setting github.copilot.chat.tools.grepSearch.outputFormat (tag | grep, default tag).
  • Token‑budget‑aware rendering + long‑line handling — Results render through prompt‑tsx, so they participate in token‑budget pruning (earlier files prioritized) and carry editor references instead of a single unprunable blob. Long lines are truncated to a max length with context kept around the match.
  • Smarter result capping — The maxResults budget is distributed proportionally across matching files (largest‑remainder, min one match per file), and paths are returned workspace‑relative.

Experiment

https://exp.microsoft.com/features/30687fdb-eb7c-dbe8-06c4-02c5ece0671a/progressions?workspaceId=dbd12384-5001-4e90-a863-526321eaf233

agent.tool.responselength — treatment enables grepSearch.outputFormat = grep via the github.copilot-chat/agent.tool.responselength flag.

Tokens returned by grep_search (control = tag, treatment = grep)

Group Events Total Tokens Avg P50 P95 P99
control 363,400 421,529,887 1,160 321.2 5,275.4 13,091.6
treatment 389,097 200,998,321 516.6 137.7 2,123.6 6,380.8
  • ~55% fewer tokens per call on average (1,160 → 517); P95 down ~60%, P99 down ~51%.
  • Total tokens dropped from 421.5M → 201.0M, despite treatment serving more calls (389K vs 363K events).
  • PValue = 0 — statistically significant.

Context: Part of the CLI/AHP‑as‑default migration. Tracking given the direct COGS impact of tool response length.

Metadata

Metadata

Assignees

Labels

agent-hostIssues for the agent-host implementation (not the protocol)

Type

No type

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions