Token waste and mid-session context loss plague real-world AI engineering: coding agents burn budget repeating file searches, while long-running agents lose track of why they made earlier decisions. Though the two symptoms look separate, both stem from leaving relationships across underlying artifacts implicit and unstructured.

Explicit Graph Edges Beat Repeated Discovery

Graphs turn implicit dependencies into explicit links, which is the same reason GraphRAG outperforms flat vector similarity on multi-hop questions. Connecting items as nodes and edges lets an agent read directly that A calls B and B depends on C instead of rediscovering structure from scratch on every turn.

Two open-source projects apply this exact principle to different layers: source code navigation and long-running agent state.

Mapping Codebase Structure with codegraph

codegraph indexes function and class relationships across large repositories to cut agent exploration overhead (GitHub repo: https://lnkd.in/gWgT4msM) .

Anyone running Codex or Claude Code on a large codebase has watched the agent burn tokens chaining repetitive grep, glob, and Read calls, a tax that grows steeper with repository size.

Using tree-sitter AST parsing, codegraph extracts functions and classes as nodes, wires call and inheritance relationships as edges, stores the graph in SQLite, and exposes it to coding agents as an MCP server. A single codegraph_explore call returns connected code context immediately.

Across benchmarks on 6 production codebases, codegraph cut tool invocations by 92% and shortened exploration time by 71%. Setup takes a single command (npx @colbymchenry/codegraph) and works with both Claude Code and Codex.

Tracking Long-Running Agent State with ActiveGraph

ActiveGraph tracks opaque state transitions in multi-hour agent runs as an explicit event-backed graph (GitHub repo: https://lnkd.in/gDgCUGzn) .

When an autonomous agent runs for hours, reconstructing prior decisions and their supporting evidence from flat chat logs quickly breaks down. ActiveGraph models task, claim, and evidence objects as nodes connected by typed edges such as supports, contradicts, and depends_on. Every mutation appends to an append-only event log, and reactive behaviors trigger automatically off graph state changes without hardcoding rigid step sequences upfront.

Its fork-and-diff capability branches mid-execution much like Git: you can fork from a decision point under an alternative assumption, compare downstream outcomes, and reuse cached LLM calls prior to the branch point to keep experiments cheap.

Whether mapping code symbols with codegraph or reasoning state with ActiveGraph, encoding relationships as explicit edges spares agents from re-inferring hidden structure on every turn.

Summary

  • Context loss and token waste in AI workflows stem largely from leaving relationships between target artifacts unstructured.
  • Representing implicit dependencies as explicit graph nodes and edges cuts repeated search overhead and improves accuracy.
  • codegraph maps AST-level codebase dependencies (cutting tool calls by 92%), while ActiveGraph tracks reactive, branchable agent state.