A text2sql-oriented multi-agent model self-evolution method

By using a closed-loop self-evolutionary framework based on multi-agent collaboration, samples are dynamically generated and evaluated, solving the problems of insufficient performance and high training data cost of Text-to-SQL models in complex query scenarios, and realizing continuous optimization and long-term adaptive improvement of the model.

CN121501816BActive Publication Date: 2026-05-01UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
UNIV OF ELECTRONICS SCI & TECH OF CHINA
Filing Date
2025-10-23
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Existing Text-to-SQL models are inadequate in complex query scenarios, have high training data costs, and lack continuous optimization capabilities.

Method used

A closed-loop self-evolutionary framework with multi-agent collaboration as its core is adopted. Through dynamic sampling, generation and verification of high-quality samples, combined with training and updating, a continuous optimization mechanism is formed, including sampling scheduling, generation, evaluation and training update steps. The data sampling is optimized by using large language model priors and Bandit mechanism.

Benefits of technology

It improves the model's parsing accuracy, generalization ability, and robustness in complex database query scenarios, and achieves continuous optimization and long-term adaptability of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121501816B_ABST
    Figure CN121501816B_ABST
Patent Text Reader

Abstract

The application provides a multi-agent model self-evolution method for Text2SQL, a core agent receives evaluation results from a training and evaluation module, dynamically adjusts data sampling ratios in a two-dimensional fine-grained sampling space constituted by structured query language (SQL) difficulty and problem style, generates an agent to generate candidate samples composed of natural language questions, SQL statements and reasoning chains according to the data sampling ratios and database modes, a judgment agent performs multi-dimensional checking on the candidate samples, qualified samples are stored in a SQL data pool, the training and evaluation module samples data from the SQL data pool, trains and updates current Text2SQL model parameters, and feeds back evaluation results to the core agent to form a closed-loop self-evolution framework. The application proposes a fine-grained target-oriented evolution optimization strategy, effectively overcomes problems such as data generation staticization, training scheduling roughness and model evolution limitation of existing Text-to-SQL technologies, and has outstanding technological progress and application value.
Need to check novelty before this filing date? Find Prior Art

Description

A self-evolutionary method for multi-agent models in Text2SQL Technical Field

[0001] This invention belongs to the field of natural language processing and database interaction technology, specifically focusing on the self-evolution technology of multi-agent models from text to structured query language (Text-to-SQL). Background Technology

[0002] Text-to-SQL (Text2SQL) technology aims to automatically convert natural language questions into structured query language (SQL) statements, enabling users to interact directly with databases through natural language. This technology significantly lowers the barrier to entry for non-professionals to access and use databases, and has broad application prospects in business intelligence, data analysis, and various information systems. In recent years, with the development of large-scale pre-trained language models (LLMs), Text-to-SQL models have made significant progress on several public benchmark datasets. For example, on relatively medium-sized benchmarks such as Spider 1.0, some models have achieved high accuracy levels. However, real-world databases typically have more complex schemas, and queries involve complex nesting, multi-table joins, and multi-step inference. Existing models still fall short in the performance of these tasks. For instance, on the more complex Spider 2.0 dataset, the query execution accuracy of mainstream models is still less than 20%, indicating that existing technologies have significant limitations in handling complex schemas, diverse SQL dialects, and long inference chains.

[0003] To address these shortcomings, existing research has gradually introduced agent mechanisms, enabling models to decompose tasks, invoke tools, and perform interactive verification during the inference process. Existing methods have shown that by leveraging a multi-agent framework that combines inference and execution, models can improve the parsing performance of complex queries to some extent. For example, using the inference-action ReAct paradigm, the model can generate inference steps while simultaneously invoking database interfaces for intermediate verification, thereby reducing error accumulation. Another example is the recently proposed multi-agent collaborative framework MAC-SQL, which decomposes complex queries into several sub-tasks, with different types of agents responsible for decomposition, repair, and verification respectively. This successfully improved the execution accuracy of GPT-4 on the benchmark BIRD dataset for relational database instructions, achieving a new performance level. These advances demonstrate that multi-agent architectures can help alleviate some of the challenges in complex Text-to-SQL tasks. However, these methods share a common characteristic: they remain focused on optimization during the inference phase, essentially relying on static model parameters and lacking the ability to continuously evolve through feedback-driven long-term interactions. Therefore, even if they improve the parsing performance of complex queries in the short term, their performance will still rapidly decline when encountering new patterns and complex problems.

[0004] On the other hand, training high-performance Text-to-SQL models requires a large amount of manually annotated natural language and SQL correspondence data. However, such annotation processes are highly specialized and costly, making it difficult to meet the needs of complex and diverse tasks. Although some studies in recent years have alleviated the data scarcity problem by expanding the training corpus through self-play or data synthesis, these methods are often one-off preprocessing processes and have failed to form a closed-loop continuous optimization. Summary of the Invention

[0005] The technical problem to be solved by this invention is to address the issues of high cost of training data construction, insufficient model performance in complex query scenarios, and lack of continuous optimization capabilities in existing technologies. This invention provides a solution that can dynamically generate data, provide real-time evaluation feedback, and combine training updates during the training and use of text-to-structured query language conversion, thereby achieving self-evolution of the Text2SQL model.

[0006] The technical solution adopted by this invention to solve the above-mentioned technical problems is a self-evolutionary method for multi-agent models in Text2SQL, based on a closed-loop self-evolutionary framework with multi-agent collaboration as its core. This framework can dynamically sample, generate, and validate high-quality samples during the iteration process and use them for continuous training, thereby improving the model's parsing accuracy, generalization ability, and robustness. The method includes the following steps:

[0007] Sampling scheduling steps: The core agent receives the evaluation results from the training and evaluation module. Based on the evaluation results, combined with the prior distribution of the large language model and the Bandit mechanism of the multi-armed gambling machine, it dynamically adjusts the data sampling ratio in the two-dimensional fine-grained sampling space composed of the difficulty and question style of the structured query language SQL.

[0008] Generation steps: The generating agent generates candidate samples consisting of natural language questions, SQL statements, and inference chains based on the data sampling ratio and database pattern;

[0009] Evaluation steps: The evaluation agent performs multi-dimensional verification on the candidate samples, and qualified samples are stored in the SQL data pool;

[0010] Training and update steps: The training and evaluation module samples data from the SQL data pool, trains the current Text2SQL model parameters, updates the Text2SQL model parameters, and feeds back the evaluation results of the trained Text2SQL model on the benchmark task set to the core agent;

[0011] By iteratively executing the above steps, a closed-loop self-evolutionary framework is formed, enabling continuous optimization of the Text2SQL model.

[0012] The present invention achieves the above objectives through the following technical solutions:

[0013] First, the closed-loop self-evolution mechanism proposed in this invention realizes a complete feedback loop from data sampling, sample generation, result evaluation to training updates. This mechanism can continuously iterate and optimize in practical use, no longer relying on a statically constructed training dataset, thereby improving the model's long-term adaptability and performance retention in complex database query scenarios.

[0014] Secondly, this invention introduces an adaptive mechanism combining large language model priors with the Bandit algorithm for bias correction in the sampling scheduling stage. This mechanism can dynamically adjust the sampling probability based on the evaluation feedback results, so that the distribution of training samples is automatically optimized as the model becomes deficient. This avoids the limitations of relying solely on heuristic rules and balances exploration and utilization, thereby significantly improving the targeting and efficiency of the training process.

[0015] Furthermore, this invention designs an integrated framework for multi-agent collaborative data generation and evaluation. The generating agent and the evaluating agent collaborate under the coordination of the core agent: the former provides multi-dimensional and diverse SQL, natural language questions, and inference chain samples, while the latter combines rule verification and agent discrimination to achieve multi-level quality control. This integrated mechanism ensures that the samples entering the data pool possess both diversity and reliability, improving the quality of training data from the source.

[0016] Finally, this invention proposes a fine-grained, goal-oriented evolutionary optimization strategy. By constructing a two-dimensional matrix of SQL difficulty and question style, and dynamically adjusting the sampling ratio within this space, the system can target and strengthen the weaknesses of the model in specific dimensions. This refined evolutionary strategy not only improves the overall performance of the model but also achieves significant improvements in complexity grading and semantic style diversity.

[0017] The beneficial effects of this invention are that it forms a mutually reinforcing overall closed loop in terms of data acquisition, quality control, and training optimization, which can effectively overcome the problems of static data generation, coarse training scheduling, and limited model evolution in existing Text-to-SQL technologies, and has outstanding technological progress and application value. Attached Figure Description

[0018] Figure 1 is an overview framework diagram of a self-evolution method for a multi-agent model oriented to Text2SQL in an embodiment of this application;

[0019] Figure 2 is a flowchart of the self-evolution process for Text2SQL in the embodiments of this application. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present 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 the present invention. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.

[0021] As shown in Figure 1, the system of this invention consists of a core agent, a generator agent, a critic agent, an SQL pool, and a training and evaluation module. The candidate sample is a structured data packet containing all the information needed to solve the problem, including the natural language question input by the system, the SQL code output by the system, and the inference chain. The right side of Figure 1 shows the fine-grained space of the training objective, namely the sampling space, which is the space formed by the Cartesian product of SQL difficulty (SQL) and question style (Question).

[0022] SQL difficulty levels include {basic, standard, advanced, and expert}.

[0023] Question styles include {plain, casual, directive, inquiry, brief, ambiguous, interactive, and detailed}.

[0024] That is, the sampling space is determined by the SQL difficulty. With question style Construct a two-dimensional matrix :

[0025]

[0026]

[0027] ;

[0028] The fine-grained space consists of 32 cells, and one dimension of the fine-grained space is... . , This is the index value of the cell in the fine-grained space. , , This indicates the number of items to be selected.

[0029] During the sampling and scheduling phase, the core agent used to determine the evolutionary goal receives the evaluation results (Score) output from the training and evaluation module (Train & Eval) and dynamically adjusts the sampling ratio (DataProportion) based on the evaluation results.

[0030] During the generation phase, the generator agent is guided by the sampling ratio to generate candidate samples consisting of questions, SQL, and inference chains under the constraints of the database schema. .

[0031] During the evaluation phase, after the candidate samples are verified by the Critic Agent, the qualified ones are stored in the SQL Pool.

[0032] During the training and update phases, the SQL data pool is used by the training and evaluation module (Train & Eval) to perform supervised fine-tuning of SFT and in-group ranking preference optimization GRPO training. Finally, the evaluation results (Score) are fed back to the core agent through static benchmark evaluation, thus forming a closed-loop iteration.

[0033] In the In each iteration, the model parameters are denoted as The SQL queue in the SQL data pool is denoted as The self-evolutionary process can be formally represented as:

[0034] ;

[0035] in, This represents the function for generating intelligent agents. This represents the function that evaluates the agent's processing. This indicates the sample selection and update mechanism. This represents the training update function.

[0036] During the sampling and scheduling phase, the core agent determines different cells in the fine-grained space by combining the prior distribution of the large language model with the online feedback of the multi-armed gambling Bandit mechanism. sampling probability The Bandit mechanism, as an online learning method, dynamically corrects the data sampling distribution across different dimensions by balancing exploration and exploitation.

[0037] No. The probability distribution formula for each iteration is:

[0038] ;

[0039] in, This indicates that the cell is obtained through LLM inference from a large language model. Prior preferences, superscript Indicates the first Round iteration, For the first Round-Iterative Bandit Mechanism for Estimating Cells The reward value, and These are all index values ​​of cells in a fine-grained space. This represents the index value of a specific cell. This represents the index value of each cell in the fine-grained space. The weighting factor is exp, which is an exponential function with the natural constant as its base. The Bandit reward value is expressed in the form of an upper confidence bound:

[0040] ;

[0041] in, For the first Wheel of cells Historical average returns For the first Wheel of cells Number of times sampled, To control the exploration intensity, ln is the natural logarithm. This mechanism ensures that while utilizing historically high-yield dimensions, exploration of uncertain dimensions is preserved, thus achieving robust adaptive scheduling.

[0042] In the generation phase, the generator agent, based on the model parameters... and sampling space Generates natural language questions, SQL, and inference chains. The generating agent is completed collaboratively by four sub-agents:

[0043] The SQL generation sub-agent generates SQL based on the database schema and the sampling target, denoted as... ;

[0044] The question-generating sub-agent generates multi-style natural language questions based on SQL, denoted as... It covers a variety of styles;

[0045] The reasoning-generating sub-agent constructs a logical chain from the natural language problem to SQL, i.e., the initial reasoning chain. ;

[0046] The sub-agent is rewritten and optimized to rewrite the inference chain in order to enhance the diversity of language and logic.

[0047] The generation result output by the Generator Agent is represented as follows:

[0048] ;

[0049] in For natural language problems, For SQL, To rewrite the reasoning chain, rewrite the function. Processed inference chain .

[0050] Candidate samples then enter the evaluation phase. The Critic Agent is responsible for performing multi-dimensional verification of the candidate samples and conducting a comprehensive evaluation based on the agent's own discriminative capabilities. The Critic Agent includes an SQL Critic Agent, a Question Critic Agent, and an Inference Chain Critic Agent.

[0051] The SQL evaluation sub-agent is used to check the syntax and executability of SQL statements. The processing... Represented as:

[0052] ;

[0053] in, It is a consistency indicator function, taking the value 1 if and only if the condition in parentheses is true. It is a weighting coefficient used to balance the importance of executability.

[0054] The question judging sub-agent is used to map all candidate natural language questions to a vector space and calculate similarity scores. Then, the final problem samples are selected using voting / maximum similarity. .

[0055] ;

[0056] in, It is a set of candidate natural language questions. and Both indicate natural language issues. It is the embedding function.

[0057] The one with the highest score was ultimately selected. .

[0058] The inference chain judging sub-agent is used to execute the inference chain and employs a result-oriented majority voting mechanism. This involves executing SQL generated by different inference chains, comparing the consistency of the database execution results, and considering a chain valid when a majority of paths yield the same result. One of these chains is then randomly selected as the final inference chain. Let the first... During the round of iteration, the intelligent agent output is generated. A number of candidate inference chains are identified, and under the constraints of natural language problems and database schemas, the inference chains are utilized. Generate candidate SQL:

[0059] ;

[0060] in, For the execution result, Candidate SQL, For database schema, The processing function for generating sub-intelligent agents from SQL. Execute functions for the database. To query the database.

[0061] Set of execution results Clustered into several clusters based on execution results The results within each cluster are completely consistent. The cluster number is used. The cluster with the largest number of samples is selected. :

[0062] ;

[0063] From the first One inference chain is randomly selected uniformly from the cluster, and the inference chain number is... This determines the final accepted generated sample. :

[0064] ;

[0065] In addition to the majority voting mechanism mentioned above, the judging agent can also invoke the discrimination function of the large language model itself. To enhance the robustness of the evaluation, the boundary samples are evaluated as an auxiliary measure.

[0066] The generated samples that pass the evaluation are stored in the SQL data pool. The SQL data pool is designed with a fixed capacity of K, and the SQL queue in the SQL data pool is updated according to a first-in, first-out (FIFO) rule. Perform iterative updates:

[0067] ;

[0068] in, This represents newly generated and validated samples. To avoid redundancy, the data pool performs deduplication and consistency filtering during updates to ensure sample quality and timeliness.

[0069] During the training phase, data is extracted from the SQL data pool according to the sampling ratio of the core agents to ensure coverage of difficulty and style.

[0070] During the training and update phases, this invention first performs supervised fine-tuning of the SFT on the model, and then introduces a reward-based optimization GRPO. Reward function Defined as:

[0071] ;

[0072] in, The weighting coefficients prioritize consistency over structural similarity. For SQL used as a label, For the generated SQL, ASTSim represents the structural similarity of the abstract syntax tree. The final model update formula is:

[0073] ;

[0074] in, For the first Model parameters during round iterations, Expressing expectations, For a model with parameter set to M, input The target SQL is generated at that time. The conditional probability, express and From the The SQL queue during round iterations. It can be seen that the model maximizes the conditional probability while utilizing the reward function. It improved the accuracy of execution and the rationality of the structure.

[0075] As shown in Figure 2, the entire self-evolutionary process of data generation is formally described as the process in the first... During the round of iteration, the task set is obtained through database queries (Task DB Query). After the SQL generation process (SolutionGenerate SQL), SQL and an inference chain are generated, and the execution result of the inference chain is recorded as... Feedback is obtained through the execution and verification feedback process. These data Data augmentation transforms the samples into new training samples. This data is then written to the SQL data pool for model updates. After this round, the model is... Updated to And new performance metrics are obtained through evaluation on a benchmark task set. The evolutionary target is defined as:

[0076] ;

[0077] in, This indicates areas for improvement in Text2SQL capabilities, such as the correctness of SQL generation and the rationality of the reasoning chain. This indicates multi-dimensional optimization directions, corresponding to a fine-grained space of SQL difficulty and problem style. This definition ensures that the present invention not only optimizes overall performance but also specifically addresses model deficiencies in particular dimensions. The entire process thus forms a closed loop of "task evolution—data generation—data augmentation—model update—evaluation feedback."

[0078] In summary, this invention, combining Figures 1 and 2, demonstrates how to introduce a self-evolutionary mechanism into the Text2SQL task from two aspects: system architecture and process iteration. The core innovation lies in defining the evolutionary objective through a mathematical formula. The invention clarifies the dual optimization directions of capability and dimension; achieves dynamic adaptation through sampling scheduling that integrates prior knowledge and Bandit; constructs a high-quality SQLPool through multi-agent collaborative generation and evaluation; and ensures continuous performance improvement through joint training of SFT and GRPO. Those skilled in the art can clearly reproduce the invention based on this, and make equivalent substitutions or extensions without departing from the spirit of the invention.

[0079] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications 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 the present invention.

[0080] The above descriptions are merely some embodiments of the present invention. Those skilled in the art can make various modifications and improvements without departing from the inventive concept of the present invention, and these all fall within the scope of protection of the present invention.

Claims

1. A self-evolutionary method for multi-agent models oriented towards Text2SQL, characterized in that, Includes the following steps: Sampling and scheduling steps: The core agent receives the evaluation results from the training and evaluation modules. Based on the evaluation results, and combining the prior distribution of the large language model with the Bandit mechanism of the multi-armed gambling machine, it dynamically adjusts the data sampling ratio in the two-dimensional fine-grained sampling space composed of the difficulty and question style of the structured query language SQL. Generation steps: The generation agent generates candidate samples composed of natural language questions, SQL statements and inference chains according to the data sampling ratio and database mode. Evaluation steps: The evaluation agent performs multi-dimensional verification on the candidate samples, and qualified samples are stored in the SQL data pool; Training and Update Steps: The training and evaluation module samples data from the SQL data pool, trains the current Text2SQL model parameters, updates the Text2SQL model parameters, and feeds back the evaluation results of the trained Text2SQL model on the benchmark task set to the core agent. By iteratively executing the above steps, a closed-loop self-evolutionary framework is formed to achieve continuous optimization of the Text2SQL model. The generation agent includes an SQL generation sub-agent, a question generation sub-agent, an inference generation sub-agent, and a rewrite optimization sub-agent. The generation steps are as follows: the SQL generation sub-agent generates SQL statements corresponding to the sampling target based on the database pattern; the question generation sub-agent generates natural language questions covering multiple styles based on the SQL statements; the inference generation sub-agent constructs a sequence from the natural language questions to the core agent. The initial inference chain of the SQL statement; the rewriting and optimization sub-agent rewrites the initial inference chain to enhance the diversity of language and logic; the judging agent includes an SQL judging sub-agent, a question judging sub-agent, and an inference chain judging sub-agent; the judging steps are as follows: the SQL judging sub-agent checks the syntactic correctness and executability of the SQL statement; the question judging sub-agent maps all candidate natural language questions to a vector space, and selects the final natural language question sample by voting through cosine similarity calculation; the inference chain judging sub-agent executes the SQL statements generated by different candidate inference chains, and selects the valid inference chain by comparing the consistency of the database execution results and using a majority voting mechanism; the specific implementation method of the core agent dynamically adjusting the data sampling ratio is as follows: calculate the sampling probability of each cell in the fine-grained sampling space according to the following formula. : ;in This indicates that the cell is obtained through LLM inference from a large language model. The prior distribution, superscript Indicates the first Round iteration, For the first Round-Iterative Bandit Mechanism for Estimating Cells The reward value, and These are all index values ​​of cells in a fine-grained space. This represents the index value of a specific cell. This represents the index value of each cell in the fine-grained space. All are tradeoff coefficients, and exp is an exponential function with the natural constant as its base.

2. The method as described in claim 1, characterized in that, Bandit reward values ​​are expressed in the form of upper confidence bounds: ;in, For the first Wheel of cells Historical average returns For the first Wheel of cells Number of times sampled, The constant used to control the intensity of the exploration is ln, which is the natural logarithm.

3. The method as described in claim 1, characterized in that, The specific process of the majority voting mechanism used by the evaluation sub-agent in the inference chain is as follows: [The process is repeated in the first...] Generated in round iteration Candidate inference chain Under the constraints of natural language processing and database schema, candidate SQL queries are generated and executed, resulting in a set of execution results { }; the set of execution results { Clustered into several groups based on the principle of completely consistent execution results. }; Select the cluster with the largest number of samples And randomly select a sequence number from the cluster. chain of reasoning This determines the final accepted generated sample. , For natural language problems, For the reasoning chain The corresponding SQL statement.

4. The method as described in claim 1, characterized in that, In the training and update steps, the training and evaluation module samples data from the SQL data pool, performs supervised fine-tuning of the SFT and in-group ranking preference optimization (GRPO) training on the current Text2SQL model parameters, and updates the Text2SQL model parameters.

5. The method as described in claim 1, characterized in that, The self-evolutionary objective is defined as: ;in, This indicates the direction for improving Text2SQL capabilities. This indicates multi-dimensional optimization directions within a fine-grained space comprised of SQL difficulty and problem style.

6. The method as described in claim 1, characterized in that, SQL difficulty and question style Two-dimensional fine-grained sampling space Specifically: SQL difficulty ={basic, standard, advanced, expert}; Problem style ={plain, casual, directive, inquiry, brief, ambiguous, interactive, and detailed}; Among them, sampling space There are 32 cells in total. The index value of the cell. , , This indicates the number of items to be selected.

Citation Information

Patent Citations

  • Intelligent SQL query generation method and system based on large language model

    CN118861081A

  • Low-sample NL2SQL intelligent generation method and device

    CN120632074A