feat: improve codegraph tool visibility for AI agents#3133
Merged
Conversation
AI agents habitually use grep/read_file/ls instead of codegraph tools for architecture and symbol-level questions. Root cause is a guidance vacuum: codegraph tools are registered but never introduced to the model via system prompt, tool descriptions, or skill bodies. Changes: - Inject codegraph steer text into system prompt when tools are available - Add codegraph hint to bash tool's steer constant - Update explore/research/review/security-review skill bodies to prefer codegraph tools for symbol/code-structure questions - Dynamically inject codegraph tool names into subagent allowed-tools via SetExtraReadTools() so skills can use them at runtime - Add StripRawPrefix to plugin.Spec to eliminate the double-prefix naming (mcp__codegraph__codegraph_context -> mcp__codegraph__context)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
CodeGraph provides symbol-level code intelligence (call graphs, impact analysis, symbol search) via MCP tools, but AI agents overwhelmingly default to
grep/read_file/lseven for architecture and call-graph questions where codegraph tools are strictly superior.Root Cause Analysis
The issue is systemic — multiple reinforcing factors create a "guidance vacuum" around codegraph tools:
askandtodo_writebashToolSteerexplicitly directs togrep, read_file, ls, glob, edit_fileexploreskill body: "Use read_file, grep, glob, ls as your primary tools"AllowedToolswhitelist excludes codegraphmcp__codegraph__codegraph_context(32 chars) vsread_file(9 chars)mcp__codegraph__*lastThe result is a self-reinforcing cycle: the model uses grep → succeeds → never discovers codegraph → continues using grep.
Solution
Four targeted interventions at the guidance layer, ordered by blast radius:
1. System prompt steering (highest impact)
Inject a
SteerTextblock into the system prompt when codegraph tools are registered, mapping each tool to its use case (e.g.codegraph_contextfor "how does X work",codegraph_callersfor "who calls X"). This is the single highest-leverage change — it reaches every turn without requiring the model to discover tools on its own.Files:
internal/codegraph/codegraph.go,internal/boot/boot.go2. Tool description cross-reference
Append a codegraph hint to
bashToolSteerso the bash tool's description (visible every turn) reminds the model that symbol-level questions have a dedicated tool class.File:
internal/tool/builtin/bash.go3. Skill body and allowed-tools update
Update all four read-only subagent skill bodies (
explore,research,review,security-review) to prefer codegraph tools for symbol/code-structure questions, with grep/read_file as fallback. IntroduceSetExtraReadTools()to dynamically inject codegraph tool names into the subagentAllowedToolswhitelist at boot time — avoids hardcoding MCP-prefixed names that change with the strip prefix.File:
internal/skill/builtins.go4. Tool name deduplication
Add
StripRawPrefixfield toplugin.Spec. When set, the prefix is stripped from each MCP tool's raw name before namespacing —codegraph_contextbecomescontext, yieldingmcp__codegraph__contextinstead of the redundantmcp__codegraph__codegraph_context. Applied in bothlistTools()(live handshake) and the lazy-tier cache path. The original raw name is preserved for MCP protocol calls.Files:
internal/plugin/plugin.go,internal/plugin/lazy.goVerification
cfg.Codegraph.Enabledand tool presence in registry — no-op when codegraph is disabled or unavailableSetExtraReadTools()is empty by default; existingTestBuiltinSubagentSkillsDeclareAllowedToolspasses unchangedStripRawPrefixdoes not affectSpecFingerprint(cache stores raw names; strip is applied at read time), so no cache invalidation side effects