Skip to content

Blog

How to build a company brain, part 9: when it gets big and slow, give the agent a graph

By Saif Qureshi6 min read
  • Company brain
  • Knowledge graph
  • Graphify

A brain with a few hundred files is easy work for an agent. It reads the entry page, then one summary, and it has what it needs. With a few thousand files that stops working. Ask something that crosses folders and the agent opens file after file to be sure, and you pay input tokens for every one. The answers come back slower, they cost more, and the agent still can't see a connection in a file it never opened.

Key takeaways

  • A big brain is slow because the agent reads whole files into its context to answer one question. Every file it reads is input tokens on your bill.
  • With a graph, the agent asks first and then opens only the few files the graph points to.
  • Graphify parses code on your machine with no AI model. Notes go through a model pass, and that pass costs tokens.
  • The graph is only as good as your links. If notes link to what they depend on, most of the graph is already written.
  • In one of my brains, more than 7,200 of about 9,900 links come from notes and fewer than 100 from code.

Why big brains get slow and costly

Three things grow with the brain. Search gets slower, because scanning every folder for a word takes longer each month. Context gets heavier: the agent reads whole files into its context window, so the input tokens per question go up, and so does the bill. And the blind spots multiply. An agent can't follow a link in a file it never opened, so the more files there are, the more it misses.

I fix this in two steps. The first is the index in part 10, which finds files fast. The second is a graph. It tells the agent which few files matter for a question and how they connect.

Comparison: without a graph, the agent scans folders, opens many files, reads them all into context, slow and costly and still misses links; with a graph, the agent asks the graph, gets the few connected notes, reads only those, fast and cheap and follows links.
The fewer files the agent reads per question, the fewer input tokens you pay for.

What Graphify does

Graphify is a tool that turns a folder into a knowledge graph. You install it once, type /graphify in your coding assistant (its README lists Claude Code, Cursor, Codex and Gemini CLI, among others), and get three files back: the graph itself, a page you can open in a browser and click through, and a report in plain language. The report names the most connected nodes, which Graphify calls god nodes, and connections you might not expect.

The graph holds nodes and the links between them. Every link carries a tag that says whether it was read directly from the source or inferred. Closely linked nodes are grouped into communities and given names. There are also hyperedges: one edge that groups three or more nodes, such as all the steps of one workflow.

Graphify was built for code, and that shows in how it treats the two kinds of input. Code is parsed on your machine with tree-sitter. No AI model is involved, so the result is the same every time and costs nothing. Documents are different. Markdown, PDFs and images go through what the README calls a semantic pass, which your assistant's model (or an API key you configure) runs. That pass costs tokens, and it means the model reads those documents. Keep that in mind before you point it at a folder with personal data. Part 7 covers what stays out.

Once the graph exists, the agent asks it before reading files. There are three commands. "graphify query" takes a question and returns a small piece of the graph. "graphify path" shows how two things connect. "graphify explain" describes one node and its neighbours. The agent gets back a handful of notes and links, and opens only those.

How Markdown became a graph

A business brain is mostly documents. For Graphify to be any use there, the notes have to carry their own links. This is what I do:

  • Link generously. Every note links to what it depends on with a relative Markdown link, and lists its source ids in the header. A feature brief links the feedback it came from. A decision links the analysis behind it.
  • Store the links. The index in part 10 keeps every Markdown link in a table. That table is already a simple graph: it knows who links to whom, which notes nobody links to, and which pages everyone cites.
  • Let Graphify add meaning. Its pass over the Markdown adds typed edges such as "references", "conceptually related to" and "rationale for", plus hyperedges for workflows.
  • Keep it fresh. Running "graphify hook install" adds a git hook that rebuilds the graph after every commit. For notes there is also an update mode that re-extracts only the files that changed.
Diagram: code (parsed locally, no AI model) and Markdown notes (links plus source ids) feed a knowledge graph (nodes, edges, hyperedges, communities), which answers query, path and explain.
The links you already write become the edges.

What the graph shows

In one of my brains the graph has about 3,000 nodes and about 9,900 links. More than 7,200 of those links are "references" edges that come from notes. Fewer than 100 are "calls" edges from code. So the shape of the business sits in its documents, and the links are what make that shape visible to an agent.

Two lists are worth reading every week. The orphan list lists notes nobody links to, which usually means a missing summary or a misfiled document. The hub list shows which pages many others cite, so those are the pages that have to stay accurate. At Kranich Studio, the example company in this series, the hubs would be the bakery chain's client page, the waitlist knowledge page and BRAIN.md. When a hub changes, the pages that cite it get a review.

I haven't measured how many tokens the graph saves per question in my own brains, so I won't give you a number. Graphify's README links to its own benchmarks if you want one. Measure on your own folder before you trust a published figure.

Prompt for a weekly graph check
prompt
Goal: a weekly health check of this brain's knowledge graph.
Steps: update the graph with Graphify (changed files only). Then read graph.json and our links table.
Report: the ten most-cited pages and the date each was last verified. Every note with no incoming links, with a suggestion for where to link it. Any page cited by more than five others that changed this week.
Constraints: do not edit, move or delete any note. Give me the list and nothing else.
From now on: for a question that crosses folders, query the graph first and read only the files it returns.
Next in How to Build a Company Brain · Part 10How to build a company brain, part 10: a SQLite index and knowledge graph your agent maintains

Frequently asked questions

Why does my AI agent get slow on a big knowledge base?

Because it reads many whole files into its context to answer one question. That takes time and input tokens, and it still misses links in files it didn't open. With an index and a graph it reads only the files that matter.

Can Graphify map documents, or only code?

Both. Code is parsed locally with no AI model. Markdown, PDFs and images are read by your assistant's model or one you configure, so that part costs tokens. In a business brain most edges come from links between notes.

Do I need a graph from the start?

No. Start by linking notes to each other, because that costs nothing and it is what the graph is built from. Add the graph when you see agents opening many files for one question. The brain I run it on has a few thousand files.

Sources

  1. Graphify on GitHub (README) github.com
  2. Graphify: how it works (passes, confidence tags, hyperedges) github.com

Talk to me

Building an AI product and need someone senior to own the technical side? Book a free 30-minute call.