Skip to content

docs(agents): stop steering agents away from Grep for code search - #119

Merged
theDakshJaitly merged 1 commit into
mainfrom
docs/graph-agent-guidance
Aug 5, 2026
Merged

docs(agents): stop steering agents away from Grep for code search#119
theDakshJaitly merged 1 commit into
mainfrom
docs/graph-agent-guidance

Conversation

@theDakshJaitly

Copy link
Copy Markdown
Collaborator

What

Rewrites the ## Code Graph guidance block in all five shipped tool configs (AGENTS.md, CLAUDE.md, copilot-instructions.md, .cursorrules, .windsurfrules) and this repo's own .mex/.tool-configs/.

Why

The old wording opened with:

Prefer graph commands over grepping or reading files.

  • Explore a task with mex graph scope "<task>" first …
  • If you already know the symbol, skip scope: use mex graph query …

That makes graph scope the first command an agent runs on every task, and positions the reliable path (graph query) as the exception.

scope matches lexically — FTS5 plus name scoring. When a task's phrasing does not share vocabulary with the code, it returns weak results. Measured on this repository, a scope response is ~1,200 tokens against ~200-500 for graph query, and on natural-language questions the expected symbol is frequently absent.

The old wording then discouraged the fallback that would have worked. The observed pattern is: run scope, get a weak manifest, expand node ids that do not help, grep anyway. Every step is billed, and correctness is preserved only because the agent eventually ignores the instruction.

External measurement in #115 found mex costing 1.3-1.7x plain grep's session tokens across three real tasks while reaching the same answers on two of them. This guidance is part of that cost.

Changes

  • graph query / graph get lead: exact and cheap when the symbol name is known. Notes that an approximate name can return a confident wrong match (where-defined ledger resolves to planSource, because FTS matches a parameter name in a signature).
  • scope is framed as a starting point for unfamiliar tasks, with an explicit statement that it matches words rather than meaning, and should never be treated as a complete answer.
  • Explicit permission to use Grep/Glob when the manifest does not contain what is needed, with a cap of one scope rephrasing.
  • Treat any source the graph DOES return as ALREADY READ is retained — that instruction is sound and avoids real duplicate reads.

Scope

Documentation only. No code, no schema, no CLI behaviour changes. The underlying retrieval issues are tracked separately; this stops the guidance from amplifying them while they are fixed.

Verification

npm run build clean, npx vitest run 369/369 passing.

The shipped Code Graph guidance told agents to "prefer graph commands over
grepping or reading files" and to run `mex graph scope` first on every task.

`scope` matches lexically, so when a task's phrasing does not share vocabulary
with the code it returns weak results — and the old wording then discouraged the
cheap fallback that would have answered the question. Agents paid for the
manifest, expanded node ids that did not help, and grepped anyway.

Reorder the guidance around what each command is actually good at:

- `graph query`/`get` lead. They are exact and cheap when the symbol name is
  known, and note that an approximate name can return a confident wrong match.
- `scope` is framed as a starting point for unfamiliar tasks, with an explicit
  statement that it matches words rather than meaning.
- Add explicit permission to fall back to Grep/Glob when the manifest does not
  contain what is needed, and cap `scope` rephrasing at one retry.

Applied to all five shipped tool configs and this repo's own scaffold.
Copilot AI lite review requested due to automatic review settings August 5, 2026 07:50

Copilot AI left a comment

Copy link
Copy Markdown

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 updates the shipped agent/tool configuration templates to stop steering agents away from Grep/Glob and to position the code graph as a complementary tool (with graph query/get as the first choice when the symbol name is known, and scope as an optional, vocabulary-based starting point for unfamiliar tasks).

Changes:

  • Rewrites the Code Graph guidance to lead with mex graph query / mex graph get for exact symbol lookups.
  • Reframes mex graph scope as a vocabulary match (not semantic), with explicit guidance to fall back to Grep/Glob and to cap scope rephrasing.
  • Keeps the “treat returned sources as already read” instruction while discouraging irrelevant node expansion.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
templates/AGENTS.md Updates Code Graph guidance to treat graph as complementary to Grep/Glob and to lead with exact query/get usage.
templates/.tool-configs/copilot-instructions.md Aligns Copilot tool-config Code Graph guidance with the new query-first / scope-caveated wording.
templates/.tool-configs/CLAUDE.md Same Code Graph guidance rewrite for Claude tool-config template.
templates/.tool-configs/.windsurfrules Same Code Graph guidance rewrite for Windsurf rules template.
templates/.tool-configs/.cursorrules Same Code Graph guidance rewrite for Cursor rules template.
.mex/.tool-configs/copilot-instructions.md Mirrors the updated guidance in the repo’s maintained tool-configs.
.mex/.tool-configs/CLAUDE.md Mirrors the updated guidance in the repo’s maintained tool-configs.
.mex/.tool-configs/.windsurfrules Mirrors the updated guidance in the repo’s maintained tool-configs.
.mex/.tool-configs/.cursorrules Mirrors the updated guidance in the repo’s maintained tool-configs.

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

@theDakshJaitly
theDakshJaitly merged commit d641f6f into main Aug 5, 2026
3 checks passed
@theDakshJaitly
theDakshJaitly deleted the docs/graph-agent-guidance branch August 5, 2026 08:00
theDakshJaitly added a commit that referenced this pull request Aug 5, 2026
Patch release carrying the agent guidance fix from #119. Documentation and
tool-config changes only; no source or schema changes.

Note that upgrading does not rewrite an existing .mex/ scaffold — tool configs
are copied at setup time — so existing users need to replace the Code Graph
section manually. Called out in the changelog.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants