Skip to content

feat: token-efficiency improvements#460

Open
jaissebastian wants to merge 2 commits into
tirth8205:mainfrom
jaissebastian:feat/token-efficiency-improvements
Open

feat: token-efficiency improvements#460
jaissebastian wants to merge 2 commits into
tirth8205:mainfrom
jaissebastian:feat/token-efficiency-improvements

Conversation

@jaissebastian
Copy link
Copy Markdown
Contributor

What is this feature?

When an AI agent uses code-review-graph MCP tools, some tools returned large dumps of data even when the agent only needed a quick answer. This caused:

  • High token usage per tool call
  • Agents making 3–4 separate tool calls just to review a change
  • Flow results being walls of raw node data, hard to read

This feature fixes all three problems: it adds a compact output mode to every tool, introduces a single-call review tool, and makes flow output readable.


What changed

1. detail_level="minimal" extended to all 29 tools

Previously, only 7 tools (like detect_changes, get_impact_radius) supported detail_level. Now every tool does.

When an agent passes detail_level="minimal", the tool strips verbose fields and returns only what's needed to make a decision. The agent can then call again with detail_level="standard" only for the specific item it wants to drill into.

Tools that gained detail_level support:

Tool What minimal returns
get_hub_nodes_tool name, kind, in_degree, out_degree, total_degree
get_bridge_nodes_tool name, kind, betweenness
get_knowledge_gaps_tool counts per category only
get_surprising_connections_tool source, target, surprise_score, reasons
get_suggested_questions_tool top 5 question texts + priority counts
get_architecture_overview_tool community names + counts + warnings only
get_community_tool name, size, cohesion, dominant_language
list_graph_stats_tool total_nodes, total_edges, files_count, last_updated
find_large_functions_tool name, kind, line_count, relative_path
refactor_tool (dead_code/suggest modes) top 10 items, name/kind only
cross_repo_search_tool name, kind, repo, file_path
list_repos_tool alias, path
get_affected_flows_tool narrative summary + compact bullets

2. New tool: get_review_bundle_tool

A single tool call that replaces the typical 3–4 call review workflow.

Before (old way):

detect_changes_tool → get_affected_flows_tool → query_graph_tool (callers_of) → get_review_context_tool

After (new way):

get_review_bundle_tool

What it returns in one response:

  • risk_score + risk — high / medium / low
  • changed_functions — list of changed functions, with optional source snippets
  • subgraph — one-hop callers and callees for each changed symbol (capped at max_nodes=20)
  • affected_flows — compact summaries of impacted execution flows
  • test_gaps — changed functions that have no test coverage
  • review_checklist — structured [ ] action items generated from the analysis
  • review_priorities — top 5 items to review first

Parameters:

get_review_bundle_tool(
  repo_root="<absolute path>",
  base="HEAD~1",              # git ref to diff against
  max_nodes=20,               # how many caller/callee neighbours to include
  include_snippets=false      # set true to get source code in the response
)

3. get_affected_flows_tool — readable summaries

Previously returned raw node dumps per flow. Now detail_level="minimal" returns:

  • A narrative paragraph: e.g. "3 flows affected by changes in 2 files: 1 high-criticality, 1 medium, 1 low."
  • Compact bullets per flow: flow_id, name, entry_point, criticality, depth, node_count, file_count, summary
  • Raw step data is still available under the detail key if needed

A new helper summarize_flow() was added to flows.py — it is reused by get_review_bundle to generate the same compact format.

jaissebastian and others added 2 commits May 10, 2026 14:30
…ow summaries

Extends `detail_level` param to all analysis, community, registry, refactor,
and query tools so agents can request compact responses from every tool, not
just the core review tools. All tools now accept `detail_level="minimal"` to
cap output to the most actionable fields.

Adds `get_review_bundle` — a single-round-trip tool that combines risk-scored
change analysis, one-hop caller/callee subgraph, affected flow summaries, and
a structured review checklist. Replaces the typical 2-4 tool call review
workflow with a single response.

Reformats `get_affected_flows` to return a narrative summary paragraph and
compact bullet IDs in `detail_level="minimal"` mode. Raw step data is moved
to a `detail` key agents can ignore. Adds `summarize_flow()` helper to
`flows.py` for reuse across tools.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ection tools

Use actual dict keys from analysis results: total_degree/in_degree/out_degree
for hubs, betweenness for bridges, and include reasons for surprising connections.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant