Skip to content

Enhancement: Code-review-graph integration for token-efficient agent context #11

@Dhwanil25

Description

@Dhwanil25

Overview

Integrate code-review-graph as an optional enhancement to the multi-agent engine. Instead of feeding agents broad task descriptions with no structural knowledge of the codebase they're working on, this integration queries a local AST-based knowledge graph to compute the blast radius of a task — only the affected functions, callers, and dependency edges — and injects that as targeted context per agent.

Measured impact: 6.8x average token reduction (up to 49x on large monorepos). A review that consumed 12,507 tokens drops to 458 with equal or better quality.


Problem

When Agentis agents handle coding tasks today:

  • Each agent receives the full task description and reasons about it blind
  • No structural knowledge of the actual codebase is available
  • Coder/Reviewer agents consume large token budgets re-deriving context that a graph already knows

Proposed Architecture

Data flow

User types task
  → (if graph enabled) query blast radius
  → orchestrator plans with graph context
  → each worker receives only its relevant code slice
  → agents work on targeted context (~450 tokens vs ~12,000)

Files to change

vite-plugin-agentis.ts
Add two middleware endpoints that proxy to the code-review-graph MCP sidecar:

  • GET /agentis/graph/status — checks if an instance is running
  • POST /agentis/graph/query — takes a task string, returns blast radius (files + functions in scope)

src/lib/multiAgentEngine.ts

  • buildOrchestratorSystem() — pass a graphContext string (blast radius summary) so the orchestrator plans around actual affected code
  • executeWorkers() — inject relevant graph nodes into each worker's prompt before streamLLM. Coder gets function signatures + callers. Reviewer gets dependency edges. Researcher gets the import graph.

src/components/pages/UniversePage.tsx

  • "Attach codebase" toggle below the task textarea
  • Pre-launch badge: "14 functions · 3 files in scope" so the user sees what was scoped before agents spawn

src/components/pages/SettingsPage.tsx

  • New "Integrations" section with a code-review-graph card
  • Toggle to enable/disable
  • MCP server URL field (default localhost:8765)
  • "Build graph" button to trigger initial indexing

Activation logic

Only activates for coding-type tasks. The orchestrator detects whether the task involves code, files, or functions — general tasks (research, writing, analysis) bypass the graph entirely so there's no overhead for non-coding workflows.


Implementation options

Option Effort Notes
Sidecar proxy (recommended) Low Run code-review-graph MCP server separately; Agentis engine proxies to it
Port to TypeScript High Full rewrite of AST parsing + SQLite graph in TS — Tree-sitter has TS bindings

Option 1 (sidecar) is the right starting point. The MCP server runs alongside the Agentis engine and the plugin middleware handles the bridge.


References

  • code-review-graph — 6.8x token reduction, Tree-sitter + SQLite, 14 languages, MCP protocol
  • Related: vite-plugin-agentis.ts middleware pattern already used for OpenClaw migration endpoints

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions