Code generation method and device based on multi-agent streaming collaboration, equipment and medium

By employing a multi-agent fluid collaboration approach, this method addresses the shortcomings of existing AI-assisted programming tools in terms of efficiency and accuracy in large-scale software engineering projects. It enables efficient and accurate code generation and testing, ensuring that the code conforms to project style and standards.

CN122152287APending Publication Date: 2026-06-05BEIJING PACTERA JINXIN TECH LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING PACTERA JINXIN TECH LTD
Filing Date
2026-02-26
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Existing AI-assisted programming tools suffer from several problems in large-scale, long-cycle, and highly constrained software engineering projects, including a lack of system-level architecture design capabilities, failure to maintain cross-module context consistency, mismatch between static models and dynamic project evolution, and low code reliability, resulting in insufficient code generation efficiency and accuracy.

Method used

A multi-agent streaming collaboration approach is adopted, which utilizes multiple agents to handle each stage through a streaming pipeline of requirements analysis, logic deduction, code generation, and test verification. These agents include a requirements analysis agent, a logic deduction agent, a code generation agent, and a test agent. A coordination and control engine coordinates and schedules the process to achieve the generation of structured requirements information, the verification of technical solution documents, the generation of source code, and the generation of test reports.

Benefits of technology

It improves the efficiency and accuracy of code generation, solves the problems of insufficient system-level architecture design capabilities and cross-module context consistency maintenance, ensures that the generated code conforms to the project style and passes testing, and realizes dynamic updates of project-specific knowledge and code reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122152287A_ABST
    Figure CN122152287A_ABST
Patent Text Reader

Abstract

The application provides a code generation method and device based on multi-agent streaming cooperation, equipment and medium, the code generation method comprises: under the unified scheduling of coordination control engine, based on demand analysis agent, the natural language description demand of the user is thought chain reasoning, and the structured demand information meeting the predefinition is generated; based on the logical deduction agent and the project context knowledge base, the structured demand information is processed to generate a technical scheme document that passes the verification; based on the code generation agent, the verified technical scheme document is combined with the coding specification knowledge base for retrieval processing to generate source code meeting the project style; based on the test agent, the source code is tested to generate a test report. Each link is independently executed by an agent, improving the efficiency and accuracy of code generation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of artificial intelligence and software engineering technology, and in particular to code generation methods, apparatus, devices and media based on multi-agent fluid collaboration. Background Technology

[0002] Current AI-assisted programming tools are primarily based on a single large language model (LLM), employing a paradigm of "prompt word engineering + context window retrieval," which performs well in tasks such as partial code completion and function generation. However, this paradigm suffers from the following significant and interconnected technical flaws in large-scale, long-cycle, and highly constrained software engineering projects, and these flaws cannot be fundamentally resolved by simply increasing the number of model parameters or extending the context window: 1. Lack of system-level architecture design capabilities: Existing tools lack the ability to formally model and reason about software engineering principles. 2. Failure to maintain cross-module context consistency: Limited by fixed-length context windows, existing systems struggle to establish semantic relationships across files and services within millions of lines of code. 3. Mismatch between static models and dynamic project evolution: LLMs become fixed after deployment and cannot continuously extract project-specific knowledge from subsequent developer code reviews, refactoring operations, or online monitoring alerts. This causes model suggestions to gradually deviate from the team's actual technology stack and coding standards as the project iterates, exhibiting a suggestion drift phenomenon. 4. Low code reliability: Due to noise in the model training data and the probability sampling mechanism, the generated code suffers from structural illusion. That is, it generates code that appears syntactically correct but violates business logic. Therefore, improving the efficiency and accuracy of code generation has become a significant technical challenge. Summary of the Invention

[0003] In view of this, the purpose of this application is to provide a code generation method, apparatus, device and medium based on multi-agent streaming collaboration, which uses multiple agents to conduct a streaming pipeline of "requirements analysis → logic derivation → code generation → test verification", so that each step is executed independently by the agent, thereby improving the efficiency and accuracy of code generation.

[0004] This application provides a code generation method based on multi-agent fluid collaboration, the code generation method comprising: Under the unified scheduling of the coordination and control engine, the demand analysis agent performs thought chain reasoning on the user's natural language description of demand, and generates structured demand information that conforms to the predefined structure. Based on the logical deduction intelligent agent and the project context knowledge base, the structured requirement information is processed to generate a technical solution document. The technical solution document is then subjected to dynamic simulation and deduction to generate a verified technical solution document. The code generation agent retrieves and processes verified technical solution documents in conjunction with a coding standard knowledge base to generate source code that conforms to the project style. The source code is tested based on the test agent, and a test report is generated that includes the test pass rate, code coverage, performance benchmark data, and root cause diagnosis conclusions located to specific lines of code. The data flow between the agents forms a directed acyclic graph topology, the main data flow direction is a unidirectional sequential processing path, and the feedback data flow path is triggered by the coordination control engine based on the real-time calculation results of the quality gating threshold.

[0005] In one possible implementation, the step of performing thought chain reasoning on the user's natural language description of needs based on the unified scheduling of the coordination and control engine, and generating structured demand information that conforms to predefined definitions, includes: Call the large language model service interface, input prompt words containing the thought chain reasoning template into the large language model of the requirement analysis agent, perform logical processing on the natural language description requirement based on the prompt words, and generate preliminary requirement deduction results; The preliminary requirements deduction results are input into a custom structured output parser for parsing and processing to generate predefined structured requirements information.

[0006] In one possible implementation, the step of logically processing the natural language description requirement based on the prompt words to generate a preliminary requirement deduction result includes: Identify the core business objectives in the natural language description requirements, and break down the core business objectives into a list of functional requirements; Extract non-functional requirement constraints and associate them with standardized quantitative indicators stored in the domain model knowledge base; Simultaneously, based on the natural language description requirements, a semantic query is initiated to the domain model knowledge base to determine the semantic query results. The structured and cleaned semantic query results are then injected into the prompt words of the large language model to guide the large language model to generate preliminary requirement deduction results that conform to the domain specifications.

[0007] In one possible implementation, the step of generating a technical solution document from the structured requirement information based on the logical deduction agent and the project context knowledge base, and then performing dynamic simulation and deduction processing on the technical solution document to generate a verified technical solution document includes: Based on the context request of the logically deduced agent, context joint retrieval and aggregation processing are performed in the project context knowledge base to generate structured context information; Based on the logical deduction, the intelligent agent processes the structured context information and structured requirement information to generate a technical solution document; The technical solution document is sent into a secure sandbox environment and simulated using symbolic execution tools or unit testing frameworks to verify the logical feasibility. If the verification fails, the technical solution document will be revised; if the verification passes, the verified technical solution document will be identified.

[0008] In one possible implementation, the code generation agent retrieves and processes verified technical solution documents in conjunction with a coding style knowledge base to generate source code that conforms to the project style, including: Based on the code generation agent, keywords are extracted from the verified technical solution documents, and the coding specification knowledge base is searched based on the keywords to determine the set of specification fragments; The code generation agent processes the verified technical solution documents, the keywords, and the set of specification fragments to generate source code that conforms to the project style.

[0009] In one possible implementation, after the source code is tested based on a test agent to generate a test report containing test pass rate, code coverage, performance benchmark data, and root cause diagnostic conclusions pinpointing specific lines of code, the code generation method further includes: If the defect density in the test report is higher than the first preset threshold, the optimization and refactoring agent is triggered, and the optimization and refactoring agent is controlled to call the static code analysis tool to scan the source code, generate refactoring suggestions based on the preset optimization rule base, and output the optimized source code. If the logic error rate in the test report is higher than the second preset threshold, then new source code is regenerated based on the code generation agent.

[0010] In one possible implementation, the demand analysis agent, the logic deduction agent, the code generation agent, and the testing agent are instantiated using large language models with different architectures, different training corpora, or different fine-tuning targets.

[0011] This application embodiment also provides a code generation device based on multi-agent streaming collaboration, the code generation device comprising: The requirements analysis module is used to perform thought chain reasoning on the user's natural language description requirements based on the requirements analysis intelligent agent under the unified scheduling of the coordination and control engine, and generate structured requirements information that conforms to predefined definitions. The logic deduction module is used to perform technical solution generation and dynamic simulation deduction on the structured requirement information based on the logic deduction intelligent agent and the project context knowledge base, and generate a verified technical solution document. The generation module is used to retrieve and process verified technical solution documents and coding standard knowledge base based on the code generation agent to generate source code that conforms to the project style. The testing module is used to test the source code based on the testing agent and generate a test report containing test pass rate, code coverage, performance benchmark data and root cause diagnosis conclusions located to specific lines of code. The data flow between the agents forms a directed acyclic graph topology, the main data flow direction is a unidirectional sequential processing path, and the feedback data flow path is triggered by the coordination control engine based on the real-time calculation results of the quality gating threshold.

[0012] This application also provides an electronic device, including: a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, the steps of the code generation method based on multi-agent streaming cooperation described above are performed.

[0013] This application also provides a computer-readable storage medium storing a computer program, which, when run by a processor, executes the steps of the code generation method based on multi-agent streaming cooperation described above.

[0014] This application provides a code generation method, apparatus, device, and medium based on multi-agent streaming collaboration. The code generation method includes: under the unified scheduling of a coordination control engine, a requirements analysis agent performs thought chain reasoning on the user's natural language description requirements to generate predefined structured requirements information; a logic deduction agent and a project context knowledge base perform technical solution generation processing on the structured requirements information to obtain a technical solution document; the technical solution document is then dynamically simulated and deduced to generate a verified technical solution document; a code generation agent performs retrieval processing on the verified technical solution document in conjunction with a coding standard knowledge base to generate source code that conforms to the project style; and a testing agent tests the source code to generate a test report containing test pass rate, code coverage, performance benchmark data, and root cause diagnosis conclusions pinpointing specific lines of code. The data flow between the agents constitutes a directed acyclic graph topology, with the main data flow direction being a unidirectional sequential processing path, and the feedback data flow path being triggered by the coordination control engine based on the real-time calculation results of a quality gating threshold. By using a streaming pipeline of multiple agents to work together to “requirements analysis → logic derivation → code generation → testing and verification”, each step is executed independently by the agent, improving the efficiency and accuracy of code generation.

[0015] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 A flowchart illustrating a code generation method based on multi-agent fluid collaboration provided in this application embodiment; Figure 2 This is one of the structural schematic diagrams of a code generation device based on multi-agent streaming collaboration provided in an embodiment of this application; Figure 3 This is a second schematic diagram of a code generation device based on multi-agent streaming collaboration provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0018] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of this application. Based on the embodiments of this application, every other embodiment obtained by those skilled in the art without inventive effort falls within the scope of protection of this application.

[0019] First, the applicable scenarios for this application will be introduced. This application can be applied to the fields of artificial intelligence and software engineering technology.

[0020] Based on this, this application provides a code generation method based on multi-agent streaming collaboration. By having multiple agents collaborate to perform a streaming pipeline of "requirements analysis → logic derivation → code generation → test verification", each step is executed independently by the agent, thereby improving the efficiency and accuracy of code generation.

[0021] Please see Figure 1 , Figure 1 A flowchart illustrating a code generation method based on multi-agent fluid collaboration provided in an embodiment of this application. Figure 1 As shown in the embodiments of this application, the code generation method includes: S101: Under the unified scheduling of the coordination and control engine, the demand analysis agent performs thought chain reasoning on the user's natural language description of demand to generate structured demand information that conforms to predefined rules.

[0022] In this step, the coordination and control engine, under unified scheduling, uses the demand analysis agent to perform thought chain reasoning on the user's natural language description of demand, and generates structured demand information that conforms to predefined requirements.

[0023] It should be noted that the coordination and control engine is responsible for instantiating predefined workflows and managing data flow and state synchronization between agents. Its core adaptive routing decision logic is implemented through the integrated rule engine Drools.

[0024] Here, natural language description of requirements refers to the information users need to provide for building the code. For example, "Please develop an interface for deducting product inventory for flash sales on an e-commerce platform, ensuring no overselling under high concurrency, and simultaneously supporting Redis caching and eventual consistency in MySQL." Structured requirement information includes a list of features, non-functional requirements (such as performance and security), and a preliminary breakdown of subtasks.

[0025] In one possible implementation, the step of performing thought chain reasoning on the user's natural language description of needs based on the unified scheduling of the coordination and control engine, and generating structured demand information that conforms to predefined definitions, includes: A: Call the large language model service interface, input prompt words containing the thought chain reasoning template into the large language model of the requirement analysis agent, perform logical processing on the natural language description requirement based on the prompt words, and generate preliminary requirement deduction results.

[0026] Here, the requirements analysis agent is developed based on the LangChain framework. Its core is to systematically process the natural language description requirements input by users by utilizing the prompt templates and chain structure provided by the framework. In specific implementation, the LangChain LLM module calls the domain-fine-tuned GPT-4 large language model service interface, and uses its thought chain capability to perform step-by-step decomposition and logical reasoning of complex requirements to generate preliminary requirements deduction results.

[0027] It should be noted that the thinking chain reasoning template includes identifying core business entities (such as products, inventory, and orders) and their key attributes; extracting explicit functional requirements (such as 'no overselling' → requiring distributed locks) and implicit non-functional requirements (such as 'high concurrency' → QPS ≥ 5000); and identifying technical constraints (such as 'compatible with Redis and MySQL' → requiring dual-write / eventual consistency design).

[0028] In one possible implementation, the step of logically processing the natural language description requirement based on the prompt words to generate a preliminary requirement deduction result includes: (1): Identify the core business objectives in the natural language description requirements, decompose the core business objectives into a list of functional requirements; extract non-functional requirement constraints and associate them with standardized quantitative indicators stored in the domain model knowledge base.

[0029] Here, lightweight dependency parsing (using the Spacyv3.7 Chinese model) is first performed on the natural language description requirements to generate core business objectives. After confirming the core business objectives, they are automatically decomposed according to the business capability hierarchy defined in the domain model knowledge base. The decomposition rules include: atomicity rule: each functional requirement must correspond to a single business verb + a single business object + a single business state (e.g., "logistics trajectory.state=update"); integrity rule: if the business verb is "alert", then three sub-requirements must be derived: "detection condition", "trigger threshold", and "notification channel"; consistency rule: the business object ID in all sub-requirements must exist in the domain model knowledge base nodes. Non-functional requirement keywords of the core business objectives (e.g., "real-time", "high concurrency", "no overselling") are identified through regular expression matching and semantic role labeling, and these non-functional requirement keywords are associated with standardized quantitative indicators stored in the domain model knowledge base.

[0030] (2): Simultaneously initiate semantic queries to the domain model knowledge base based on the natural language description requirements, determine the semantic query results, and inject the structured and cleaned semantic query results into the prompt words of the large language model to guide the large language model to generate preliminary requirement deduction results that conform to the domain specifications.

[0031] Here, multiple semantic query requests are initiated to the domain model knowledge base to determine the semantic query results. The structured and cleaned semantic query results are then injected into the prompt words of the large language model to guide the large language model to generate preliminary requirement deduction results that conform to the domain specifications.

[0032] It should be noted that the cleaned semantic query results are not inserted as independent text paragraphs with prompt words, but are precisely injected into the designated placeholders in the thought chain reasoning template.

[0033] Here, semantic query requests include domain concept consistency verification queries, business rule constraint queries, entity relationship path reasoning queries, and best practice pattern matching queries.

[0034] Among them, the domain model knowledge base takes knowledge graph as its core and models the concepts, rules and relationships of business domains (such as finance and e-commerce) as graph structures. The knowledge graph is constructed through the following steps: (1) extract entities and relationships from domain documents (requirements specifications, API documents, etc.) and use the NLP tool Spacy to perform entity recognition and relationship extraction; (2) store the structured data in the graph database Neo4j; (3) provide a graph query interface (Cypher query language) to support complex reasoning.

[0035] B: Input the preliminary requirements deduction results into a custom structured output parser for parsing and processing, and generate structured requirements information that conforms to the predefined requirements.

[0036] Here, a custom structured output parser is used to reduce the initial requirements deduction results to a predefined JSONSchema format, generating machine-readable structured requirements information, providing clear and structured input for subsequent intelligent agents.

[0037] It should be noted that the processing steps of the structured output parser include: checking text length, checking the basic structure, schema enforcement and field reduction, and semantic consistency cleaning.

[0038] S102: Based on the logical deduction intelligent agent and the project context knowledge base, perform technical solution generation and dynamic simulation processing on the structured requirement information to generate a verified technical solution document.

[0039] In this step, a logical deduction agent and a project context knowledge base are used to process the structured requirements information to generate technical solution documents. The technical solution documents are then subjected to dynamic simulation and deduction to generate verified technical solution documents.

[0040] It should be noted that the technical solution document includes the architecture diagram (such as UML), pseudocode of key algorithms, data structure design, etc.

[0041] The logic deduction agent is developed based on the Microsoft AutoGen framework, and its built-in components enable customized professional roles. A simulation deduction system was constructed, and a large language model is also set up internally for the logic deduction agent.

[0042] In one possible implementation, the step of generating a technical solution document from the structured requirement information based on the logical deduction agent and the project context knowledge base, and then performing dynamic simulation and deduction processing on the technical solution document to generate a verified technical solution document includes: a: Based on the logic, the context request of the intelligent agent is used to perform context joint retrieval and aggregation processing in the project context knowledge base to generate structured context information.

[0043] Here, the logic deduction agent initiates a context request to the project context knowledge base. The project context knowledge base includes: a dynamic context sub-base, stored in Redis containing the current task ID, user preference tags, and temporary variable key-value pairs; a coding standard knowledge base, storing project coding standard document fragments vectorized by the model; and a domain model knowledge base, built on the Neo4j graph database, storing business domain concepts, rules, and relation triples generated through entity relation extraction. The logic deduction agent invokes this knowledge base, synchronously retrieving the above three types of knowledge bases, and performs semantic alignment and structured aggregation on the returned heterogeneous context data to generate unified JSON structured context information.

[0044] b: Based on the logic deduction, the intelligent agent processes the structured context information and structured requirement information to generate a technical solution document.

[0045] Here, the logic deduction agent takes structured context information and structured requirement information as input, and generates a technical solution document based on its internal large language model. The technical solution document includes at least: UML class diagram / sequence diagram descriptions, pseudocode for key algorithms, definitions of core data structures, and API interface contracts.

[0046] c: The technical solution document is placed in a secure sandbox environment and simulated using symbolic execution tools or unit testing frameworks to verify its logical feasibility. If the verification fails, the technical solution document is revised; if the verification passes, the verified technical solution document is identified.

[0047] Here, the technical solution document is sent to a Docker containerized security sandbox environment. Within the sandbox, one of the following verification operations is performed: a symbolic execution tool is invoked to solve path constraints on the pseudocode, detecting unreachable branches, undefined behavior, or assertion failures; or a unit testing framework is invoked to automatically generate test stubs based on the API contracts defined in the technical solution, and perform lightweight functional verification. The execution results from the sandbox environment are returned to the logic derivation agent in the form of structured logs. If the structured logs indicate a logical defect, the logic derivation agent corrects the technical solution document based on the defect location information. If the structured logs indicate that all verification items pass, the current technical solution document is marked as a "verified technical solution document" and output to the coordination control engine, triggering the startup of the downstream code generation agent.

[0048] S103: The code generation agent retrieves and processes verified technical solution documents in conjunction with a coding standard knowledge base to generate source code that conforms to the project style.

[0049] In this step, the code generation agent retrieves and processes the verified technical solution documents in conjunction with the coding standard knowledge base to generate source code that conforms to the project style.

[0050] It should be noted that the generated source code is "domain-specific, project-specific, and context-specific" code that is user-specified for the business domain (such as finance or e-commerce), follows the project's established technology stack, and is deeply coupled with the current codebase architecture and coding standards.

[0051] In this application, the code generation agent deeply collaborates with verified technical solution documents and coding standard knowledge bases to generate source code that conforms to the project's specific style and can be directly integrated into the existing codebase. This process addresses the two core shortcomings pointed out in the background technology: "weak cross-module context awareness and consistency maintenance capabilities" and "low code reliability due to illusions." Instead of relying on the spontaneous style judgment of a large language model, it transforms abstract specifications into executable and verifiable code constraints through structured retrieval.

[0052] In one possible implementation, the code generation agent retrieves and processes verified technical solution documents in conjunction with a coding style knowledge base to generate source code that conforms to the project style, including: I: Based on the code generation agent, keywords are extracted from the verified technical solution documents, and the set of standard fragments is determined by searching the coding standard knowledge base based on the keywords.

[0053] Here, the validated technical solution document undergoes structured parsing to extract three types of semantic keywords: entity keywords: class names, interface names, and core business object names identified from UML class diagrams or pseudocode, extracted using the SpacyNLP tool as noun phrases; operation keywords: key action verbs extracted from verb phrases in the pseudocode; and constraint keywords: extracted from explicitly declared non-functional requirement fields in the technical solution document.

[0054] In this process, the three types of keywords are used as query vectors and input into the coding standard knowledge base to perform multi-vector hybrid retrieval, thereby determining the set of standard fragments.

[0055] It should be noted that the coding specification knowledge base is built based on the Retrieval Enhanced Generation (RAG) technology. By vectorizing the coding specification documents and storing them in a vector database, intelligent retrieval is supported. The specific process includes: (1) using the document parsing tool Apache Tika to convert the specification documents into plain text; (2) using LangChain's RecursiveCharacterTextSplitter to split the documents into paragraphs; (3) using OpenAI's text-embedding-3-small embedding model to generate vectors; and (4) storing them in the vector database and creating an index.

[0056] II: The code generation agent processes the verified technical solution document, the keywords, and the set of specification fragments to generate source code that conforms to the project style.

[0057] Here, the verified technical solution documents, keywords, and a set of specification fragments are injected into the prompt words and input into the finely tuned large language model service interface. The source code output by the code generation agent is then subjected to syntax and legality checks. Only when there are no compilation errors and the preset constraints are met is it marked as "source code that conforms to the project style" and output. Otherwise, a retry mechanism is triggered to regenerate the source code.

[0058] S104: Test the source code based on the test agent and generate a test report containing test pass rate, code coverage, performance benchmark data, and root cause diagnosis conclusions located to specific lines of code.

[0059] In this step, a test agent is used to test the source code and generate a test report that includes test pass rate, code coverage, performance benchmark data, and root cause diagnosis conclusions pinpointing specific lines of code.

[0060] The data flow between the agents forms a directed acyclic graph topology. The main data flow direction is a unidirectional sequential processing path, and the feedback data flow path is triggered by the coordination control engine based on the real-time calculation results of the quality gating threshold.

[0061] Here, the development of the test agent heavily relies on LangChain's tool invocation mechanism. This is achieved by encapsulating the APIs of the JUnit, Pytest, and Jest automated testing frameworks into standard LangChain Tool objects. After receiving the source code, the test agent uses LangChain's AgentExecutor and its underlying large language model to infer which testing tools need to be invoked and generate specific test execution instructions. The raw results returned by the test framework (such as error stack traces) are then processed by LangChain's OutputParser through structured parsing and pattern matching, transforming generalized error information into precise diagnostic conclusions pinpointing the code line and root cause, thus achieving intelligent error analysis and reporting.

[0062] The root cause localization process is as follows: S1. Perform pattern matching on the raw error logs output by the test framework to extract the exception type, file line number, and assertion expression; S2. Retrieve the associated source code, call chain, and historical repair patterns from the project context knowledge base based on the file line number; S3. Input the results of S1 and S2 into the finely tuned large language model to generate an attribution conclusion containing the `upstream_origin` field according to the preset JSON Schema; S4. Synchronously call the symbolic execution engine to automatically deduce the constraints that triggered the exception for the erroneous code segment; S5. When the information after constraint solving is consistent with the attribution conclusion, output the root cause diagnosis conclusion.

[0063] In one possible implementation, after the source code is tested based on a test agent to generate a test report containing test pass rate, code coverage, performance benchmark data, and root cause diagnostic conclusions pinpointing specific lines of code, the code generation method further includes: If the defect density in the test report is higher than the first preset threshold, the optimization and refactoring agent is triggered, which calls the static code analysis tool to scan the source code and generates refactoring suggestions based on the preset optimization rule base, outputting the optimized source code; if the logic error rate in the test report is higher than the second preset threshold, the new source code is regenerated based on the code generation agent.

[0064] Here, the optimization and refactoring agent is implemented through LangChain's Agent architecture. Its core is to encapsulate the scanning interfaces of static code analysis tools like SonarQube and ESLint into callable tools. Based on LLM's inference capabilities, the optimization and refactoring agent interprets the quality reports returned by the analysis tools and, according to a pre-built optimization rule base (such as design pattern application scenarios and performance optimization patterns), sequentially executes the "analysis-decision-refactoring" process through LangChain's Chain components. This optimization and refactoring agent can generate specific refactoring code suggestions and even directly apply refactoring operations, thereby achieving automated and intelligent continuous optimization of code quality.

[0065] The coordination and control engine incorporates an adaptive triggering mechanism. For example, when the defect rate reported by the test agent exceeds a threshold, the engine automatically triggers an optimization agent instead of simply reverting to the code generation agent, thus achieving "intelligent routing."

[0066] It should be noted that the optimization rule base stores decision metadata (such as task ID, agent type, input / output hashes), while the time series database records performance metrics (such as decision time and resource consumption). Simultaneously, historical data is analyzed using decision trees to generate optimization suggestions.

[0067] In one possible implementation, the demand analysis agent, the logic deduction agent, the code generation agent, and the testing agent are instantiated using large language models with different architectures, different training corpora, or different fine-tuning targets.

[0068] It should be noted that in the process of multiple intelligent agents cooperating in this application, the intelligent agent can directly receive the intermediate structural product output by the previous intelligent agent, or the coordination and control engine can send the intermediate structural product output by the previous intelligent agent to the intelligent agent. This part is not specifically limited.

[0069] In this application, a project context knowledge base is used to uniformly provide dynamic session context and static architectural constraints; a domain model knowledge base actively mines cross-service semantic dependency chains through entity relationship path reasoning queries; and a coding standard knowledge base, combined with vector retrieval and a rule engine (Drools), enforces style constraints such as naming conventions and exception handling patterns. These three elements work together to ensure that code generation, testing, and optimization are always anchored to the same semantic coordinate system. This achieves strong context awareness and logical consistency maintenance across modules and lifecycles, breaking through the limitations of the context window in traditional AI tools.

[0070] In a specific implementation, the coordination and control engine receives the user's natural language description of requirements, activates the requirements analysis agent, and uses the requirements analysis agent to output structured requirements information. The coordination and control engine persists this document to a knowledge base. The coordination and control engine then activates the logic deduction agent, which generates a technical solution based on the structured requirements information and performs simulated execution to verify the logical feasibility of the solution. It outputs a verified technical solution document, including architecture design, API interface definitions, and pseudocode for key algorithms. The code generation agent generates source code based on the verified technical solution document and project information (such as coding standards) obtained from the context manager. The testing agent performs comprehensive testing on the generated source code and generates a detailed test report. The coordination and control engine makes decisions based on the test report. If a performance bottleneck or a refactoring is required, the engine directly activates the optimization and refactoring agent; if a logical error or style issue is found, it reverts to the code generation agent. This "intelligent routing" mechanism is key to achieving efficient adaptive optimization. When the source code passes all tests or meets other termination conditions (such as reaching the maximum number of iterations), the process terminates and delivers the final code.

[0071] In this application, heterogeneous large language models are used to instantiate different types of agents, effectively avoiding the collective cognitive blind spots that homogeneous models may bring. The code generation task is decomposed into a sequential, phased pipeline (e.g., requirements analysis → verification → coding → testing). Before the code actually runs, the system verifies the logical feasibility through simulation and reverse reasoning, achieving "pre-emptive" debugging and identifying potential errors in advance. An automatic feedback loop based on quality gating thresholds (e.g., test pass rate) is established. When the output does not meet the standards, a specific agent (e.g., an optimization agent) is automatically triggered to make corrections, iterating multiple times until the termination condition is met. This allows the system to continuously learn and self-optimize as the project evolves.

[0072] This application provides a code generation method based on multi-agent streaming collaboration. The method includes: under the unified scheduling of a coordination control engine, a requirements analysis agent performs thought chain reasoning on the user's natural language description of requirements to generate predefined structured requirements information; a logic deduction agent and a project context knowledge base perform technical solution generation and dynamic simulation processing on the structured requirements information to generate a verified technical solution document; a code generation agent retrieves the verified technical solution document and combines it with a coding standard knowledge base to generate source code that conforms to the project style; and a testing agent tests the source code to generate a test report containing test pass rate, code coverage, performance benchmark data, and root cause diagnosis conclusions pinpointing specific lines of code. The data flow between the agents forms a directed acyclic graph topology, with the main data flow direction being a unidirectional sequential processing path, and the feedback data flow path being triggered by the coordination control engine based on real-time calculation results of quality gating thresholds. By using multiple agents to collaboratively execute a streaming pipeline of "requirements analysis → logic deduction → code generation → test verification," each step is executed independently by the agent, improving the efficiency and accuracy of code generation.

[0073] Please see Figure 2 , Figure 3 , Figure 2 This is one of the structural schematic diagrams of a code generation device based on multi-agent streaming collaboration provided in an embodiment of this application; Figure 3 This is a second schematic diagram of a code generation device based on multi-agent streaming collaboration provided in an embodiment of this application. Figure 2 As shown, the code generation device 200 includes: The requirements analysis module 210 is used to perform thought chain reasoning on the user's natural language description requirements based on the requirements analysis intelligent agent under the unified scheduling of the coordination and control engine, and generate structured requirements information that conforms to predefined requirements. The logic deduction module 220 is used to perform technical solution generation and dynamic simulation deduction processing on the structured requirement information based on the logic deduction intelligent agent and the project context knowledge base, and generate a verified technical solution document. The generation module 230 is used to retrieve and process the verified technical solution documents in conjunction with the coding standard knowledge base based on the code generation intelligent agent, and generate source code that conforms to the project style. The testing module 240 is used to test the source code based on the testing agent and generate a test report containing the test pass rate, code coverage, performance benchmark data and root cause diagnosis conclusions located to specific lines of code. The data flow between the agents forms a directed acyclic graph topology, the main data flow direction is a unidirectional sequential processing path, and the feedback data flow path is triggered by the coordination control engine based on the real-time calculation results of the quality gating threshold.

[0074] Furthermore, the requirements analysis module 210 is used to perform thought chain reasoning on the user's natural language description requirements based on the requirements analysis agent under the unified scheduling of the coordination and control engine, and generate structured requirements information that conforms to predefined definitions: Call the large language model service interface, input prompt words containing the thought chain reasoning template into the large language model of the requirement analysis agent, perform logical processing on the natural language description requirement based on the prompt words, and generate preliminary requirement deduction results; The preliminary requirements deduction results are input into a custom structured output parser for parsing and processing to generate predefined structured requirements information.

[0075] Furthermore, the requirements analysis module 210 is used to perform logical processing on the natural language description requirements based on the prompt words, and generate preliminary requirements deduction results: Identify the core business objectives in the natural language description requirements, and break down the core business objectives into a list of functional requirements; Extract non-functional requirement constraints and associate them with standardized quantitative indicators stored in the domain model knowledge base; Simultaneously, based on the natural language description requirements, a semantic query is initiated to the domain model knowledge base to determine the semantic query results. The structured and cleaned semantic query results are then injected into the prompt words of the large language model to guide the large language model to generate preliminary requirement deduction results that conform to the domain specifications.

[0076] Furthermore, the logic deduction module 220 is used to process the structured requirement information based on the logic deduction agent and the project context knowledge base to obtain a technical solution document, and to perform dynamic simulation and deduction processing on the technical solution document to generate a verified technical solution document. Based on the context request of the logically deduced agent, context joint retrieval and aggregation processing are performed in the project context knowledge base to generate structured context information; Based on the logical deduction, the intelligent agent processes the structured context information and structured requirement information to generate a technical solution document; The technical solution document is sent into a secure sandbox environment and simulated using symbolic execution tools or unit testing frameworks to verify the logical feasibility. If the verification fails, the technical solution document will be revised; if the verification passes, the verified technical solution document will be identified.

[0077] Furthermore, the generation module 230 is used by the code generation agent to retrieve and process the verified technical solution documents in conjunction with the coding standard knowledge base, and generate source code that conforms to the project style: Based on the code generation agent, keywords are extracted from the verified technical solution documents, and the coding specification knowledge base is searched based on the keywords to determine the set of specification fragments; The code generation agent processes the verified technical solution documents, the keywords, and the set of specification fragments to generate source code that conforms to the project style.

[0078] Furthermore, such as Figure 3 As shown, the code generation device 200 also includes an optimization module 250, which is used for: If the defect density in the test report is higher than the first preset threshold, the optimization and refactoring agent is triggered, and the optimization and refactoring agent is controlled to call the static code analysis tool to scan the source code, generate refactoring suggestions based on the preset optimization rule base, and output the optimized source code. If the logic error rate in the test report is higher than the second preset threshold, then new source code is regenerated based on the code generation agent.

[0079] This application provides a code generation device based on multi-agent streaming collaboration. The code generation device includes: a requirements analysis module, used to perform thought chain reasoning on the user's natural language description requirements based on the requirements analysis agent under the unified scheduling of the coordination control engine, and generate structured requirements information that conforms to predefined definitions; a logic deduction module, used to perform technical solution generation processing on the structured requirements information based on the logic deduction agent and the project context knowledge base to obtain a technical solution document, and perform dynamic simulation deduction processing on the technical solution document to generate a verified technical solution document; a generation module, used to perform retrieval processing on the verified technical solution document based on the code generation agent and the coding standard knowledge base, and generate source code that conforms to the project style; and a testing module, used to test the source code based on the testing agent, and generate a test report containing test pass rate, code coverage, performance benchmark data, and root cause diagnosis conclusions located to specific lines of code; wherein, the data flow between each agent constitutes a directed acyclic graph topology, the main data flow direction is a unidirectional sequential processing path, and the feedback data flow path is triggered by the coordination control engine based on the real-time calculation results of the quality gating threshold. By using a streaming pipeline of multiple agents to work together to “requirements analysis → logic derivation → code generation → testing and verification”, each step is executed independently by the agent, improving the efficiency and accuracy of code generation.

[0080] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 4 As shown, the electronic device 400 includes a processor 410, a memory 420, and a bus 430.

[0081] The memory 420 stores machine-readable instructions executable by the processor 410. When the electronic device 400 is running, the processor 410 communicates with the memory 420 via the bus 430. When the machine-readable instructions are executed by the processor 410, they can perform the operations described above. Figure 1 The steps of the code generation method based on multi-agent fluid collaboration in the method embodiment shown are described in detail in the method embodiment, and will not be repeated here.

[0082] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, can perform the above-described actions. Figure 1 The steps of the code generation method based on multi-agent fluid collaboration in the method embodiment shown are described in detail in the method embodiment, and will not be repeated here.

[0083] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0084] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the shown or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.

[0085] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0086] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0087] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0088] Finally, it should be noted that the above-described embodiments are merely specific implementations of this application, used to illustrate the technical solutions of this application, and not to limit them. The scope of protection of this application is not limited thereto. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this application. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A code generation method based on multi-agent fluid collaboration, characterized in that, The code generation method includes: Under the unified scheduling of the coordination and control engine, the demand analysis agent performs thought chain reasoning on the user's natural language description of demand, and generates structured demand information that conforms to the predefined structure. Based on the logical deduction intelligent agent and the project context knowledge base, the structured requirement information is processed to generate a technical solution document. The technical solution document is then subjected to dynamic simulation and deduction to generate a verified technical solution document. The code generation agent retrieves and processes verified technical solution documents in conjunction with a coding standard knowledge base to generate source code that conforms to the project style. The source code is tested based on the test agent, and a test report is generated that includes the test pass rate, code coverage, performance benchmark data, and root cause diagnosis conclusions located to specific lines of code. The data flow between the agents forms a directed acyclic graph topology, the main data flow direction is a unidirectional sequential processing path, and the feedback data flow path is triggered by the coordination control engine based on the real-time calculation results of the quality gating threshold.

2. The code generation method according to claim 1, characterized in that, The process, under the unified scheduling of the coordination and control engine, involves a demand analysis agent performing thought chain reasoning on the user's natural language description of their needs to generate predefined structured demand information, including: Call the large language model service interface, input prompt words containing the thought chain reasoning template into the large language model of the requirement analysis agent, perform logical processing on the natural language description requirement based on the prompt words, and generate preliminary requirement deduction results; The preliminary requirements deduction results are input into a custom structured output parser for parsing and processing to generate predefined structured requirements information.

3. The code generation method according to claim 2, characterized in that, The step of logically processing the natural language description requirement based on the prompt words to generate preliminary requirement deduction results includes: Identify the core business objectives in the natural language description requirements, and break down the core business objectives into a list of functional requirements; Extract non-functional requirement constraints and associate them with standardized quantitative indicators stored in the domain model knowledge base; Simultaneously, based on the natural language description requirements, a semantic query is initiated to the domain model knowledge base to determine the semantic query results. The structured and cleaned semantic query results are then injected into the prompt words of the large language model to guide the large language model to generate preliminary requirement deduction results that conform to the domain specifications.

4. The code generation method according to claim 1, characterized in that, The structured requirement information is processed by a logic-based intelligent agent and a project context knowledge base to generate a technical solution document. This document is then dynamically simulated and analyzed to generate a validated technical solution document, including: Based on the context request of the logically deduced agent, context joint retrieval and aggregation processing are performed in the project context knowledge base to generate structured context information; Based on the logical deduction, the intelligent agent processes the structured context information and structured requirement information to generate a technical solution document; The technical solution document is sent into a secure sandbox environment and simulated using symbolic execution tools or unit testing frameworks to verify the logical feasibility. If the verification fails, the technical solution document will be revised; if the verification passes, the verified technical solution document will be identified.

5. The code generation method according to claim 1, characterized in that, The code generation agent retrieves and processes verified technical solution documents using a coding standard knowledge base, generating source code that conforms to the project style, including: Based on the code generation agent, keywords are extracted from the verified technical solution documents, and the coding specification knowledge base is searched based on the keywords to determine the set of specification fragments; The code generation agent processes the verified technical solution documents, the keywords, and the set of specification fragments to generate source code that conforms to the project style.

6. The code generation method according to claim 1, characterized in that, After the source code is tested based on a test agent, and a test report is generated containing test pass rate, code coverage, performance benchmark data, and root cause diagnostic conclusions pinpointing specific lines of code, the code generation method further includes: If the defect density in the test report is higher than the first preset threshold, the optimization and refactoring agent is triggered, and the optimization and refactoring agent is controlled to call the static code analysis tool to scan the source code, generate refactoring suggestions based on the preset optimization rule base, and output the optimized source code. If the logic error rate in the test report is higher than the second preset threshold, then new source code is regenerated based on the code generation agent.

7. The code generation method according to claim 1, characterized in that, The demand analysis agent, the logic deduction agent, the code generation agent, and the testing agent are instantiated using large language models with different architectures, different training corpora, or different fine-tuning targets.

8. A code generation device based on multi-agent streaming collaboration, characterized in that, The code generation device includes: The requirements analysis module is used to perform thought chain reasoning on the user's natural language description requirements based on the requirements analysis intelligent agent under the unified scheduling of the coordination and control engine, and generate structured requirements information that conforms to predefined definitions. The logic deduction module is used to process the structured requirement information based on the logic deduction agent and the project context knowledge base to generate a technical solution document, and to perform dynamic simulation and deduction processing on the technical solution document to generate a verified technical solution document. The generation module is used to retrieve and process verified technical solution documents and coding standard knowledge base based on the code generation agent to generate source code that conforms to the project style. The testing module is used to test the source code based on the testing agent and generate a test report containing test pass rate, code coverage, performance benchmark data and root cause diagnosis conclusions located to specific lines of code. The data flow between the agents forms a directed acyclic graph topology, the main data flow direction is a unidirectional sequential processing path, and the feedback data flow path is triggered by the coordination control engine based on the real-time calculation results of the quality gating threshold.

9. An electronic device, characterized in that, include: The device includes a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the memory via the bus. The machine-readable instructions are executed by the processor to perform the steps of the code generation method based on multi-agent streaming collaboration as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the code generation method based on multi-agent streaming collaboration as described in any one of claims 1 to 7.