Beyond Memory: How Ontology Enables Continuous Project Learning for Coding Agents
The article explains how ontology — shared domain concepts and constraints — combined with memory and recursive self-improvement loops helps coding agents progressively understand project-specific knowledge, detailing a three-layer knowledge graph implemented in Tencent's R&D loop that improved bug localization success from 58% to 65%.
1. What Is Ontology in the AI Era?
Ontology (in the knowledge-engineering sense) makes explicit the concepts, relationships, and applicability conditions of a domain so they can be shared. Unlike a database schema (which describes data structure) or a knowledge graph (which stores entity instances), ontology captures the shared meaning of objects and relations — e.g., what "order completion" means across warehouse, finance, and support systems. The article illustrates with a simplified order system: "Order" and "Shipment" are types; a specific order is an instance; "order has shipment" is a relation; amount, currency, and creation time are attributes. Business rules such as split-shipment logic and completion conditions (all valid shipments signed) must be explicitly modeled.
Formal languages like W3C OWL 2 ( https://www.w3.org/TR/owl2-overview/) provide classes, properties, individuals, and logical axioms, but engineering practice can start with versioned concept definitions, relation types, data mappings, and rule files. Crucially, ontology expresses rules; validating that live data satisfies them is a separate step (e.g., using SHACL ( https://www.w3.org/TR/shacl/) or application-level checks).
1.1 How It Differs from Schema, Knowledge Graphs, and RAG
Database/Interface Schema — fields, types, structure, partial constraints; still leaves open what a field means in business and how it maps across systems.
CodeGraph — symbols, calls, dependencies, code locations; does not capture the business responsibility of a call chain or inviolable conventions.
Knowledge Graph — entity and relation instances; does not guarantee that relations carry explicit semantics, scope, or justification.
Documents & RAG — retrieves relevant material; still requires judging whether multiple pieces refer to the same object and whether they apply to the current scenario.
Ontology — provides shared concepts, relation semantics, and associated axioms/constraints; the remaining question is whether current facts conform to these definitions and whether actions produce expected results.
The author emphasizes that the key gap is: after retrieving a piece of knowledge, can the system determine which object it describes, under what conditions it holds, and which inference step it supports? Storage technology (graph DB, relational tables, files) is an implementation choice.
1.2 Lessons from Palantir and Forward Deployed Engineers (FDE)
Palantir's Ontology system (
https://www.palantir.com/docs/foundry/architecture-center/ontology-system/) links data, logic, actions, and security. It binds business objects to logic, operations, and permissions — e.g., "migrate an instance" involves instance-node relations, target-zone constraints, migration state, executable actions, and operation rights. Palantir's modeling advice (
https://www.palantir.com/docs/foundry/ontology/ontology-best-practices/) stresses starting from the real-world domain, then mapping source data — directly mirroring the challenge in R&D where one business object spans multiple systems and one table mixes multiple concepts. FDEs, who work on-site with customers, repeatedly face the same disambiguation: "the process succeeded" — but which object, which phase, acceptance or actual business effect? As agents move closer to real operations, this semantic clarification becomes unavoidable. Ontology provides a way to deposit such clarifications into a shared model so they need not be re-explained in every prompt.
2. From Loop and Memory to Recursive Self-Improvement (RSI)
2.1 Task Repetition ≠ System Learning
An Agent uses a model to judge, calls tools to act, and iterates based on environment feedback. The Loop is this action-observation-adjustment cycle (e.g., write code → run tests → read failures → modify → retest). The loop improves the current task, but a new session may repeat the same searches and misunderstandings. Memory stores cross-session information: events, verified knowledge, handling methods. Model weights stay fixed, yet the agent system improves by acquiring better knowledge and tools.
Reflexiv ( https://arxiv.org/abs/2303.11366) shows an agent forming natural-language reflections from task feedback and storing them in episodic memory. Agent Workflow Memory ( https://arxiv.org/abs/2409.07429) goes further, inducing reusable workflows from history and selectively providing them to later tasks. However, storing ≠ learning ; a mistaken experience recalled more stably can reinforce errors. Experience must change subsequent behavior and be validated by subsequent outcomes. Feedback must preserve the conditions, reasoning, and excluded alternatives — not just "success/fail".
2.2 Three Levels of Recursive Self-Improvement
RSI (Recursive Self-Improvement) means the system changes itself to improve future performance, and the process that generates improvements can itself be improved. The article distinguishes three engineering-focused levels:
In-task iteration — changes to the current task's plan or artifact (e.g., test fails → patch this requirement's code).
Cross-task self-improvement — changes to persistent knowledge, tools, or work methods (e.g., save a verified compatibility experience for next round).
Self-improvement of the improvement process — changes to how improvements are generated, selected, and validated (e.g., adjust experience-extraction or skill-optimization strategies based on downstream performance).
Darwin Gödel Machine ( https://arxiv.org/abs/2505.22954) iteratively modifies the agent's own code, maintaining a population of candidates filtered by coding benchmarks — changing the problem-solving machinery, not just a single patch. Skill∞ ( https://arxiv.org/html/2610.35434v1) makes the recursion explicit: task skills store task-solving methods; meta-skills describe how to optimize task skills. A meta-agent diagnoses execution traces, proposes candidates, requests independent review, and allocates search budget. The same optimization process can then be applied to meta-skills themselves. Crucially, scoring is kept outside the self-improvement loop, and candidates undergo independent review — improving the method is not the same as lowering the bar.
These researches give RSI concrete experimental objects, but they operate under constrained tasks, budgets, and verification conditions. In enterprise R&D we can start with external memory, tools, and processes without touching base-model weights; a single positive experiment does not prove sustained, unbounded improvement.
3. Combining Ontology and RSI
3.1 EvoOntology: Evolving Ontology from Agent Usage Feedback
EvoOntology ( https://arxiv.org/html/2609.15779v1) tackles data-analysis/text-to-SQL scenarios where agents repeatedly reconfirm field meanings, table relationships, and filter conditions. It splits an evolvable ontology system into Content (domain concepts, field mappings, usage constraints, supporting evidence), Schema (how those objects and relations are represented), and Tool (how the agent discovers and expands information). Two access modes are provided: browse (find semantically relevant objects) and resolve (retrieve needed objects and associated records). Sessions start with a brief summary; detailed knowledge is queried on demand.
A card-game query example: the initial ontology knows cards link to legality records and that status lives in legalities.status, but it does not encode that status is relative to a format. The agent finds the field but must re-derive how to use it. Evolution identifies the missing semantic content — adding the meaning of status values, corresponding fields, observational evidence, and constraints. To find cards banned in a target format, both legalities.status = 'Banned' and legalities.format = target_format must hold; checking only "banned" loses the scope. This change touches Content, not the query tool or Schema.
Key methodological points: (1) Execution traces are analyzed to classify the limitation as content gap, tool exposure issue, or schema expressiveness limit. (2) Each candidate modification targets one level. (3) Candidates are compared against the original under the same model, validation set, and interaction budget; only improvements meeting a threshold are kept. (4) Construction/selection materials are separated from final test tasks; the ontology is frozen before final evaluation — no peeking at test answers. The core insight: ontology both helps the agent understand the task and can be revised based on the agent's actual usage results. Revising the ontology is distinct from recursively improving the revision mechanism (which Skill∞ addresses).
3.2 The Team's Approach: Give Feedback a Concrete Target
Synthesizing Reflexion, Agent Workflow Memory, EvoOntology, and Skill∞ reveals a progression: from leaving experience, to forming reusable methods, to evolving semantic knowledge and access, to making the optimization process itself modifiable. The team's takeaway: don't lump all failures into "model not smart enough" or "not enough memory." A localization failure may stem from missing code relations, misunderstood business concepts, stale experience conditions, or known constraints not being checked. Ontology lets feedback attach to specific objects — a business concept, a cross-repo mapping, a state condition, a faulty inference — so the next optimization has a concrete target instead of rewriting the entire memory.
Examples: conflating "request accepted" and "business completed" → split or enrich concepts; concept correct but search returns only similar old cases → adjust index or applicability filtering; retrieval and explanation fine but data-plane check omitted → fix workflow and verification tools. These need different fixes, not the same generic reminder.
The desired loop: Loop provides actions and real results; Memory stores experiences with provenance; Ontology organizes concepts and experience applicability conditions; subsequent tasks verify whether the knowledge changed behavior. If extraction, retrieval, and usage strategies can also be improved from this, the system enters learning-mechanism improvement.
Cost warning: semantic organization adds extraction/maintenance overhead; graph relations can amplify bad experiences. Therefore, the combination requires both "can link" and "can correct" capabilities — the system must be able to narrow an experience's scope, split mistakenly merged concepts, or retract invalid conclusions, not just keep adding content.
3.3 What a Senior Engineer Sees in Code
To decide what knowledge to extract, the team asked: what does a project-familiar engineer know beyond function call graphs? They know the business flow a logic segment belongs to, who drives state transitions, which consumers still depend on an old protocol. Seeing a special branch, they recall why it was kept. Seeing an anomaly, they know which observation distinguishes environment issues from real defects. They know which conditions must hold despite process changes — these are business invariants .
The article maps engineer judgments to desired project knowledge assets:
Why does this code exist? → Functional responsibility, business goals, design decisions, rejected alternatives.
Does parameter meaning change across this boundary? → Field mappings, units, defaults, null semantics, compatibility meanings.
Who advances state, when is it done? → Lifecycle, state scope, state drivers, completion evidence.
Which condition must never be broken? → Contract-backed invariants, preconditions, counterexamples.
Who is affected by a change here? → Cross-repo consumers, dependency paths, version ranges, related tests.
Why did this fail before? → Trigger conditions, root-cause evidence, fix trade-offs, applicability boundaries.
How to falsify the current hypothesis? → Diagnostic branches, discriminating observations, regression cases, open questions.
Knowing "what I don't know" matters: seniors distinguish current implementation, confirmed requirements, and personal guesses; they revert to design or ask product owners on conflict. Extracted experience should preserve this distinction, not treat every confident explanation as fact. The goal isn't to replicate full human cognition but to externalize the knowledge clues that repeatedly steer localization, change scope, and verification. Ontology supplies shared concepts; historical cases supply episodes; Skills supply methods; tests and runtime results validate. Next: put these roles into the actual workflow.
4. Practice: Organizing Three-Layer Project Knowledge in the R&D Loop
4.1 One Loop: From Design Completion to Pre-Release Testing
Current practice: after requirements and design are settled, the agent handles implementation through pre-release testing. Humans set goals, design, and necessary business trade-offs; the agent understands requirements, implements changes, runs verification, locates and fixes failures until acceptance criteria are met. Design completion doesn't mean zero ambiguity — the agent must translate design into observable acceptance conditions (object, scope, inputs, expected states, exclusions). Business conflicts still require clarification, not guessing. Scope excludes production release or unauthorized actions.
The loop (illustrated in Figure 1) runs in the team's cloud-database R&D path: local compile/static checks; native unit, functional, and affected regression tests in integration environments; occasional real-data access verification. Interface success, async task completion, process readiness, client usability each need matching evidence. The loop doesn't mandate full re-run on every failure: unchanged report + unchanged input → no redeploy; test observer changed → re-verify affected judgments; unknown write result → restore observation of original task to avoid duplicate execution. Division of labor: agent handles semantic understanding, planning, implementation, exception judgment; deterministic tools execute confirmed routine steps (build, deploy, wait, callback aggregation). Tool success ≠ business acceptance. The loop must deliver acceptance evidence tied to the actual version, not just the model saying "done."
This execution generates abundant learnable material: which concept was misunderstood, which test exposed a compatibility issue, which clarification changed implementation direction. Team Memory must carry these into the next round, not let them vanish with the session. Analysis of real bottlenecks shows many reworks involve business concepts: the model reads local code but misinterprets project-specific meanings of objects, states, or fields. This observation (not yet quantified as a failure percentage) motivated adding semantic relations to the existing Memory, beyond saving more raw dialogues.
4.2 Four Memory Assets + Three-Layer Cross-Indexed Graph
Existing team Memory comprises four assets: Chat Memory (dialogue context, clarifications, decisions), Wiki (business/architecture knowledge), CodeGraph (code structure, dependencies), Skill (reusable handling methods). Each has distinct purpose and provenance.
On top of these, the team built a three-layer cross-repo associative graph . The four assets and three layers describe two dimensions: assets focus on material form and use; layers focus on how different knowledge types interlink and are accessed. They are not seven parallel assets nor strictly one-to-one.
Layer 1: Engineering Facts — primarily built by engineering means: functions, types, fields, interfaces, and their users; similar to CodeGraph but includes cross-repo links; largely static. Helps the agent locate definitions, find users, see which repos a feature spans. Cross-repo links require contract verification via APIs, messages, or schemas — not just same-name symbols. Dynamic behaviors (reflection, config routing) may need runtime info; "code may connect" ≠ "this execution traversed".
Layer 2: Project Semantics — combines engineering analysis with LLM to extract functional responsibilities, business concepts, inter-definition relations, field meanings, cross-repo mappings, and constraints; supports intra- and cross-repo; more dynamic, updated as new materials and understandings arrive. Layer 1 tells the agent a field flows from Repo A to Repo B; Layer 2 explains what each end means, whether unit conversion occurs, whether defaults match, which versions need compatibility. Semantic layer must offer verifiable explanations anchored to engineering locations. LLM-generated candidate relations cannot be promoted to project facts on linguistic fluency alone.
Layer 3: Errors & Experiences (bug_fixed) — organizes historical bugs into experiences, attached to relevant nodes/relations of the first two layers, exposed via progressive disclosure. Code finds related experiences; experiences trace back to code and business conventions. Critical distinction: an event that occurred vs. a reusable experience . Events record version, symptom, conditions, cause judgment, fix; experiences distill the revealed risk and applicability scope. One event may support multiple experiences; multiple events may jointly support one constraint. Symptom location, root-cause location, and patch location can differ — avoid collapsing into an unexplained "related code" link.
Figure 2 shows bidirectional query arrows: "code implements a convention" ↔ "convention implemented by which code" (semantic relations themselves aren't necessarily symmetric). Linking to a historical issue means "worth checking", not "same root cause proven". Ontology need not be a fourth layer. It lives in Layer 2's concept/constraint expressions and in cross-layer role distinctions (implementation, experience, evidence). Layer 1 provides engineering anchors; Layer 3 provides historical counterexamples; both help refine project semantics. Ongoing ontology optimization makes these meanings and boundaries more reliable.
4.3 Letting the Agent Navigate Relations to Needed Knowledge
Three-layer cross-indexing means the model can enter from any layer: known symbol → engineering layer; business requirement only → concept layer; fault symptom → experience layer. Once inside, it follows relations based on the current question — no fixed "read code → read semantics → read history" order.
Simplified cross-repo scenario: a config convention — omitted strategy field → default config; explicit empty list → clear limits. After request failure and retry, user selection lost. (Illustrative, not from later localization trial.) From the field, Layer 1 guides the agent through Repo A request parsing, cross-repo message contract, Repo B persistence and retry read path. Layer 2 adds that "omitted" and "explicit empty" express two intents; both propagation and retry must preserve the distinction. Historical experience with same applicability conditions (default-value override) offers a prioritized candidate explanation.
Verification follows: what value was saved on first request? What value read on retry? If distinction lost at save → check parsing/persistence; if save correct but retry changes → check default-value application point. Experience narrows search; current code and live observation decide.
Tests can expand along constraints: omitted/empty/non-empty handling, intent preservation across retry, compatibility when protocol versions differ. If current fault differs from old case, the exclusion process is equally valuable. Must record which conditions didn't match, which observation overturned the old explanation — not just the final patch.
Progressive disclosure controls information volume: first provide association reason, risk summary, applicability scope; then expand trigger conditions and check methods; finally full diffs, dialogues, runtime evidence. Disclosure depth and graph layer are orthogonal; engineering and semantic layers can also unfold gradually. Key preconditions must appear with the summary — e.g., an experience valid only for old protocol must not hide the version condition in the last layer. Permissions and project scope constrain retrieval entry points; cross-repo navigability ≠ read-all. Graph traversal needs budget and stop conditions: return to task once enough material supports or rejects the current hypothesis.
This yields multiple concrete uses: planning → locate impact from function; implementation → verify cross-repo contracts; testing → supplement boundary cases from constraints and historical counterexamples; localization → follow symptoms to candidate mechanisms. Useful navigation doesn't prescribe the model's entire thinking order; it gives the next query a basis, and the query result feeds back into the current judgment.
4.4 Extracting Correctable Experiences from Code, Bugs, and Dialogues
With the three-layer structure in place, the priority is improving semantic extraction and maintenance. The team avoids a single extraction prompt that compresses everything into similar summaries. Source code describes current behavior; design expresses intended behavior; bug tickets record anomalies and investigations; dialogues contain final clarifications and rejected proposals.
A practical method: (1) engineering analysis to locate symbols and contracts; (2) LLM generates semantic candidates around high-frequency misjudgments. Each candidate carries source, object, version, applicability conditions; then cross-checked against design, implementation, tests, or domain confirmation. Two repos both naming "Task" doesn't mean same concept; same business object with different names shouldn't be auto-split.
Desired concept card: definition, easily confused objects, state scope, engineering mappings, key constraints, verification entry points. Desired experience: at least symptom, trigger conditions, cause evidence, handling, inapplicability conditions. This is a data-design direction; not all fields are auto-filled yet.
Real internal retrospective example: A parent instance was deleted, but the logical topology table retained a record. Early judgment called it dirty data. Later verification revealed parent instance and child topology belong to different scopes; logical record ≠ physical process. The earlier "deletion defect confirmed" classification was retracted. This mirrors the card case: fields and data were found, but object or applicability scope wasn't fully expressed. In the deletion scenario, a cleanup helper's safety check passing doesn't prove business-level cleanup is correct; conversely, current implementation retaining the record doesn't prove all versions should retain it. Need to verify deletion contract, then observe business state, logical data, and physical resources separately.
For such experiences, next step is tracing correction impact along associations. When an old conclusion is superseded, summaries, Skills, and test assumptions referencing it should enter a review-pending state. Original events aren't deleted but must not continue guiding new tasks as confirmed rules. This requires versioned statements and dependency tracking — a capability the team aims to strengthen.
Another retrospective noted "read but not acted on": a shared-management-port experience was retrieved, yet the subsequent observer still judged by an incorrect one-to-one mapping. This shows recall logs alone don't prove experience effectiveness. A stable constraint should map to the current run's object mapping, test assertion, or pre-action check. Turning natural-language experience into enforced checks requires confirming contract source, reviewing assertions, and avoiding the same faulty assumptions generating both implementation and the sole acceptance criterion.
Start small: prioritize concepts that repeatedly affect judgments — state, defaults, resource identity, cross-repo compatibility. For localized, contract-clear changes where ordinary code search suffices, don't force-load the whole graph. Ontology maintenance investment must be justified by reduced misjudgments and rework.
5. Preliminary Results and How to Validate Ongoing Improvement
5.1 Bug Localization Success Rate: 58% → 65%
In an internal code-bug localization trial, adding the graph capabilities raised the agent's localization success rate from 58% to 65% (+7 percentage points). This is an early positive signal that the three-layer associative knowledge is worth further validation on this batch of localization tasks.
Localization is a sub-task of the full loop. After finding the issue, patch correctness, regression adequacy, environment stability all affect final delivery. Hence this result doesn't translate directly to overall R&D efficiency gains, nor does it alone prove the semantic layer contributed the entire uplift.
Further disentanglement needed: Does the engineering graph make cross-repo code easier to find? Do semantic explanations reduce object/condition misjudgments? Does historical experience provide better diagnostic starting points? Is the three-layer combination more effective than any single layer? These require controlled ablation under the same model, information sources, and budget.
When comparing graph vs. plain Memory, information parity is critical. If the graph group gets extra historical tickets while the retrieval group only sees code, the gain may reflect more information, not better organization. Fairer comparison: give both groups identical materials, observe whether relational and applicability expressions add value.
bug_fixed delivers two distinct business values: (1) known failure recurs → retrieve old solution, reduce duplicate work; (2) target bug never in graph → use other events' experience to localize, demonstrating transfer ability. These should be reported separately.
Evaluating on unseen problems requires excluding the target patch, subsequent regression tests, duplicate tickets, and indirect relations derived from them. Deleting the bug title isn't enough; the semantic layer may retain answer clues. Time-slicing and provenance tracking are both experimental necessities and help detect stale knowledge in the production graph.
5.2 From One-Time Localization Gain to Verifiable Continuous Improvement
Next, observe both outcomes and process. Outcomes: localization success rate, pre-release acceptance completion rate, defect leakage, human interventions. Process: when knowledge was retrieved, whether conditions matched, whether it changed implementation or testing, where rework still recurs. Process evidence aids diagnosis; subsequent controlled results decide if improvement holds.
For continuous learning, a feasible experiment: advance tasks chronologically. Group A uses a frozen graph version; Group B absorbs only experiences formed and validated in completed tasks. Compare on the next batch of unseen tasks, while retaining regression checks on old tasks. If new knowledge lifts some tasks but regresses others, that regression must count.
Closer to RSI: include the knowledge-update process in the comparison. E.g., fixed extraction strategy vs. new strategy process the same historical materials, produce candidate graphs, test on independent tasks. Improvement targets: concept-splitting rules, cross-repo mapping verification methods, experience applicability filtering, skill generation pipelines. More generated relations ≠ better.
Borrowing from EvoOntology, each candidate modification should target an explainable problem: semantic gap, mapping error, access difficulty, execution omission. Specify expected behavior change, then compare before/after. Borrowing from Skill∞, if the learning strategy itself is modified, verify it produces more useful knowledge/methods across multiple tasks, not just fixes one experience.
Using the earlier empty-value scenario, three successive changes: (1) fix retry code → complete current task; (2) codify empty-vs-default distinction as conditional experience → improve input handling for future similar tasks; (3) discover multiple experiences miss applicability conditions → modify extraction strategy to require conditions and counterexamples for new candidates. The third change's efficacy is judged by whether its generated experiences help later diverse tasks while reducing misuse. Modification results feed the next strategy optimization, not just add a permanent reminder.
Enterprise context needs external boundaries: knowledge can be revised, but business goals and permissions cannot be relaxed by the learning process. Agent may flag unreliable test tools and propose fixes, but cannot delete failing cases to improve scores. High-impact constraint releases, version switches, rollbacks must retain review gates. Costs count too: semantic extraction, graph maintenance, extra checks consume time; retrieval noise may introduce new errors. Final comparison must weigh user-facing end-to-end latency, model/tool overhead, maintenance investment — not just cumulative execution time or knowledge entry count. Current three-layer graph localization gain and sustained learning-method improvement are two separate goals needing separate evidence.
6. Conclusion: Make Project Understanding the Starting Point for the Next Round
Ontology clarifies business objects, relations, and constraints, giving experiences verifiable meaning and applicability scope. Memory preserves these knowledge pieces and their provenance. Loop supplies actions and feedback. Self-improvement mechanisms use subsequent results to decide what to keep, correct, or discard. When the improvement process itself can be validated and optimized, recursion emerges.
Current practice: introduce team Memory into the design-to-pre-release R&D loop, using a three-layer graph (engineering facts, project semantics, bug_fixed) to link intra- and cross-repo knowledge. This lets the agent go from code to experience, from experience back to implementation, and use concepts and constraints to judge applicability. The 58%→65% localization result is an early signal; full-loop gains and continuous learning effects need further validation.
The aim is to emulate a senior engineer's effective project associations: knowing what a code segment owns, why it was designed that way, where it broke before, how to verify one's own judgment. These understandings need not be extracted all at once, but should accumulate stepwise and be correctable when new evidence appears.
After a loop ends, besides delivering requirements and test results, the team wants to retain the newly clarified project knowledge. The next round can reliably start from there — one less repeated understanding, one less repeated misjudgment. The integration of ontology and RSI in internal R&D can begin with this concrete step.
TencentDB Agent Memory is open-sourced on GitHub. The team invites developers to discuss engineering trade-offs in memory system design and welcomes feedback via Issues to co-build next-generation agent memory infrastructure:
https://github.com/Tencent/TencentDB-Agent-MemorySigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
