Agent Memory & Codebase Knowledge Base
Agent Memory & Codebase Knowledge Base
Agent Memory is a persistent, self-improving knowledge layer built into the autonomous development pipeline. Rather than starting from scratch on every pipeline run, implementation agents accumulate and reuse project-specific knowledge — conventions, past mistakes, gotchas, and successful patterns — so code quality compounds over time.
Overview
Every pipeline run now:
- Loads relevant memory entries ranked by confidence and helpfulness
- Injects them into the implementation agent's system prompt
- Records which entries were used
Every night at 3 AM UTC, the Distiller scans the last 24 hours of pipeline logs, extracts new patterns, and reinforces entries that repeat — automatically raising their confidence score.
Entry Structure
Each memory entry has the following fields:
| Field | Description |
|---|---|
type | One of: pattern, mistake, convention, dependency, gotcha, success |
category | One of: schema, api, ui, testing, auth, performance, inngest, deployment, general |
title | Short descriptive title |
content | Full explanation |
codeExample | Optional illustrative code snippet |
affectedFiles | Optional list of relevant file paths |
tags | Optional free-form tags |
confidence | Float 0–1. Higher = more likely to be injected |
humanVerified | Boolean. Verified entries get confidence 0.95 |
timesUsed | How many times this entry has been surfaced to agents |
source | agent, manual, or distiller |
Entry Types
| Type | Icon | Purpose |
|---|---|---|
pattern | ⚡ | Recurring coding patterns worth following |
mistake | ⚠️ | Known errors to avoid |
convention | 📖 | Project-specific code conventions |
dependency | 📦 | Dependency usage notes |
gotcha | 🚨 | Tricky edge cases that have caused issues |
success | ✅ | Approaches that have worked well |
Confidence Scoring
Confidence controls whether an entry gets injected into agent prompts:
- 0.0–0.49 — low confidence; entry exists but is rarely injected
- 0.50–0.79 — moderate confidence; injected when relevant
- 0.80–1.0 — high confidence; consistently injected
Reinforcement learning: when the distiller observes the same pattern again, it calls upsertMemoryEntry() which increments the confidence score. Repeated mistakes or confirmed patterns gradually earn higher confidence without manual intervention.
Human verification: clicking Verify in the dashboard immediately sets confidence to 0.95.
The Nightly Distiller
The Inngest cron (agentMemoryDistiller) runs every night at 3:00 AM UTC. It:
- Queries completed and failed pipeline runs from the last 24 hours
- Parses agent log output for known error patterns
- Creates or reinforces structured memory entries
Automatically Detected Patterns
| Log Signal | Memory Entry Created |
|---|---|
TypeScript TS2339 error | mistake — property does not exist on type |
DynamicServerError | gotcha — page must use force-dynamic |
Drizzle .where() chaining | mistake — incorrect query builder usage |
Inngest Jsonify error | gotcha — return type serialisation issue |
| Missing module import error | mistake — import path or package missing |
| New router/schema/Inngest file written | convention — established file structure pattern |
| PR merged successfully | success — approach that led to green CI |
Dashboard
Navigate to Products → [Product] → Agent Memory (/dashboard/products/[id]/agent-memory) to view and manage the knowledge base.
Stats Cards
- Total Entries — all active memory entries
- Patterns — entries of type
pattern - Mistakes Caught — entries of type
mistake - Human Verified — entries with
humanVerified: true
Filtering
Filter the entry list by type (pattern, mistake, convention, etc.) and category (schema, api, ui, etc.) using the dropdowns at the top of the list.
Entry Cards
Each card shows:
- Title, type badge, category badge, confidence percentage
- A Verified badge if
humanVerifiedis true - Usage count and source
- Expandable More section with code example, affected files, and tags
Actions
- Verify (shield icon) — sets
humanVerified: trueand confidence to 0.95 - Delete (trash icon) — soft-deletes the entry (
active = false); it will no longer be injected
Adding Entries Manually
Click Add Entry to open the creation dialog. Manual entries are created with confidence: 0.9 and humanVerified: true by default, so they are injected immediately.
Required fields:
- Type — select from the six types
- Category — select from the nine categories
- Title — short label
- Content — full explanation
Optional fields:
- Code Example — a snippet illustrating the point
- Tags — comma-separated
tRPC API Reference
All endpoints are under the agentMemory router.
agentMemory.list
Returns paginated memory entries for a project.
Input
{
projectId: string;
type?: "pattern" | "mistake" | "convention" | "dependency" | "gotcha" | "success";
category?: "schema" | "api" | "ui" | "testing" | "auth" | "performance" | "inngest" | "deployment" | "general";
cursor?: number; // offset
limit?: number;
}
agentMemory.stats
Returns aggregate counts for a project's memory entries.
Input
{ projectId: string }
agentMemory.create
Creates a human-authored entry (confidence: 0.9, humanVerified: true).
Input
{
projectId: string;
type: EntryType;
category: EntryCategory;
title: string;
content: string;
codeExample?: string;
affectedFiles?: string[];
tags?: string[];
}
agentMemory.update
Updates any field on an existing entry.
Input
{ id: string; [field]: value }
agentMemory.delete
Soft-deletes an entry (sets active = false).
Input
{ id: string }
agentMemory.verify
Marks an agent-extracted entry as human-verified and sets confidence to 0.95.
Input
{ id: string }
Library Functions
These are used internally by the pipeline and distiller. You do not need to call them directly unless building custom tooling.
getRelevantMemory(projectId, options?)
Retrieves the top-N active entries ranked by confidence and usage, optionally filtered by category.
formatMemoryForInjection(entries)
Renders an array of entries into a compact markdown block grouped by category, suitable for inclusion in an LLM system prompt. Prefixes each entry with a type icon.
upsertMemoryEntry(projectId, entry)
Inserts a new entry or, if a matching title already exists, increments its confidence score (reinforcement learning).
recordMemoryUsage(ids)
Increments timesUsed for the given entry IDs.
Pipeline Integration
Memory loading is best-effort and non-blocking — if the memory query fails, the pipeline continues unaffected.
Orchestrator (pipeline.ts)
└─ getRelevantMemory(projectId)
└─ formatMemoryForInjection(entries)
└─ passed as agentMemory in baseEventData
└─ implementation agent reads event.data.agentMemory
└─ injected into system prompt via agentMemory option
The PipelineEventData type now includes:
interface PipelineEventData {
// ... existing fields
agentMemory?: string; // formatted markdown block
}