(:Idea)
Graph edit algebra
A graph edit algebra is a small set of operations on a code knowledge graph that an AI agent uses to change a codebase. The agent resolves a name, transforms the graph, reads the delta, then commits or reverts.
The problem with editing code as text
An AI agent that edits code as text finds call sites with grep and changes them with string patches. Grep misses the method called through an interface. It also matches the comment that only mentions the name. The patch lands in one file while callers in other files keep the old signature.
The agent finds out later, from a failing test, if a test exists. Nothing in the loop told it what the edit did to the structure of the program.
The four steps
-
Resolve
The agent names a symbol by its qualified name, for example
myproj.pkg.util.helper. The graph answers with the definition and every call, reference, import and override site it knows about. The sites come from the graph and never from a text search. -
Transform
The agent picks an operation. Code-Graph-RAG ships three today, which are rename, change signature and move. The operation plans a rewrite of every site and stages the new file contents in memory. The working tree is untouched.
-
Read the delta
The touched files are re-ingested and the operation gets a structural delta. This is a JSON report of what the edit did to the program. It lists the symbols that appeared, disappeared or changed name, the call sites that changed and the tests that reach the changed code.
-
Commit or revert
Each operation carries a postcondition. A rename promises that exactly the requested names changed, that the number of call sites into them is the same and that no caller is left dangling. If the delta breaks the promise, the transaction is undone and the working tree is byte for byte what it was.
Why I call it an algebra
The operations are few, they all act on the same object, which is the graph, and each one states what it guarantees. Every operation goes through the same edit transaction, so a sequence of edits is a sequence of transactions that can be shown and undone in order.
cgr rename myproj.pkg.util.helper assist --dry-run
cgr rename myproj.pkg.util.helper assist
cgr edits show
cgr edits undo
Rename is also an MCP tool, so Claude Code and other MCP clients can call it directly.
Text edits and graph edits side by side
| Question | Text edit | Graph edit algebra |
|---|---|---|
| How are call sites found? | Text search | Edges in the graph |
| When does a multi-file change land? | File by file | All files or none |
| What does the agent learn after the edit? | Whether the patch applied | What the edit did to the program's structure |
| What happens on a bad edit? | The tree stays changed | The transaction is undone |
Read more
- Edit transactions, the stage, verify, commit and undo mechanism.
- Structural delta, what every write reports back.
- Postcondition contract, what each operation promises.
- Rename, the first operation.
Cite this page
Avagyan, V. "Graph edit algebra." vitali87.com, 2026. https://vitali87.com/graph-edit-algebra/
Questions people ask
What is a graph edit algebra?
A graph edit algebra is a small set of operations on a code knowledge graph that an AI agent uses to change a codebase. The agent resolves a name, transforms the graph, reads the delta, then commits or reverts.
Who defined the graph edit algebra?
I did, and I implemented it in Code-Graph-RAG.
Which operations does the graph edit algebra have?
I ship three in Code-Graph-RAG today. They are rename, change signature and move.
What happens when an edit fails its check?
The transaction is undone and the working tree is byte for byte what it was before the edit.