This article is published in English.
Practical notes: Context Graphs for AI Agents: Giving AI the Memory of a Senior
Operable walkthrough of Practical notes: Context Graphs for AI Agents: Giving AI the Memory of a Senior: contracts, checks, and drop-in code slots for teams shipping this pattern.
Why the next generation of AI agents needs more than vector search, embeddings, and bigger context windows
Cite the passages that actually grounded the answer. Without citations, operators cannot tell hallucination from an indexing gap.
What Is a Context Graph?
EmployeeController.java exists.
ReimbursementService.java exists.
SecurityConfig.java exists.
ADR-17.md exists.
EmployeeController
|
| follows_pattern
v
EmployeeApiConvention
|
| requires
v
TenantValidation
ReimbursementEndpoint
|
| handled_by
v
ReimbursementOrchestrator
|
| writes_to
v
ReimbursementRepository
|
| persists
v
HrReimbursement
ReimbursementEndpoint
|
| governed_by
v
ADR-17
ADR-17
|
| created_because_of
v
ProductionIncident-928
A Graph Is Basically Dots and Lines
For the A Graph Is Basically stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness. For the A Graph Is Basically stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
Node ---- Relationship ---- Node
Vaibhav ---- works_at ---- PeopleStrong
Controller ---- calls ---- Service
Service ---- calls ---- Repository
Repository ---- writes_to ---- DatabaseTable
Endpoint ---- protected_by ---- Permission
Feature ---- explained_by ---- ADR
ADR ---- resulted_from ---- Incident
Test ---- validates ---- Endpoint
Knowledge Graph vs Context Graph
When working through the Knowledge Graph vs Context stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
Employee
WORKS_FOR
Organization
Order
BELONGS_TO
Customer
PaymentService
USES
PaymentRepository
PaymentService
USES
PaymentRepository
PaymentService
GOVERNED_BY
ADR-12ADR-12
CREATED_AFTER
Incident-492PaymentService
REQUIRES
FinancePermissionPaymentRepository
WRITES_TO
PaymentTransactionPaymentTransaction
MUST_BE_SCOPED_BY
OrganizationIDPaymentTransaction
MUST_BE_SCOPED_BY
TenantID
The Most Important Part: Context Graphs Store the “Why”
When working through the The Most Important Part stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
Discount = 25%
Approved = true
ApprovedBy = 182
Customer-482
RECEIVED
25% Discount
25% Discount
APPROVED_BY
SalesDirector25% Discount
EXCEPTION_TO
StandardDiscountPolicyException
BECAUSE
CustomerMigrationRiskCustomerMigrationRisk
DOCUMENTED_IN
Opportunity-928Decision
PRODUCED
SuccessfulRenewal
Core Components of a Context Graph
When working through the Core Components of a stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node. When working through the Core Components of a stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
1. Entities — The Things That Exist
The 1 Entities The Things stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Repository
Module
Package
Class
Method
API Endpoint
Database Table
Database Column
Configuration
Skill
Rule
Architecture Decision
Pull Request
Commit
Issue
Incident
Test
Developer
Team
Node: ReimbursementController
Type: JavaClass
Path: services/hr/.../ReimbursementController.java
Node: POST /reimbursements
Type: Endpoint
Node: HrReimbursement
Type: DatabaseTable
2. Relationships — How Things Connect
The 2 Relationships How Things stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
ReimbursementController
EXPOSES
POST /reimbursements
POST /reimbursements
CALLS
ReimbursementService
ReimbursementService
USES
ReimbursementRepository
ReimbursementRepository
WRITES_TO
HrReimbursement
POST /reimbursements
REQUIRES_PERMISSION
CREATE_REIMBURSEMENT
ReimbursementService
FOLLOWS_PATTERN
OrchestratorPattern
3. Properties — Details About Nodes and Relationships
The 3 Properties Details About stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts. The 3 Properties Details About stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
JavaClass:
name = ReimbursementController
language = Java
framework = Spring Boot
module = hr-service
Endpoint:
method = POST
path = /api/v1/reimbursements
authenticationRequired = true
Service
CALLS
Repository
since = 2026-04-18
confidence = 1.0
source = static-analysis
4. Time
For the 4 Time stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
Controller
USES
FieldInjection
FieldInjectionPattern
validUntil = 2025-01-15
ConstructorInjectionPattern
validFrom = 2025-01-16
5. Provenance — Where Did This Information Come From?
For the 5 Provenance Where Did stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
Rule:
All employee APIs must validate TenantID.
Rule
EXTRACTED_FROM
ADR-0027.md
Rule
OBSERVED_IN
14 Production Endpoints
Rule
INTRODUCED_BY
PR-8421
6. Short-Term Memory
For the 6 Short-Term Memory stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness. For the 6 Short-Term Memory stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
CurrentTask
TARGETS
AdminAPI
CurrentTask
EXCLUDES
EmployeeApp
7. Long-Term Memory
When working through the 7 Long-Term Memory stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
Repository
USES
Java17
Repository
USES
SpringBoot3EndpointCreation
REQUIRES
ControllerTestEndpointCreation
REQUIRES
ServiceTest
8. Decision or Reasoning Memory
When working through the 8 Decision or Reasoning stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Cache stable system instructions and tool schemas. Re-sending identical preamble is a common source of burn.
Approach A:
Controller -> Repository
Business logic must pass through the service/orchestrator layer.
Approach-A
REJECTED_BECAUSE
ArchitectureRule-42
So How Does the Context Graph Actually Work?
When working through the So How Does the stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node. When working through the So How Does the stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
Task:
Create Endpoint
Domain:
ReimbursementOperation:
ApproveActor:
Admin
Step 1 — Find the Starting Nodes
The Step 1 Find the stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Reimbursement
Approve
Endpoint
Admin
ReimbursementController
ReimbursementService
HrReimbursement
ReimbursementStatus
APPROVE_REIMBURSEMENT permission
ReimbursementWorkflow
Step 2 — Expand Their Relationships
The Step 2 Expand Their stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
ReimbursementController
|
+--- FOLLOWS_PATTERN ---> ExpenseController
|
+--- CALLS -------------> ReimbursementService
|
+--- PROTECTED_BY ------> FinancePermission
ReimbursementService
|
+--- USES --------------> ReimbursementOrchestrator
ReimbursementOrchestrator
|
+--- WRITES_TO ---------> HrReimbursement
|
+--- GOVERNED_BY -------> ADR-24
ADR-24
|
+--- CREATED_AFTER -----> Incident-842
Step 3 — Filter the Graph
The Step 3 Filter the stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts. The Step 3 Filter the stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
current branch
current module
task
user permission
repository version
organization
time
confidence
Step 4 — Build the Agent’s Context
For the Step 4 Build the stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
TASK
Create reimbursement approval endpoint.
RELEVANT PATTERN
ExpenseApprovalController.REQUIRED ARCHITECTURE
Controller -> Service -> Orchestrator -> Repository.SECURITY
Permission APPROVE_REIMBURSEMENT required.TENANCY
Queries must include OrganizationID and TenantID.DATABASE
HrReimbursement.IMPORTANT DECISION
ADR-24 prohibits direct status updates.TEST PATTERN
ExpenseApprovalControllerTest.
Step 5 — Agent Performs the Work
For the Step 5 Agent Performs stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
Controller
Request DTO
Response DTO
Service
Orchestrator
Repository query
Authorization
Tenant filtering
Tests
Step 6 — Store What Happened
For the Step 6 Store What stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness. For the Step 6 Store What stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
PR-9928
IMPLEMENTED
ReimbursementApprovalEndpoint
ReimbursementApprovalEndpoint
FOLLOWS
OrchestratorPattern
PR-9928
VALIDATED_BY
ArchitectureTests
Vector Database vs Context Graph
When working through the Vector Database vs Context stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
EmployeeController.java
EmployeeService.java
EmployeeRepository.java
SecurityConfig.java
ADR-17.md
Incident-928.md
EmployeeControllerTest.java
add-end-point/SKILL.md
What a Vector Search Does
When working through the What a Vector Search stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
EmployeeController.java similarity 0.94
CandidateController.java similarity 0.89
EndpointGuide.md similarity 0.87
EmployeeService.java similarity 0.82
ADR-17.md
What a Context Graph Does
When working through the What a Context Graph stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node. When working through the What a Context Graph stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
EmployeeEndpoint
EmployeeEndpoint
MUST_FOLLOW
EmployeeApiPattern
EmployeeApiPattern
REQUIRES
TenantIsolation
TenantIsolation
DEFINED_BY
ADR-17
ADR-17
INTRODUCED_AFTER
SecurityIncident-28
Vector Search Asks:
The Vector Search Asks stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Context Graph Asks:
The Context Graph Asks stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
But Do Not Throw Away Your Vector Database
The But Do Not Throw stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts. The But Do Not Throw stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
Vector Search
+
Graph Traversal
+
Metadata Filters
+
Keyword Search
+
Agent Reasoning
A Simple Mental Model
For the A Simple Mental Model stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Prefer structured outputs with schema validation over free-form prose when the next step is code or a tool call.
Context Graphs Inside a Git Repository
For the Context Graphs Inside a stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
employee-platform/
│
├── services/
│ ├── employee-service/
│ ├── payroll-service/
│ └── recruitment-service/
│
├── docs/
│ └── adr/
│
├── database/
│ └── migrations/
│
├── .agents/
│ ├── AGENTS.md
│ │
│ ├── skills/
│ │ └── add-end-point/
│ │ ├── SKILL.md
│ │ ├── templates/
│ │ └── references/
│ │
│ └── context/
│ ├── repository.yml
│ ├── architecture.yml
│ └── rules.yml
add-end-point
Designing a Repository Context Graph
For the Designing a Repository Context stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness. For the Designing a Repository Context stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
Repository
Module
Service
Class
Method
Endpoint
DatabaseTable
DatabaseColumn
Skill
ArchitecturePattern
Rule
Permission
ADR
Issue
PullRequest
Commit
Test
Repository CONTAINS Module
Module CONTAINS ClassController EXPOSES EndpointEndpoint CALLS ServiceService USES RepositoryRepository READS_FROM TableRepository WRITES_TO TableEndpoint REQUIRES PermissionClass TESTED_BY TestClass FOLLOWS PatternPattern DEFINED_IN ADRRule GOVERNED_BY ADRCommit CHANGES ClassPullRequest CONTAINS CommitIssue RESOLVED_BY PullRequestSkill APPLIES_TO EndpointSkill REQUIRES Rule
A Small Example Graph
When working through the A Small Example Graph stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
EmployeeController
|
| CALLS
v
EmployeeService
|
| DELEGATES_TO
v
EmployeeHandler
|
| USES
v
EmployeeRepository
|
| WRITES_TO
v
HrEmployee
EmployeeController
|
| REQUIRES
v
EmployeePermission
EmployeeRepository
|
| FILTERS_BY
+----> TenantID
|
+----> OrganizationID
EmployeeController
|
| TESTED_BY
v
EmployeeControllerTest
add-end-point
|
| USES_PATTERN
v
EmployeeEndpointPattern
How Do We Build This Graph?
When working through the How Do We Build stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
Java source
imports
method calls
Spring annotations
package structure
repository interfaces
SQL queries
DDL
configuration
test classes
Git history
ADR documents
AGENTS.md
SKILL.md
Phase 1 — Static Code Analysis
When working through the Phase 1 Static Code stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node. When working through the Phase 1 Static Code stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
@RestController
@RequestMapping("/employees")
public class EmployeeController {
private final EmployeeService employeeService; @PostMapping
public EmployeeResponse create(
@RequestBody EmployeeRequest request) {
return employeeService.create(request);
}
}
EmployeeController
TYPE
Controller
EmployeeController
EXPOSES
POST /employeesEmployeeController
CALLS
EmployeeService.create
Phase 2 — Repository Analysis
The Phase 2 Repository Analysis stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
public interface EmployeeRepository
extends JpaRepository<EmployeeEntity, Long> {
}
EmployeeRepository
OPERATES_ON
EmployeeEntity
@Entity
@Table(name = "HrEmployee")
EmployeeEntity
MAPS_TO
HrEmployee
Phase 3 — Git History
The Phase 3 Git History stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Commit 812ac3
Message:
Add tenant filtering to employee repository.
Reason:
Prevent cross-tenant access.
EmployeeRepository
CHANGED_IN
Commit-812ac3
Commit-812ac3
PART_OF
PR-982PR-982
INTRODUCED
TenantIsolationRule
Phase 4 — Architecture Documents
The Phase 4 Architecture Documents stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts. The Phase 4 Architecture Documents stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
All employee mutations must pass through the EmployeeHandler.
EmployeeMutation
MUST_USE
EmployeeHandler
rule source:
ADR-17
Phase 5 — AI Skills
For the Phase 5 AI Skills stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
.agents/skills/add-end-point/SKILL.md
Before creating an endpoint:
1. Identify the nearest existing endpoint pattern.
2. Resolve authentication and authorization rules.
3. Resolve tenant and organization isolation.
4. Identify service/orchestrator pattern.
5. Identify persistence pattern.
6. Identify required tests.
get_context(
task="create-endpoint",
domain="employee",
operation="create"
)
The Context Graph Service
For the The Context Graph Service stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
AI Agent
|
v
Context API / MCP Server
|
+--------> Graph Database
|
+--------> Vector Database
|
+--------> Git Repository
find_entity
get_neighbors
find_path
get_architecture_context
get_security_context
get_database_context
get_change_history
get_similar_implementations
get_context_for_task
record_decision
get_context_for_task(
repository="employee-platform",
skill="add-end-point",
task="create reimbursement approval endpoint"
)
What Graph Database Should We Use?
For the What Graph Database Should stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness. For the What Graph Database Should stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
JSON files
+
NetworkX
+
SQLite
A Very Simple Neo4j-Like Representation
When working through the A Very Simple Neo4j-Like stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
CREATE (:Class {
name: "EmployeeController",
type: "Controller"
});
CREATE (:Service {
name: "EmployeeService"
});CREATE (:Repository {
name: "EmployeeRepository"
});
MATCH (c:Class {name:"EmployeeController"}),
(s:Service {name:"EmployeeService"})
CREATE (c)-[:CALLS]->(s);
MATCH (s:Service {name:"EmployeeService"}),
(r:Repository {name:"EmployeeRepository"})
CREATE (s)-[:USES]->(r);
Querying the Graph
When working through the Querying the Graph stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
MATCH path =
(endpoint:Endpoint)-[*1..4]-(context)
WHERE endpoint.domain = "employee"
RETURN path
Controller
Service
Handler
Repository
Table
Permission
Tenant Rule
Tests
ADR
A Better Architecture: Hybrid Retrieval
When working through the A Better Architecture Hybrid stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Measure recall on a fixed question set before tuning prompts. Prompt churn rarely fixes a weak retrieval surface. When working through the A Better Architecture Hybrid stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
User Request
|
v
Context Retriever
|
+--------------+--------------+
| | |
v v v
Vector Graph Keyword
Search Traversal Search
| | |
+--------------+--------------+
|
v
Context Ranking
|
v
Agent Context
|
v
LLM
The Context Budget Problem
The The Context Budget Problem stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Repository:
8 million tokens
Controller conventions
Service convention
Security rule
Two repositories
One ADR
Three tests
Total:
18,000 tokens
Context Graph + Agent Skill
The Context Graph Agent Skill stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
Developer
|
v
AI Agent
|
v
add-end-point Skill
|
v
Context Graph Query
Developer
|
| "Create employee endpoint"
v
AI Agent
|
| reads
v
.agents/skills/add-end-point/SKILL.md
|
| SKILL.md says:
| "Before generating code,
| call get_task_context"
v
MCP Tool
get_task_context(...)
|
v
Context Graph Service
|
+---- Neo4j / Graph DB
|
+---- Vector Search
|
+---- Git metadata
|
v
Relevant Context
|
v
AI Agent
|
| follows retrieved rules
v
Generate / modify code
Nearest endpoint:
LeaveRequestController
Controller pattern:
@RestController
constructor injectionService pattern:
interface + implementationArchitecture:
Controller
-> Service
-> Handler
-> RepositorySecurity:
LEAVE_VIEWTenant rules:
OrganizationID + TenantIDPersistence:
HrLeaveBalanceTesting:
ControllerTest
ServiceTest
RepositoryITArchitecture decision:
ADR-42
Then the Agent Generates Code
The Then the Agent Generates stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
LeaveBalanceController
LeaveBalanceRequest
LeaveBalanceResponse
LeaveBalanceService
LeaveBalanceServiceImpl
LeaveBalanceHandler
LeaveBalanceRepository
LeaveBalanceProjection
LeaveBalanceException
LeaveBalanceControllerTest
LeaveBalanceServiceTest
LeaveBalanceRepositoryTest
The Then the Agent Generates stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
Does the endpoint follow the required architecture?
YES.Does it apply security?YES.Does repository filtering include TenantID?YES.Does it include OrganizationID?YES.Are mandatory tests present?YES.
Repository Bootstrap
For the Repository Bootstrap stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
bootstrap-context
2-3 representative endpoints
architecture
build files
framework versions
dependency injection
security
database patterns
testing
exception handling
transactions
module boundaries
Repository
USES
Java17
Repository
USES
SpringBoot3Endpoint
FOLLOWS
Controller-Service-Handler-RepositoryDatabaseQuery
MUST_INCLUDE
TenantIDDatabaseQuery
MUST_INCLUDE
OrganizationID
Skills Become Much Smaller
For the Skills Become Much Smaller stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
For employee APIs use EmployeeHandler.
For payroll APIs use PayrollOrchestrator.For recruitment APIs use ActionHandler.For employee APIs tenant filtering happens...For payroll APIs...
1. Understand the requested endpoint.
2. Query the repository Context Graph.3. Resolve:
- architecture pattern
- closest implementation
- security
- data ownership
- persistence
- testing requirements4. Generate code.5. Validate generated changes against graph constraints.6. Record newly confirmed repository knowledge.
Skills Tell the Agent HOW
For the Skills Tell the Agent stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
Context Graph Tells the Agent WHAT IS TRUE HERE
For the Context Graph Tells the stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
Context Graphs and Multi-Agent Systems
For the Context Graphs and Multi-Agent stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
Architecture Agent
Security Agent
Backend Agent
Testing Agent
Database Agent
Reviewer Agent
duplicate work
different conclusions
large token usage
conflicting decisions
Context Graph
/ | \
/ | \
v v v
Backend Security Testing
Agent Agent Agent
Endpoint requires FINANCE_WRITE
Context Graphs Can Learn From Pull Requests
For the Context Graphs Can Learn stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness.
repository.findByEmployeeId(employeeId);
EmployeeRepositoryQuery
MUST_FILTER_BY
TenantID
EmployeeRepositoryQuery
MUST_FILTER_BY
OrganizationIDRule
LEARNED_FROM
PR-11882
A Context Graph Is Not the LLM’s Brain
For the A Context Graph Is stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Prefer structured outputs with schema validation over free-form prose when the next step is code or a tool call.
LLM
=
Reasoning Engine
Context Graph
=
Structured MemoryVector Database
=
Semantic Memory SearchSkills
=
ProceduresTools
=
Actions
AI Agent
|
+---------+---------+
| | |
v v v
Skills Context Tools
Graph
|
+-------+-------+
| |
v v
Vector Graph
Search Store
Context Graph vs Fine-Tuning
For the Context Graph vs Fine-Tuning stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Put human approval on edges that spend money or change production data. Compile-time wiring does not equal business completeness. For the Context Graph vs Fine-Tuning stage, define the inputs, the owner of the step, and the exit criteria before changing code. Operators should be able to re-run the step from a known checkpoint without guessing hidden state. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
OldRule
status = deprecated
NewRule
status = active
Context Graph vs Huge Prompt
When working through the Context Graph vs Huge stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Cache stable system instructions and tool schemas. Re-sending identical preamble is a common source of burn.
AGENTS.md
= 40,000 lines
Task
|
v
Relevant Subgraph
|
v
Prompt
Entire Organization
|
v
Prompt
How to Would Deploy a First Version
When working through the How to Would Deploy stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
Repository:
employee-service
Skill:
add-end-point
Module
Class
Endpoint
Service
Repository
Table
Rule
Permission
Test
ADR
CONTAINS
EXPOSES
CALLS
USES
WRITES_TO
READS_FROM
REQUIRES
TESTED_BY
FOLLOWS
DEFINED_IN
Suggested Deployment
When working through the Suggested Deployment stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
Git Repository
|
|
v
Repository Indexer
|
+------ Java Parser
|
+------ Git Parser
|
+------ Markdown Parser
|
+------ SQL Parser
|
v
Context Graph DB
|
+------ Vector Index
|
v
Context Service / MCP
|
v
AI Coding Agent
|
v
Repository Skills
Update the Graph Incrementally
When working through the Update the Graph Incrementally stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Prefer small, testable units over sprawling scripts. When a step fails, the failure should point at a single responsibility rather than a tangled pipeline. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
EmployeeController.java
EmployeeService.java
ADR-42.md
git diff HEAD~1
changed files
|
v
re-index
|
v
update graph
Context Should Have Confidence
When working through the Context Should Have Confidence stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
EmployeeController
CALLS
EmployeeService
confidence = 1.0
source = static-analysis
Employee APIs
PROBABLY_REQUIRE
ManagerPermission
confidence = 0.62
source = llm-inference
FACT
OBSERVATION
INFERENCE
DECISION
RULE
Humans Must Be Able to Correct the Graph
When working through the Humans Must Be Able stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
Payroll APIs use Handler architecture.
HandlerPattern
status = deprecated
OrchestratorPattern
status = active
The Bigger Idea: From Repository Search to Repository Understanding
When working through the The Bigger Idea From stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Keep configuration outside application code. Environment files, secret stores, and feature flags belong in one place operators can audit without reading the whole graph. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node.
Question
|
v
Search Files
|
v
Read Files
|
v
Generate Code
Question
|
v
Understand Task
|
v
Identify Relevant Entities
|
v
Traverse Architecture
|
v
Recover Rules
|
v
Recover History
|
v
Recover Decisions
|
v
Build Context
|
v
Execute Skill
|
v
Validate Result
|
v
Record Learning
The Senior Engineer Analogy
When working through the The Senior Engineer Analogy stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Document the happy path and the recovery path together. Retries, human gates, and dead-letter handling are part of the product, not later polish. Checkpoint after expensive steps. Resume should not re-bill the same LLM call when an operator retries a later node. When working through the The Senior Engineer Analogy stage, write down the contract first: required inputs, success signal, and what happens on partial failure. That checklist keeps later code changes honest. Treat this stage as a contract between inputs and validated outputs. Name the artifacts, define success checks, and refuse silent partial completion.
That Is the Real Promise
The That Is the Real stage works best when treated as a measurable surface. Capture one golden transcript, one failure case, and the rollback note before expanding scope. Record timings and token or query cost next to functional results. Cost visibility early prevents surprise bills when the path moves from demo to shared environments. Keep graph state flat and typed. Nested blobs hide which node wrote which field and break resume after interrupts.
The Future Repository May Look Very Different
CODE
What the system does.
SKILLS
How agents should perform work.CONTEXT GRAPH
What the agent should understand about this repository.
my-platform/
│
├── services/
│
├── database/
│
├── docs/
│
├── tests/
│
│
├── AGENTS.md
│
├── .agents/
│ │
│ ├── skills/
│ │ ├── add-end-point/
│ │ ├── fix-bug/
│ │ ├── create-migration/
│ │ └── review-pr/
│ │
│ └── context/
│ ├── graph-schema.yml
│ ├── rules.yml
│ └── bootstrap.yml
│
└── context-graph/
├── indexer/
├── extractors/
├── graph-api/
└── validation/
One Final Example
TASK
Create reimbursement endpoint.
DOMAIN
Finance / Employee.PATTERN
ExpenseController.ARCHITECTURE
Controller -> Service -> Orchestrator -> Repository.AUTHENTICATION
Session authentication required.AUTHORIZATION
CREATE_REIMBURSEMENT.TENANCY
OrganizationID + TenantID mandatory.DATABASE
HrReimbursement.TRANSACTION
Orchestrator owns transaction.IMPORTANT HISTORY
Direct reimbursement status mutation caused incident FIN-822.RULE
Use ReimbursementWorkflow.TESTING
Controller + Service + Repository tests required.REFERENCE PR
PR-11822 implemented similar Expense workflow.
Closing Thought
LLM
gives the agent intelligence.
Skills
give the agent procedures.Tools
give the agent hands.Vector search
helps the agent find things.Context Graph
helps the agent understand how those things are connected.Decision history
helps the agent understand why.