Last week, I watched an AI coding agent make the same mistake for the third time in the same repo.
It reintroduced a bug we’d already fixed.
It ignored a naming convention we’d already explained.
It missed an architecture constraint buried in a migration from six months ago.
None of this was because the model was “bad.” The problem was simpler:
the agent had no memory.
Every new session started from scratch. So onboarding an AI agent looked a lot like onboarding a new teammate every single morning.
That gets expensive fast.
The real onboarding problem isn’t docs. It’s lost context.
Most teams already have some version of:
- code comments
- ADRs
- Notion pages
- Slack threads
- PR discussions
- tribal knowledge in one senior engineer’s head
The issue is that AI agents don’t naturally turn that into persistent, reusable context.
Even if you paste docs into the prompt, the agent still has to figure out:
- what matters
- what changed
- what conflicts with what
- which patterns are preferred
- which bug fixes should never be repeated
That’s where ASTs became surprisingly useful for us.
ASTs are better onboarding material than raw code
Raw source files are noisy. They mix signal with implementation detail.
ASTs give you something more useful: structure.
From an AST, you can extract things like:
- exported APIs
- dependency relationships
- deprecated patterns
- repeated implementation shapes
- framework usage
- module boundaries
Then, if you combine that with an LLM like Gemini, you can compile those low-level facts into higher-level knowledge:
- “All payment flows go through this service”
- “This hook replaces the legacy auth helper”
- “These two modules conflict if used together”
- “This migration fixed a timezone bug; don’t reintroduce local parsing”
That’s a much better onboarding artifact than “here are 2,000 files, good luck.”
The pattern: AST extraction -> LLM synthesis -> knowledge graph
The mental model looks like this:
Source code / docs / PRs / bug notes
|
v
AST + entity extraction
|
v
Gemini summarizes patterns,
gotchas, decisions, relationships
|
v
Knowledge graph with links:
uses / replaces / depends_on /
conflicts_with / owns
|
v
AI agent retrieves context next time
The key idea is not “ask the model to remember.”
It won’t.
The key idea is: compile memory into something searchable and structured.
A tiny example
Here’s a minimal Node example showing how AST parsing can turn code into reusable knowledge signals.
npm install @babel/parser
const parser = require("@babel/parser");
const code = `
import { apiClient } from "./api";
export async function getUser(id) {
return apiClient.get("/users/" + id);
}
`;
const ast = parser.parse(code, { sourceType: "module" });
const imports = ast.program.body
.filter(n => n.type === "ImportDeclaration")
.map(n => n.source.value);
const exports = ast.program.body
.filter(n => n.type === "ExportNamedDeclaration")
.map(n => n.declaration.id.name);
console.log({ imports, exports });
Output:
{ imports: [ './api' ], exports: [ 'getUser' ] }
By itself, that’s not magical. But at codebase scale, this becomes a pipeline:
- parse files
- extract entities and relationships
- summarize them into human-usable knowledge
- store them so agents can retrieve them later
If you only need local code indexing, a plain vector DB or repo search may be enough. But if your pain is “the agent keeps forgetting decisions and patterns across sessions and projects”, you need something closer to a graph than a pile of embeddings.
Why a graph works better than just stuffing more into the prompt
Prompts are temporary.
Context windows are finite.
Embeddings are good at similarity, but weaker at explicit relationships.
A knowledge graph lets you store things like:
AuthProvider replaces LegacyAuthDateParser conflicts_with LocalTimezoneParsingBillingService depends_on InvoicePolicyFeatureFlagX caused bug in CheckoutFlow
That matters because onboarding isn’t just “find similar text.”
It’s often “find the right relationship.”
This is the problem we built PeKG for: giving AI coding agents persistent memory across sessions and projects.
It stores decisions, bug fixes, patterns, gotchas, and architecture knowledge in a searchable graph, and works with MCP-compatible agents like Claude Code, Cursor, Windsurf, Cline, Aider, and Roo Code. Your agent does the heavy lifting; PeKG stores and retrieves the compiled knowledge.
A nice side effect: if you learn something in Project A, you can apply it in Project B instead of rediscovering it.
What changed once we treated onboarding as knowledge compilation
Instead of asking:
- “How do we make the prompt better?”
we started asking:
- “What should the agent never have to relearn?”
That led to a better system:
- deep scan source files
- extract entities and relationships
- cluster related knowledge automatically
- compile raw notes into wiki-like articles
- retrieve from personal, team, shared, and public knowledge tiers
In practice, that means fewer repeated explanations and fewer “didn’t we already solve this?” moments.
Try it yourself
If you’re exploring MCP-based workflows, check out https://pekg.ai/docs for MCP setup.
If your main problem is knowledge capture and repeated agent mistakes, see https://pekg.ai/hints.txt for 115 practical tips.
And if you want to test persistent memory for your agent, try https://app.pekg.ai - free tier available. The free plan includes 100 articles, 5 projects, and 1 user, which is enough to see whether graph-based memory helps your workflow.
If PeKG isn’t the right fit, I’d still recommend this general approach: use ASTs to extract structure, use an LLM to synthesize meaning, and store the result somewhere your agent can query later.
Because the real issue usually isn’t model quality.
It’s that your agent wakes up every day with amnesia.
How are you handling codebase memory and onboarding for AI agents today? Drop your approach below.
-- PeKG team
This post was created with AI assistance.
Top comments (0)