-
Notifications
You must be signed in to change notification settings - Fork 0
Enhancement: Code-review-graph integration for token-efficient agent context #11
Description
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 runningPOST /agentis/graph/query— takes a task string, returns blast radius (files + functions in scope)
src/lib/multiAgentEngine.ts
buildOrchestratorSystem()— pass agraphContextstring (blast radius summary) so the orchestrator plans around actual affected codeexecuteWorkers()— inject relevant graph nodes into each worker's prompt beforestreamLLM. 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.tsmiddleware pattern already used for OpenClaw migration endpoints