A method for continuous evolution of code-based intelligent agents based on structured memory.

By constructing structured memory and introducing a two-stage retrieval and self-correction mechanism, the problem of lack of experience internalization and self-evolution in complex engineering tasks by code-based intelligent agents is solved, thereby improving the ability and accuracy of intelligent agents to solve complex tasks and realizing the continuous evolution of intelligent agents.

CN122086382APending Publication Date: 2026-05-26BEIJING FEISHI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610205155.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-12
Publication Date
2026-05-26

Smart Images

  • Figure CN122086382A_ABST
    Figure CN122086382A_ABST
Patent Text Reader

Abstract

This invention provides a method for the continuous evolution of code agents based on structured memory. Addressing the problem that existing code agents cannot adapt to complex repository-level tasks, this invention proposes a human-machine co-evolution framework. The method mainly includes three stages: First, the memory construction stage, which uses a large language model to extract historical code submission records into standardized structured memories and constructs a vector database; Second, the dynamic execution and self-correction stage, where, when handling new tasks, a two-stage retrieval mechanism is used to obtain the most relevant historical experience to the current problem, and a refined sub-agent is introduced to generate test cases and verification lists, providing real-time guidance and correction to the main agent's generation results; Third, the experience internalization stage, where manually verified task solutions are again converted into structured memories and stored in the database. This invention, by constructing a closed-loop evolution mechanism, significantly improves the accuracy and automation level of code generation and defect repair.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the interdisciplinary field of artificial intelligence and software engineering, and is a method for the continuous evolution of code agents based on structured memory. This invention is an agent technology architecture that utilizes a large language model to extract structured experience from historical commits in a code repository, and achieves automated problem-solving and continuous capability improvement for complex code tasks through a two-stage retrieval and self-correction mechanism. Background Technology

[0002] With the rapid development of large language models, software engineering is undergoing a shift towards a human-computer collaboration paradigm. In this paradigm, developers are gradually transforming from manual coders to high-level architects, guiding intelligent agents to complete specific code implementation and maintenance tasks through natural language instructions. Although existing code-based intelligent agents perform well in handling independent and simple tasks, they still face significant limitations when dealing with complex, repository-level engineering problems, mainly in the following aspects:

[0003] 1. Lack of understanding of project evolution: Most mainstream code agents operate based on the current state of the code repository, failing to perceive the project's evolution. This "static" perspective makes it difficult for agents to capture project-specific coding standards, complex cross-file dependencies, and unwritten development conventions. As a result, agents lose information implicit in past development processes, leading them to rely solely on their own capabilities when solving new problems.

[0004] Second, the lack of an experience internalization mechanism: Current intelligent agent systems typically reset the context after each task, failing to internalize the solution. This prevents the performance of the intelligent agent from improving as the project develops.

[0005] III. Limitations of Existing Memory and Evolutionary Mechanisms: Although current research on long short-term memory mechanisms attempts to enhance the continuity of large language models, and research on self-correction attempts to optimize output through feedback, these general methods are not specifically designed for the evolutionary characteristics of code repositories. They struggle to effectively structure non-standardized code commit records and have not formed a complete closed loop from "structuring historical experience" to "real-time execution correction" and then to "internalizing new experience."

[0006] Therefore, there is a need for a code-based intelligent agent framework that can utilize project evolution history to build structured memories and continuously internalize experience and achieve self-evolution during collaboration with users, in order to solve the above-mentioned technical bottlenecks and improve the autonomous adaptability and problem-solving rate of intelligent agents in complex software engineering tasks. Summary of the Invention

[0007] This invention provides a method for the continuous evolution of code agents based on structured memory, addressing the shortcomings of existing technologies where code agents cannot adapt to complex repository-level tasks and repeatedly make the same errors. This improves the accuracy of code generation and the agent's adaptability to specific projects. Specifically, it includes the following steps:

[0008] The memory construction process involves: acquiring the historical commit records of the code repository, transforming these records into structured memory entries using a large language model, and building a vector database. Specifically, first, the original commit information and code change details are obtained; then, the large language model is used to analyze this unstructured data, extracting and generating structured data containing six dimensions: original commit information, code change details, functional keywords, formal problem description, root cause analysis, and solution summary; finally, the functional keywords and formal problem description are concatenated and vectorized, and stored in the vector database.

[0009] Experience retrieval step: Upon receiving the code task instruction, the agent retrieves historical memory entries related to the current task from the vector database according to the task instruction. This step employs a two-stage retrieval mechanism: First, based on the query vector generated by the task instruction, a preset number of candidate memory entries are retrieved from the vector database using an approximate nearest neighbor search algorithm; then, a cross-encoder model is used to score the semantic relevance between the task instruction and the candidate memory entries, and the final relevant historical memory entries are selected based on the scoring results.

[0010] Self-correction and execution steps: Utilizing retrieved historical memory entries, the refined sub-agent generates test cases and verification checklists, guiding the main code agent to modify code patches and iteratively correcting based on execution feedback. The refined sub-agent generates test code for reproducing the problem and a checklist containing verification logic based on the current task and retrieved historical successes; the main code agent corrects code patches according to these constraints; if a test fails, the refined sub-agent updates the test or checklist based on feedback information, driving the main code agent to perform the next round of optimization until verification is passed.

[0011] Experience internalization step: After the code patch is verified and manually confirmed and submitted to the code repository, the system pulls the new commit record containing the code patch from the code repository, calls the memory building step, uses the large language model to transform the new commit record into a structured memory entry and merges it into the vector database, realizing the closed-loop update of experience.

[0012] The method for continuous evolution of code-based intelligent agents based on structured memory provided by this invention has the following beneficial effects:

[0013] 1. Effective utilization of project evolution history: By transforming unstructured historical commit records into structured memories containing root cause analysis and solutions, this invention enables agents to understand and utilize project-specific coding conventions and implicit constraints hidden in historical code changes, avoiding generation errors caused by a lack of understanding of the project evolution context.

[0014] 2. A closed-loop mechanism for human-machine co-evolution has been established: This invention not only utilizes historical data but also feeds back the latest solutions validated by users to the memory bank through an experience internalization mechanism. This enables the agent to continuously accumulate knowledge as the project develops, avoiding the problem of agents being "forgetful" and repeatedly making mistakes in existing technologies, and achieving continuous growth in the agent's capabilities.

[0015] 3. Improved ability and accuracy in solving complex tasks: By introducing refined sub-agents and a two-stage retrieval mechanism, this invention can accurately find reference precedents and generate specific test cases and verification lists based on historical experience to constrain the code generation process. This strategy based on retrieval enhancement and real-time feedback correction significantly improves the success rate of the agent in handling complex, repository-level software engineering tasks.

[0016] 4. Enhanced autonomous adaptability of the agent: The refined sub-agent can dynamically adjust the verification logic based on the feedback during execution. Combined with the retrieved historical wisdom, the agent can adapt to different code repository styles and development standards through context learning without modifying the model parameters. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in this invention or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below.

[0018] Figure 1 This is a schematic diagram of the overall architecture and closed-loop evolution process of the code-based intelligent agent continuous evolution system based on structured memory provided in this embodiment of the invention. Detailed Implementation

[0019] To make the objectives, technical solutions, and technical effects of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.

[0020] First, the terminology used in the embodiments of the present invention will be explained illustratively.

[0021] Code agent: refers to an automated software development agent system built on a large language model, capable of receiving user instructions and autonomously completing code writing, debugging, and repair tasks through tool calls (such as reading files and running code). In this embodiment, the code agent includes a main code agent and refined sub-agents.

[0022] Structured memory refers to data entries formed by standardizing unstructured raw code submission records. In this invention, each structured memory is formalized as a six-tuple mi=(oi, ci, ki, pi, ri,si), which includes the original submission information (oi), code changes (ci), functional keywords (ki), formal description of the problem (pi), root cause analysis (ri), and solution summary (si).

[0023] Vector database: A database used to store structured memories. It transforms key information from structured memories into high-dimensional vectors through an embedding model and indexes them to support fast retrieval based on semantic similarity.

[0024] Refined Sub-Agent: This invention introduces an auxiliary agent module. It does not directly modify the codebase, but instead generates test cases and verification lists using retrieved historical experience before execution. During execution, it constrains and guides the behavior of the main agent, achieving self-correction.

[0025] Two-stage retrieval: A high-precision retrieval mechanism comprising two steps: "retrieval" and "re-ranking". The first stage utilizes near nearest neighbor search to quickly recall the candidate set, while the second stage uses a cross-encoder to perform fine-grained semantic relevance scoring on the candidate set to filter out the most relevant historical experiences.

[0026] Experience internalization: refers to the process of converting code patches generated by the agent and verified manually or automatically back into structured memory and storing them in a vector database, thereby achieving closed-loop evolution of the agent's capabilities.

[0027] like Figure 1 As shown, the method provided in this embodiment mainly consists of two core stages: stage one: memory construction, and stage two: self-correction and internalization.

[0028] 1. Phase One: Memory Building

[0029] This phase aims to reconstruct the repository's commit history, transforming the raw code commit history into structured knowledge that the agent can understand. The specific steps are as follows:

[0030] Step S11: Data Acquisition. The system first crawls or reads raw commit data from the online code repository, including commit information and specific code differences.

[0031] Step S12: Structured Extraction. The acquired unstructured submission data is input into the large language model. Using a preset prompt template, the large language model analyzes and refines the raw data, generating standardized six-tuple structured memories. Specifically, this includes:

[0032] Original commit message (oi): The original message used when committing code in an online repository.

[0033] Code Changes (CI): Code change information submitted in the online repository.

[0034] Extract functional keywords (ki): These serve as semantic anchors for subsequent fast indexing.

[0035] Generate problem description (pi): Formalize the symptoms and constraints of the problem that the submission addresses.

[0036] Root cause analysis (ri): Explaining the underlying logic or technical bottleneck that leads to the problem, helping the agent understand "why" it went wrong.

[0037] Summarize the solution (si): Extract standardized remediation strategies or action guidelines.

[0038] Step S13: Vectorized Storage. The generated structured knowledge (keyword ki and problem description pi concatenated) is encoded into dense vectors using an embedding model, and these vectors and their corresponding complete memory entries are stored in a local vector database.

[0039] 2. Phase Two: Self-Correction and Internalization

[0040] This stage is the core execution process for the intelligent agent to solve new tasks (such as fixing bugs or developing new features), achieving self-correction and capability evolution by utilizing the memories built in stage one. The specific steps are as follows:

[0041] Step S21: Task Reception and Query Generation. The user issues instructions to the code agent to fix bugs or add features. Based on its understanding of the task, the agent autonomously synthesizes a query vector.

[0042] Step S22: Context-aware retrieval.

[0043] Initial screening: The system uses an approximate nearest neighbor search in the vector database to retrieve the top-k candidate submission records based on the query vector.

[0044] Reordering: The cross-encoder model is used to score the semantic matching degree between candidate submission records and the current task, filtering out irrelevant entries and retaining the most relevant historical experience as a reference.

[0045] Step S23: Refine the sub-agent guidance.

[0046] Generate Tests and Checklists: The refining sub-agent receives retrieved historical successes, a description of the current task, and environmental feedback. Using the retrieved solutions as a reference, it generates test code and a checklist for the current task. The test code is used to reproduce the problem and verify the fix, while the checklist contains a series of constraints that need to be checked (such as project-specific coding standards).

[0047] Feedback loop: The main code agent generates code patches based on the requirements of the verification checklist. Subsequently, the system runs test code to verify the patches.

[0048] Iterative Correction: If a test fails or does not meet the list requirements, the execution result is fed back to the refining sub-agent. The refining sub-agent adjusts the test logic or updates the list based on the feedback, guiding the main agent to make the next round of modifications. This process constitutes a runtime self-correcting closed loop.

[0049] Step S24: Code Generation and Verification. After multiple rounds of self-correction, the main code agent outputs the final code. This code must pass automated testing and be finally submitted to the user for verification.

[0050] Step S25: Internalize experience.

[0051] Submission and Confirmation: Once the user confirms that the fix was successful, the code patch will be submitted to the code repository.

[0052] Closed-loop update: In the next phase one process, the newly generated and verified submission record is retrieved, processed again by the large language model into structured memory, and updated to the vector database.

[0053] Through this step, the agent transforms the successful code repair into a long-term memory, which can be retrieved and utilized in future tasks, thus achieving "human-machine co-evolution".

[0054] Through the above implementation methods, the present invention can enable the code agent to continuously adapt to the evolution of the project and improve its ability to solve complex engineering problems without changing the parameters of the large model, through structured external memory and dynamic correction mechanisms.

Claims

1. A method for the continuous evolution of a code-based intelligent agent based on structured memory, characterized in that, include: Memory construction steps: Obtain the historical commit records of the code repository, use a large language model to transform the historical commit records into structured memory entries, and build a vector database; Experience retrieval step: In response to the received code task instruction, retrieve historical memory entries related to the current task from the vector database according to the task instruction; Self-correction and execution steps: Using retrieved historical memory entries, test cases and verification lists are generated by refining sub-agents, which guide the main code agent to generate code patches and iteratively correct based on execution feedback; Experience internalization step: After the code patch is verified, the code patch and the corresponding task information are transformed into new structured memory entries and stored in the vector database.

2. The method according to claim 1, wherein the memory construction step specifically includes: Retrieve the original commit content and description from the code repository; The large language model is used to analyze it, extract and generate structured memory entries with six dimensions, namely: original commit information, code change content, functional keywords, formal description of the problem, root cause analysis and solution summary; The functional keywords and the formal description of the problem are then concatenated, encoded into a high-dimensional vector using an encoding model, and stored in a vector database.

3. The method according to claim 1, wherein the experience retrieval step specifically includes a two-stage retrieval process: Initial screening stage: Generate a query vector according to the task instructions, and use the approximate nearest neighbor search algorithm to retrieve a preset number of candidate memory entries from the vector database; Reordering stage: The semantic relevance between the task instruction and the candidate memory entries is scored using a cross-encoder model, and the final relevant historical memory entries are selected based on the scoring results.

4. The method according to claim 1, wherein the workflow of the refined sub-agent in the self-correction and execution step includes: Based on the task instructions given by the main intelligent agent and the retrieved relevant historical memory entries, test cases are generated to reproduce the problem. Based on the resolution strategies in the relevant historical memory entries, a checklist containing verification logic is constructed; The test cases and the checklist are provided as feedback signals to the main code agent.

5. The method according to claim 1, wherein the experience internalization step specifically includes: Pull new commit records containing the code patch from the code repository, and use a large language model to extract new structured memories from the new commit records.