Database question and answer assistant construction method and system and central air conditioner display terminal
By using a structured task chain model and multi-agent collaborative execution, the problems of multi-step reasoning and SQL query errors in existing technologies are solved, achieving efficient and accurate responses to complex database queries and error self-healing capabilities.
Patent Information
- Application Number
- CN202511527973.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-24
- Publication Date
- 2026-02-03
AI Technical Summary
Existing technologies struggle to handle multi-step reasoning problems, making it difficult to map user questions to SQL that accurately meets business needs. This results in unreliable responses, and errors in SQL queries can lead to user questions remaining unanswered.
By adopting a structured task chain model, user questions are broken down into multiple sub-tasks through a task planning agent, and multi-agent collaborative execution is used to generate structured query statements and result aggregation, thereby automating the entire process from natural language input to task planning, database query, and structured business response.
It enables efficient and accurate solutions to complex data analysis problems, possesses error self-healing and multi-round interaction capabilities, and can generate accurate SQL query statements and reliable responses.
Smart Images

Figure CN121456089A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of intelligent agents, and particularly relates to a database question and answer assistant construction method and system and a central air conditioning display terminal. BACKGROUND
[0002] As a major part of building energy consumption, the central air conditioning system involves a large number of equipment types and complex operation data. With the improvement of building informatization level, more and more central air conditioning system operation data are accessed to the database for centralized management, and the central air conditioning cloud operation and maintenance platform is used for visual operation and maintenance management. At present, with the rapid development and wide application of large language models, integrating an AI question and answer assistant in the cloud operation and maintenance platform has become a common application means of large language models in the field of heating, ventilation and air conditioning.
[0003] However, when facing complex problems that need to be solved in multiple steps, the large language model may not be able to query effective data from the database according to the user's intention, and finally output an incorrect answer. In addition, when the user's question involves a large amount of data, if a large amount of data is directly called according to the user's intention, the large language model may report an error due to too much input data. Finally, there is a large semantic gap between natural language queries and database structures, and user questions are difficult to map to accurate SQL structured query statements that meet business requirements, and the generated SQL cannot be guaranteed to be completely correct, and query errors will result in the user's question being unable to be answered. Traditional database question and answer systems lack effective automatic parsing, scheduling and multi-step calculation capabilities, and cannot quickly extract valuable information from the database, resulting in the situation of "having data but not using it" and "using it but not being accurate".
[0004] The existing technology usually focuses on the design of intelligent question and answer processes in general fields, and the core is semantic understanding and knowledge retrieval driven by large language models; and cannot perform task decomposition, so it is difficult to handle problems requiring multi-step reasoning.
[0005] An intelligent question and answer method in the prior art includes (1) a large language model analyzes the semantic of a user question, calculates the matching degree with a report theme, and dynamically selects a question correction or report generation process; (2) a domain knowledge base is used to convert a fuzzy query into a deterministic request to eliminate semantic ambiguity; (3) database metadata is parsed to analyze field association, and executable SQL is generated; (4) SQL is dynamically rewritten according to user roles to add permission filtering conditions, and the query is executed and sensitive data is desensitized; (5) the characteristics of the analysis results are analyzed, a visual form is automatically matched, and a natural language explanation is generated; and (6) user feedback is collected to optimize the semantic model and query strategy. However, this method only handles single-step queries, and it is difficult to handle problems requiring multi-step reasoning.
[0006] Another existing intelligent question-answering method includes: constructing a CoTSQL model for table-based question answering based on thought chains and a frame extraction model; an example filtering module generates an SQL framework architecture for natural language questions through the frame extraction model, and selects examples similar to the target question based on the frame category using a filtering algorithm; a pattern processing module performs pattern linking, extracts key table information and pattern relationships, and provides a contextual environment; a prompt construction module integrates the filtered examples and processed pattern information into CoTSQL-style prompts, inputs them into a large language model to generate a preliminary SQL query; and an SQL correction module detects and corrects illusion errors generated by the large language model through SQL repair and consistency strategies, executes the corrected SQL query in the database, and finally obtains the table-based question-answering result. While this method allows the large model to think about complex problems step by step, it only improves the accuracy of handling complex problems; the final SQL is still a single query statement, resulting in poor performance for problems requiring multi-step reasoning. Summary of the Invention
[0007] To address the shortcomings of existing technologies, such as difficulty in handling multi-step reasoning, difficulty in mapping user questions to accurate SQL that meets business needs leading to unreliable responses, and errors in SQL queries causing user questions to remain unanswered, this invention provides a database question-and-answer assistant construction method, system, and central air conditioning display terminal.
[0008] The present invention adopts the following technical solution.
[0009] The first aspect of this invention discloses a method for constructing a database question-answering assistant, comprising: Read the metadata of the target database, as well as the preset number of rows of data; The first prompt word is constructed based on the metadata, the preset number of rows of data, and the preset task planning requirements; When a user inputs a question, a pre-defined task planning agent generates a structured task chain based on the first prompt word; the structured task chain includes query sub-tasks and / or aggregation sub-tasks obtained by decomposing the user input question based on the first prompt word. Based on a preset SQL generation agent, determine whether the query class subtask exists. If it exists, generate a corresponding structured query statement for the query class subtask and write it into the structured task chain. Execute the structured query statements of each of the query subtasks, obtain the query results, and write them into the structured task chain; The structured task chain is input into a preset result aggregation agent, which generates a response to the user's question based on the query results and the aggregated subtasks.
[0010] More preferably, The metadata includes the table structure, field names, data types, and field comments in the target database.
[0011] More preferably, The task planning requirements include the fields required to construct the query subtasks and the aggregation subtasks, the filling requirements for each required field, and the principles for dividing the subtasks.
[0012] More preferably, The first prompt also includes the first agent role setting, database-related business descriptions, and a structured task chain model.
[0013] More preferably, The first intelligent agent role setting is used to clarify the knowledge system that the task planning intelligent agent needs to invoke, and the tasks that the task planning intelligent agent needs to execute.
[0014] More preferably, The structured task chain model is a preset structured task chain framework, including the writing format of the fields required for the query subtasks and the aggregation subtasks; The required fields include a subtask number field, a precise description of the subtask field, a query statement field, a dependent subtask field, and a subtask execution result field.
[0015] More preferably, When the task planning agent generates the structured task chain, it only writes the contents corresponding to the subtask number field, the accurate description field of the subtask, and the dependent subtask field.
[0016] More preferably, The SQL generation agent, based on a preset SQL, determines whether the query-type subtask exists. If it does, it generates a corresponding structured query statement for the query-type subtask and writes it into the structured task chain. This means that the SQL generation agent, based on a preset second prompt word and the content written in the accurate description field of each query-type subtask, determines whether the query-type subtask exists. If it does, it generates a corresponding structured query statement for each query-type subtask and writes it into the query statement field of the corresponding query-type subtask.
[0017] More preferably, The step of executing the structured query statements of each query subtask, obtaining query results, and writing them into the structured task chain means traversing the query statement fields of each query subtask in the structured task chain, executing the structured query statements to obtain the query results, and writing them into the subtask execution result field of the corresponding query subtask.
[0018] More preferably, When the execution of the structured query statement of the query subtask fails, the error message is written to the query statement field, and the structured task chain is re-input into the SQL generation agent to regenerate each of the structured query statements.
[0019] More preferably, The result aggregation agent generates a response to the user's question based on the query results and the aggregation subtasks, including: The result aggregation agent generates the results of each aggregation subtask based on a preset third prompt word, according to the content of the subtask execution result field of the query / aggregation subtask corresponding to the dependent subtask field in each aggregation subtask, and the content of the accurate description field of the subtask in each aggregation subtask, and writes the results into the subtask execution result field accordingly. Then, based on the structured task chain model containing the results of each of the aggregated subtasks and the question input by the user, the response to the user's question is generated; the response to the user's question includes a direct answer to the user's question, the question analysis process, and other findings and additional suggestions.
[0020] The second aspect of this invention discloses a database question-answering assistant construction system based on a database question-answering assistant construction method, including a database learning module, a first prompt word construction module, a structured task chain generation module, a structured query statement generation module, a structured query statement execution module, and a result aggregation and response generation module. The database learning module is used to read the metadata of the target database and the preset number of rows of data; The first prompt word construction module constructs the first prompt word based on the metadata, the preset number of rows of data, and the preset task planning requirements; When the structured task chain generation module receives a question input by the user, a preset task planning agent generates a structured task chain based on the first prompt word. The structured task chain includes query sub-tasks and / or aggregation sub-tasks obtained by decomposing the question input by the user based on the first prompt word. The structured query statement generation module, based on a preset SQL generation agent, determines whether the query class subtask exists. If it does, it generates a corresponding structured query statement for the query class subtask and writes it into the structured task chain. The structured query statement execution module is used to execute the structured query statements of each of the query class subtasks, obtain the query results respectively, and write them into the structured task chain. The result aggregation and response generation module is used to input the structured task chain into a preset result aggregation agent, which generates a response to the user's question based on the query results and the aggregation sub-tasks.
[0021] The third aspect of the present invention discloses a central air conditioning display terminal, wherein the central air conditioning display terminal runs the database question-and-answer assistant construction system.
[0022] The fourth aspect of this invention discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the database question-and-answer assistant construction method.
[0023] The beneficial effects of this invention are compared with those of the prior art: This invention designs a structured "task chain" model to express multiple sub-tasks that need to be completed for a user's problem and their dependencies, which can efficiently and accurately solve complex data analysis problems. Based on this task chain model, a method for constructing a task planning agent is proposed, which can automatically output a structured task chain according to the user's question. This invention automates the entire process from natural language input to task planning, database querying, and structured business responses through multi-agent collaborative execution. It not only accurately answers quantitative questions but also generates root cause analysis, trend judgments, and operational suggestions. Furthermore, this invention offers the following advantages: 1. By periodically learning database information, the large language model gains a comprehensive understanding of the data, which helps generate more accurate SQL query statements and improve query accuracy; 2. Introduce a structured task chain model mechanism. Guide the large language model to break down complex user problems into several sub-tasks and dependencies, and obtain the final result through multiple steps; 3. Possesses error self-healing and multi-turn interaction capabilities. When the SQL query generated by the large language model is incorrect, it can regenerate the SQL based on the error message, improving robustness in complex database environments. Attached Figure Description Figure 1 This is a flowchart illustrating the construction process of a database question-and-answer assistant. Figure 2This is a schematic diagram of the intelligent prompts for task planning; Figure 3 This is a schematic diagram of the database question-and-answer assistant system module. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of this invention. The embodiments described in this application are merely some embodiments of this invention, and not all embodiments. Based on the spirit of this invention, other embodiments obtained by those skilled in the art without creative effort are all within the protection scope of this invention.
[0025] This invention addresses the development of an AI question-answering assistant based on a large language model, integrated into a central air conditioning system operation and maintenance cloud platform. It provides a multi-agent collaborative architecture for database queries and analysis tasks, comprising several agents: a task planning agent, an SQL generation agent, and a result aggregation agent. This architecture, combined with the database question-answering assistant construction method of this invention, enables intelligent parsing, execution, and result management of complex database query tasks. Its operational flow is as follows: Figure 1 As shown.
[0026] This invention includes multiple agents / modules. The functions and outputs of each agent / module are described below. For each agent, a method for constructing system prompt words is given.
[0027] The prompt is an instruction or question input by the user or system into the large language model to guide the model to generate specific content or complete a specific task. A system prompt is a pre-defined instructional text within the agent, used to define the AI agent's role and guide its behavior.
[0028] The first aspect of this application discloses a method for constructing a database question-answering assistant; see appendix. Figure 1 ,include: Read the metadata of the target database, as well as the preset number of rows of data.
[0029] The target database can be a database such as MySQL, PostgreSQL, SQL Server, or Oracle. The target database used in this invention is typically used to store data related to the refrigeration room.
[0030] The metadata includes the table structure, field names, data types, and field comments in the target database.
[0031] The preset number of rows refers to a number of rows (i.e., the preset number of rows) of data selected from the target database; the preferred value range for the preset number of rows is 3-5 rows.
[0032] The read metadata is the framework of the target database. Reading the metadata of the target database and adding the metadata to the first prompt word helps the task planning agent to better analyze the data in the target database.
[0033] The first prompt word is constructed based on the metadata, the preset number of rows of data, and the preset task planning requirements; the task planning requirements include the fields required to construct query-type subtasks and aggregation-type subtasks, the filling requirements of each required field, and the subtask division principles.
[0034] The task planning requirements specify the fields needed for constructing query-type and aggregation-type subtasks, and the filling requirements for each field. Specifically, for each subtask, the following fields should be provided according to the structured task chain model: "task_id" (subtask number), "description" (accurate description of the subtask), "sql" (query statement), "dependencies" (dependencies field, which contains an array of dependent subtask IDs; if none exists, it is an empty array), and "result" (subtask execution result field). At this stage, only the values for "task_id," "description," and "dependencies" need to be provided. The principle for dividing subtasks is that subtasks should avoid extracting large amounts of data from the database as much as possible and should be summarized according to the specific problem.
[0035] The aforementioned task planning requirements enable the task planning agent to more clearly define how to generate structured task chains.
[0036] The first prompt also includes the first agent's role setting, database-related business descriptions, and a structured task chain model. Adding this first prompt helps the task planning agent better understand how to generate structured task chains that can be used to efficiently and accurately solve complex data analysis problems.
[0037] The first intelligent agent role setting is used to clarify the knowledge system that the task planning intelligent agent needs to call (for example: you are a task planning expert, so the intelligent agent calls the knowledge system about "task planning"), and the task that the task planning intelligent agent needs to perform (i.e., breaking down the complex problem raised by the user into several sub-tasks).
[0038] Setting the role of the first agent in the first prompt can significantly improve the relevance, consistency and scenario adaptability of the agent's output, and help the task planning agent clarify its "identity positioning", thereby more accurately matching user needs.
[0039] The database business description includes explanations of the various technical terms used in the target database.
[0040] The structured task chain model is a preset structured task chain framework, including the writing format of the fields required for the query subtasks and the aggregation subtasks; The fields required for both query-type subtasks and aggregation-type subtasks include a subtask number field, a precise description of the subtask, a query statement field, a dependent subtask field, and a subtask execution result field. The writing format is consistent, and query-type subtasks and aggregation-type subtasks are distinguished only by the precise description of the subtask.
[0041] The structured task chain model introduces a structured task chain mechanism to the task planning agent. It guides the large language model to break down complex user problems into several sub-tasks and dependencies, obtaining the final result through multiple steps. Specifically, the structured task chain model is as follows: [{"task_id": 1, "description": "Subtask description 1", "sql": "SQL statement 1", "result": "Result 1", "dependencies": []}, {"task_id": 2, "description": "Subtask description 2", "sql": "SQL statement 2", "result": "Result 2", "dependencies": []}, {"task_id": 3, "description": "Subtask description 3", "sql": "", "result": "Result 3", "dependencies": [1, 2]}, ...] The meanings of each field in the task chain model are as follows: task_id is a subtask number field used to record subtask numbers; The description field is a precise description of the subtask.
[0042] SQL represents a query statement field. It is used to perform data queries; when no query is needed, the value is an empty string. The Dependencies field represents the dependent subtasks. It lists the numbers of other subtasks that this subtask depends on for execution; it is an empty array if there are no dependent subtasks. The `result` field represents the subtask execution result. If the subtask is a query subtask, the `result` field stores the SQL query result; if the subtask is an aggregation subtask, the `result` field stores the aggregation calculation result.
[0043] When a user inputs a question, a pre-defined task planning agent generates a structured task chain based on the first prompt word. The structured task chain includes query-type subtasks and / or aggregation-type subtasks obtained by decomposing the user input question based on the first prompt word. The query-type subtasks and aggregation-type subtasks can be collectively referred to as subtasks, and both query-type subtasks and aggregation-type subtasks are specific categories of subtasks.
[0044] The pre-defined task planning agent can use any existing large model (such as GPT, Qwen, Deepseek, etc.), and the subsequent SQL generation agent and result aggregation agent can also use any existing large model. The structured task chain must include at least one query subtask or an aggregation subtask; When the task planning agent generates the structured task chain, it only writes the contents corresponding to the subtask number field, the accurate description field of the subtask, and the dependent subtask field.
[0045] The task planning agent clarifies the specific categories of subtasks and their dependencies by filling in a portion of the generated structured task chain. This allows the agent to write the content of each field in the structured task chain step by step, making the structured task chain more thorough in its analysis of user problems. This enables the agent to efficiently and accurately solve complex data while obtaining more precise answers.
[0046] Based on a preset SQL generation agent, determine whether the query class subtask exists. If it exists, generate a corresponding structured query statement for the query class subtask and write it into the structured task chain. Specifically, the SQL generation agent, based on a preset second prompt word, determines whether a query-type subtask exists according to the content written in the accurate description field of each subtask. If it exists, it generates a corresponding structured query statement for each query-type subtask and writes it into the query statement field of the corresponding subtask. The preset second prompt word is used to prompt the SQL generation agent what knowledge system it needs to invoke (e.g., if you are an SQL expert, the agent invokes a knowledge system about "SQL"), and the task that the SQL generation agent needs to perform, that is, to determine whether a query-type subtask exists based on the content written in the accurate description field of each subtask; if it exists, it generates a corresponding structured query statement for each subtask and writes it into the query statement field of the corresponding subtask.
[0047] Since the aforementioned content obtains precise and simple query subtasks by decomposing each user input question, the SQL generation agent can generate more accurate SQL query statements based on preset second prompt words, thereby improving query accuracy.
[0048] Execute the structured query statements of each of the query subtasks, obtain the query results, and write them into the structured task chain; Specifically, executing the structured query statements of each of the query-type subtasks, obtaining query results, and writing them into the structured task chain means traversing the query statement fields of each of the query-type subtasks in the structured task chain, executing the structured query statements to obtain the query results, and writing them into the subtask execution result field of the corresponding query-type subtask.
[0049] This step improves the subtask execution result field of query-type subtasks in the structured task chain, laying a solid foundation for generating reliable answers to user questions in the future.
[0050] When the execution of the structured query statement in the query subtask fails, an error message is written to the query statement field, and the structured task chain is re-input into the SQL generation agent to regenerate each structured query statement. Those skilled in the art should know that the error message may include error codes, error types, etc., or may only include "SQL statement error"; the error message is recorded after the original SQL statement. This step enables the invention to possess error self-healing and multi-turn interaction capabilities. When an SQL query generated by the large language model encounters an error, the SQL can be regenerated based on the error message, improving robustness in complex database environments.
[0051] The structured task chain is input into a preset result aggregation agent, which generates a response to the user's question based on the query results and the aggregated subtasks.
[0052] Specifically, the result aggregation agent, based on a preset third prompt word, generates the results of each aggregation subtask according to the content of the subtask execution result field of the query / aggregation subtask corresponding to the dependent subtask field in each aggregation subtask, and the content of the accurate description field of the subtask in each aggregation subtask, and writes the results into the respective subtask execution result fields. The preset third prompt word is used to prompt the result aggregation agent to call what knowledge system (e.g., if you are a data aggregation expert, the agent calls a knowledge system about data aggregation; if you are an intelligent answer generator, the agent calls a knowledge system about answering questions), and the task that the result aggregation agent needs to perform, that is, to generate the results of each aggregation subtask according to the content of the subtask execution result field of the query / aggregation subtask corresponding to the dependent subtask field in each aggregation subtask, and the content of the accurate description field of the subtask in each aggregation subtask, and write the results into the respective subtask execution result fields.
[0053] Then, based on the structured task chain model containing the results of each of the aggregated subtasks and the question input by the user, the response to the user's question is generated; the response to the user's question includes a direct answer to the user's question, the question analysis process, and other findings and additional suggestions.
[0054] This invention designs a structured "task chain" model to express multiple sub-tasks that need to be completed for a user's problem and their dependencies, which can efficiently and accurately solve complex data analysis problems. Based on this task chain model, a method for constructing a task planning agent is proposed, which can automatically output a structured task chain according to the user's question. This invention achieves full automation of the process from natural language input to task planning, database querying, and structured business responses through the collaborative execution of multiple intelligent agent modules. It can not only accurately answer quantitative questions, but also generate content such as cause analysis, trend judgment, and operation and maintenance suggestions.
[0055] Example 1 A method for building a database question-answering assistant.
[0056] Step 1: Read the metadata of the target database and the preset number of rows of data, and record the metadata of the target database and the preset number of rows of data as database metadata and data example; The metadata of the target database includes all table structures, field names, data types, and field comments (including data units) in the target database.
[0057] A predetermined number of rows of data are read from each table to record real data features for large-scale model learning. The target database is typically structured in tabular form, where each row represents a data record. Multiple rows are read here to allow the large-scale model to learn the data features of the database.
[0058] The reading step can automatically obtain the above information through the database connection interface and convert it into a unified structured format for subsequent steps to call; the preferred value range for the preset number of rows is 3-5 rows.
[0059] The system can periodically monitor and synchronize changes to the target database, ensuring that all agents relying on database metadata always operate based on the latest and most accurate metadata, thereby improving the accuracy of SQL generation and the overall reliability of the system. The synchronized update refers to rereading the target database's metadata and several rows of data from the tables after changes have been made.
[0060] This invention enables the large language model to gain a comprehensive understanding of the data by periodically learning database information, which helps generate more accurate SQL query statements and improve query accuracy.
[0061] Step 2: As Figure 2 As shown, the first prompt word is constructed based on the preset first intelligent agent role setting, database metadata and data examples, preset database-related business descriptions, preset task planning requirements, and preset structured task chain model; The first intelligent agent role setting is used to clarify the knowledge system that the task planning intelligent agent needs to call and the tasks that the task planning intelligent agent needs to perform; for example, if you are a task planning expert, the intelligent agent will call the knowledge system about "task planning"; the tasks that the task planning intelligent agent needs to perform are (i.e., breaking down the complex problem raised by the user into several sub-tasks).
[0062] Specifically, the intelligent agent role is preferably set as follows: "You are a task planning expert who breaks down the complex problems raised by users into several sub-tasks. Each sub-task is responsible for a relatively simple SQL query task or data aggregation calculation task, and the dependencies between sub-tasks need to be clearly defined"; the database business description includes explanations of various professional technical terms in the target database.
[0063] The database metadata and data examples are obtained according to step 1; The specific content of the database-related business description is determined by the business content of the target database of the multi-agent system; for example, a refrigeration room includes equipment such as chillers, chilled water pumps, cooling water pumps, and cooling towers; cooling capacity refers to the cooling capacity of the refrigeration room, etc.
[0064] The task planning requirements include the fields required to construct the query subtasks and the aggregation subtasks, the filling requirements for each required field, and the principles for dividing the subtasks.
[0065] The task planning requirements, specifically the fields required for constructing the query-type subtasks and the aggregation-type subtasks, and the filling requirements for each required field, include: For each subtask, the following fields should be provided according to the structured task chain model: "task_id" (subtask number field), "description" (precise description of the subtask field), "sql" (query statement field), "dependencies" (dependency subtask field, which contains an array of dependent subtask IDs; if none exists, it is an empty array), and "result" (subtask execution result field); at this stage, only the values of "task_id", "description", and "dependencies" need to be provided; the principle for dividing the subtasks is that subtasks should avoid extracting large amounts of data from the database as much as possible, and should be summarized according to the specific problem.
[0066] Preferably, the task planning requirements are as follows: "① For each subtask, provide the following fields according to the structured task chain model: "task_id" (subtask ID), "description" (task description), "sql" (query statement), "dependencies" (an array containing dependent subtask IDs; an empty array if none exists), and "result" (subtask execution result). At this stage, only the values of "task_id", "description", and "dependencies" need to be provided. ② Subtasks should avoid extracting large amounts of data from the database as much as possible and should be summarized according to the specific problem. For example, if the user's problem is 'calculate the power consumption from May to October', then when planning the task, provide aggregation by month, and do not filter out all the data from May to September." The structured task chain model is a preset structured task chain framework, including the writing format of each subtask; The fields required for a subtask include the subtask number field, the accurate description of the subtask field, the query statement field, the dependent subtask field, and the subtask execution result field.
[0067] The structured task chain model is used to define a task decomposition method. This model specifies the structure of subtasks and the way to express the dependencies between subtasks.
[0068] Specifically, the structured task chain model includes a subtask number field, a precise description field of the subtask, a query statement field, a dependent subtask field, and a subtask execution result field, for example: [{"task_id": 1, "description": "Subtask description 1", "sql": "SQL statement 1", "result": "Result 1", "dependencies": []}, {"task_id": 2, "description": "Subtask description 2", "sql": "SQL statement 2", "result": "Result 2", "dependencies": []}, {"task_id": 3, "description": "Subtask description 3", "sql": "", "result": "Result 3", "dependencies": [1, 2]}, ...] The meanings of each field in the task chain model are as follows: task_id is the subtask number field; The description field is a precise description of the subtask.
[0069] SQL represents a query statement field. It is used to perform data queries; when no query is needed, the value is an empty string. The `Dependencies` field represents the dependent subtasks. It lists the IDs of other subtasks that this subtask depends on for execution; it is an empty array if there are no dependent subtasks. The result field represents the execution result of the subtask.
[0070] Subtasks are divided into two categories: query subtasks and aggregation subtasks, as detailed below: Query-type subtasks (such as "querying the power consumption of the project in June" or "querying the cooling capacity of the project on July 8") are subtasks that require generating SQL structured query statements to retrieve data from the database. These subtasks do not depend on other subtasks. Aggregation-type subtasks (such as "calculate the energy efficiency of the project in June based on the cooling capacity and power consumption of the project in June", "calculate the change ratio of energy efficiency in July relative to June based on the energy efficiency of the project in June and July") are subtasks that require aggregation calculations, statistics and other operations based on the execution results of other subtasks. These types of tasks do not require querying.
[0071] Furthermore, the structured task chain model only specifies the structure of the model's subtasks and the method for establishing dependencies; the number of subtasks is unlimited.
[0072] If the subtask is a query subtask, the execution result field of the subtask will store the SQL query result; if the subtask is an aggregation subtask, the execution result field of the subtask will store the aggregation calculation result.
[0073] Step 3: When the user inputs a question, the preset task planning agent generates a structured task chain based on the first prompt word; the structured task chain includes query subtasks and / or aggregation subtasks obtained by decomposing the user input question based on the first prompt word; the query subtasks and aggregation subtasks can be collectively referred to as subtasks, and both query subtasks and aggregation subtasks are specific categories of subtasks.
[0074] The pre-defined task planning agent can use any existing large model (such as GPT, Qwen, Deepseek, etc.), and the subsequent SQL generation agent and result aggregation agent can also use any existing large model. The structured task chain must include at least one query subtask or an aggregation subtask; When the task planning agent generates the structured task chain, it only writes the contents corresponding to the subtask number field, the accurate description field of the subtask, and the dependent subtask field.
[0075] The task planning agent construction module, based on the aforementioned structured task chain model and incorporating the design of the first prompt word, proposes a method for constructing a task planning agent, such as... Figure 2 As shown, this intelligent agent can effectively decompose user-input data query problems into multiple sub-tasks, achieving efficient and accurate task planning.
[0076] Step 4: Based on the preset SQL generation agent, determine whether the query class subtask exists. If it exists, generate the corresponding structured query statement for the query class subtask and write it into the structured task chain. The preset SQL generation agent is constructed by setting a second prompt word for any existing large model. This agent needs to generate SQL query statements for each query subtask based on the input task chain.
[0077] Specifically, the SQL generation agent acquires the input structured task chain and the database metadata and data examples read in step 1. Then, based on a preset second prompt word, it traverses the sub-tasks in the task chain model and performs semantic recognition on the task description. If it is determined to be a query task, it combines the database information obtained in step 1 to generate a structured query statement (hereinafter referred to as SQL statement) corresponding to the task description and writes it into the query statement field of the sub-task.
[0078] The preset second prompt word is used to prompt the SQL generation agent what knowledge system it needs to call (e.g., you are an SQL expert, so the agent calls the knowledge system about "SQL"), and the task that the SQL generation agent needs to perform, that is, to determine whether the query class subtask exists based on the content written in the accurate description field of the subtask of each query class subtask; if it exists, a corresponding structured query statement is generated for each query class subtask and written into the query statement field of the corresponding query class subtask.
[0079] If the query statement field in the query subtask already contains an SQL statement and also includes database execution error information, then based on the error information, the SQL statement is corrected and replaced by the updated field.
[0080] If the query statement fields in a query subtask already contain an SQL statement but do not include database execution error information, then the subtask will not be processed. Preferably, the preset second prompt word is as follows: "You are an SQL expert. You will receive database information and a batch of tasks." You need to iterate through all the tasks and identify the text in the "description" field of each task. If the description text provides a query task, you need to write the corresponding SQL query statement based on the database information and assign this statement to the "sql" field of that task. If the value of the "sql" field of the task is an SQL statement and a database error message, it means that the SQL query has encountered an error, and you need to regenerate the correct SQL query statement based on this information. The output of the SQL generation agent is a structured task chain with SQL query statements.
[0081] Step 5: Execute the structured query statements of each of the query subtasks, obtain the query results, and write them into the structured task chain; The subtasks in the task chain that are not empty in the query statement fields are called in sequence, and the corresponding SQL statements are submitted to the database and executed.
[0082] Upon successful execution, the query results will be written to the result field of the subtask. When execution fails, the failed SQL statement and the error message returned by the database are written into the query statement field of the subtask. After all query-type subtasks have been executed, the structured task chain is re-entered into step 4 for SQL statement correction. When the cumulative number of execution failures of the same structured task chain exceeds a preset threshold n, to avoid the system from entering an infinite loop, the task execution is terminated, and "The query data is incorrect, please retry" is output. Those skilled in the art should know that the error message may include error code, error type, etc., or may only include "SQL statement error". The error message is recorded after the original SQL statement. The preset threshold can be set by those skilled in the art according to the actual situation.
[0083] This step generates a structured task chain containing SQL query results or SQL query error messages.
[0084] Step 6: Input the structured task chain into a preset result aggregation agent, which generates a response to the user's question based on the query results and the aggregated subtasks.
[0085] The result aggregation agent is responsible for uniformly integrating and formatting the query results of all subtasks according to the system prompts, and then outputting them to the user interface.
[0086] The result is aggregated into the structured task chain generated in step 5 by the intelligent agent; For aggregate subtasks in a task chain, the result of the subtask is generated based on the "result" of its dependent subtasks and the "description" of the subtask, and then assigned to the "result" field to obtain the complete task chain. Based on the user's input questions and the complete task chain obtained above, the information is integrated and summarized, and then formatted and output as required. The resulting aggregated agent is constructed by building a third cue word for any existing large model.
[0087] Specifically, after all query-type subtasks have been executed, the result aggregator, based on a preset third prompt word, generates an aggregated result for the subtasks marked as aggregation-type in the task chain, according to the result fields of their dependent subtasks and the task description, and writes it to the result field of that subtask. Further, combining the complete task chain with the user-input question, the execution results of each subtask are integrated and summarized to form the final output. This output includes a direct answer to the user's question, the corresponding analysis process, and possible additional suggestions.
[0088] The preset third prompt word is used to prompt the result aggregation agent what knowledge system it needs to call (e.g., if you are a data aggregation expert, the agent calls a knowledge system about data aggregation; if you are an intelligent answer generator, the agent calls a knowledge system about answering questions), and the task that the result aggregation agent needs to perform, that is, according to the content of the subtask execution result field of the query / aggregation subtask corresponding to the dependent subtask field in each aggregation subtask, and the content of the accurate description field of the subtask in each aggregation subtask, the results of each aggregation subtask are generated accordingly and written into the subtask execution result field.
[0089] The preset third prompt word includes two parts. The first part of the prompt word is used to prompt the result aggregation agent to generate the result of each aggregation subtask according to the content of the subtask execution result field of the query / aggregation subtask corresponding to the dependent subtask field in each aggregation subtask, and the content of the accurate description field of the subtask in each aggregation subtask, and write the result of each subtask execution result field accordingly. Those skilled in the art should know how to design this part of the prompt word, and it will not be described in detail here.
[0090] The second part of the prompt words is used to prompt the result aggregation agent to generate the response to the user's question based on the structured task chain model written into the results of each of the aggregated subtasks and the question input by the user; the response to the user's question includes a direct answer to the user's question, the question analysis process, and other findings and additional suggestions.
[0091] Preferably, the second part of the prompt words is as follows: "You are an intelligent answer generator. You will receive a task chain and a user's question. The task chain is constructed by breaking down the user's question, containing sub-tasks and dependencies between them. Each sub-task contains a corresponding execution result. Please integrate and analyze the task chain and the user's question to provide an answer. The answer should include ① a direct answer to the user's question; ② the question analysis process; ③ other findings and additional suggestions (if applicable)." Example 2 A method for building a database question-answering assistant.
[0092] Read the metadata of the target database, as well as the preset number of rows of data, and record them as database metadata and data examples.
[0093] The metadata includes the table structure, field names, data types, and field comments in the target database.
[0094] The preset number of rows refers to a number of rows (i.e., the preset number of rows) of data selected from the target database; the preferred value range for the preset number of rows is 3-5 rows.
[0095] The first prompt word is constructed based on the preset first agent role setting, database metadata and data examples, preset database-related business descriptions, preset task planning requirements, and preset structured task chain model. The first intelligent agent role setting is used to clarify the knowledge system that the task planning intelligent agent needs to invoke, and the tasks that the task planning intelligent agent needs to execute.
[0096] The database business description includes explanations of the various technical terms used in the target database.
[0097] The task planning requirements include the fields required to construct the query subtasks and the aggregation subtasks, the filling requirements for each required field, and the principles for dividing the subtasks.
[0098] The structured task chain model is a preset structured task chain framework, including the writing format of the fields required for the query subtasks and the aggregation subtasks; Preferably, the first prompt word is specifically: First agent role setting: You are a task planning expert who breaks down complex problems raised by users into several sub-tasks. Each sub-task is responsible for a relatively simple SQL query task or data aggregation calculation task, and you need to clarify the dependencies between the sub-tasks.
[0099] Database metadata: { "table": { "table_name": "data_000000_2024", "columns_definitions": [ { "name": "id", "type": "INT", "unit": null }, { "name": "date", "type": "DATE", "unit": null }, { "name": "hour", "type": "INT", "unit": null }, { "name": "cooling_load", "type": "FLOAT(6,1)", "unit": null }, { "name": "power_consumption", "type": "FLOAT(6,1)", "unit": null } ] } } Data example: [ {"id": 0, "date": "2024-10-01", "hour": 1, "cooling_load": 368.6, "power_consumption": 61.2}, {"id": 1, "date": "2024-10-01", "hour": 2, "cooling_load": 342.9, "power_consumption": 60.1}, {"id": 2, "date": "2024-10-01", "hour": 3, "cooling_load": 335.4, "power_consumption": 59.7} ] Database-related business instructions: - The refrigeration room contains equipment such as chillers, chilled water pumps, cooling water pumps, and cooling towers. - Cooling capacity refers to the cooling capacity of the refrigeration room, measured in kWh. - Cooling capacity refers to the cooling capacity of the chiller room, measured in kWh. - Equipment energy consumption percentage refers to the proportion of electricity consumed by chilled water pumps, cooling water pumps, cooling towers, and chillers to the total electricity consumption of the refrigeration room. - Chiller energy efficiency = Cooling capacity of the chiller room / Power consumption of the chiller unit - Energy efficiency of a chiller room = Cooling capacity of the chiller room / Power consumption of the chiller room - Chilled water pump delivery coefficient = Cooling capacity of the chiller room / Power consumption of the chilled water pump - Cooling tower delivery coefficient = Cooling capacity of the chiller room / Power consumption of the cooling tower - Cooling water pump delivery coefficient = Cooling capacity of the chiller room / Power consumption of the cooling water pump - Chiller units include Chiller Unit 1, Chiller Unit 2, Chiller Unit 3, Chiller Unit 4, etc. Unless otherwise specified, "chiller unit" refers to the sum of all chiller units. The same applies to chilled water pumps, cooling water pumps, and cooling towers. - The cooling capacity, power consumption, and cooling volume of a refrigeration room are the sum of the values for the entire refrigeration room, not the values of individual equipment. Task planning requirements: ① For each subtask, provide the following fields according to the structured task chain model: "task_id" (task ID), "description" (task description), "sql" (query statement), "dependencies" (an array containing the IDs of dependent subtasks, or an empty array if none exists), and "result" (subtask execution result); In the initial stage of the task chain, only the values of "task_id", "description", and "dependencies" need to be provided; ② Subtasks are divided into two categories: query subtasks and aggregation subtasks. Query subtasks need to generate SQL to query data from the database; these tasks do not depend on other subtasks. Aggregation subtasks need to perform aggregation calculations, statistics, and other operations based on the execution results of other subtasks; these tasks do not need to perform queries, and their "sql" field is always empty. ③ Subtasks should avoid extracting large amounts of data from the database as much as possible, and should be summarized according to the specific problem. For example, if the user's problem is 'calculate the power consumption from May to October', then in task planning, the query-type subtasks should first perform aggregate queries by month to obtain the results for each month, and finally the aggregate-type subtasks should be used to calculate the sum of power consumption for each month. Do not filter out all the data from May to September.
[0100] Structured task chain model: [{"task_id": 1, "description": "Subtask description 1", "sql": "SQL statement 1", "result": "Result 1", "dependencies": []}, { "task_id": 2, "description": "Subtask description 2", "sql": "SQL statement 2", "result": "Result 2", "dependencies": []}, { "task_id": 3, "description": "Subtask description 3", "sql": "", "result": "Result 3", "dependencies": [1, 2]}, ...] The meanings of each field in the task chain model are as follows: task_id is a subtask number field used to record subtask numbers; The description field is a precise description of the subtask.
[0101] SQL represents a query statement field. It is used to perform data queries; when no query is needed, the value is an empty string. The Dependencies field represents the dependent subtasks. It lists the numbers of other subtasks that this subtask depends on for execution; it is an empty array if there are no dependent subtasks. The result field represents the execution result of the subtask.
[0102] When a user inputs a question, a pre-defined task planning agent generates a structured task chain based on the first prompt word. The structured task chain includes query-type subtasks and / or aggregation-type subtasks obtained by decomposing the user input question based on the first prompt word. The query-type subtasks and aggregation-type subtasks can be collectively referred to as subtasks, and both query-type subtasks and aggregation-type subtasks are specific categories of subtasks.
[0103] The pre-defined task planning agent can use any existing large model (such as GPT, Qwen, Deepseek, etc.), and the subsequent SQL generation agent and result aggregation agent can also use any existing large model. The structured task chain must include at least one query subtask or an aggregation subtask; When the task planning agent generates the structured task chain, it only writes the contents corresponding to the subtask number field, the accurate description field of the subtask, and the dependent subtask field.
[0104] Based on a preset SQL generation agent, determine whether the query class subtask exists. If it exists, generate a corresponding structured query statement for the query class subtask and write it into the structured task chain. Specifically, the SQL generation agent, based on a preset second prompt word, determines whether a query-type subtask exists according to the content written in the accurate description field of each subtask. If it exists, it generates a corresponding structured query statement for each query-type subtask and writes it into the query statement field of the corresponding subtask. The preset second prompt word is used to prompt the SQL generation agent which knowledge system to invoke and the task to be executed.
[0105] Preferably, the second prompt word is as follows: "You are an SQL expert. You will receive database information and a batch of tasks." You need to iterate through all the tasks and identify the text in the "description" field of each task. If the description text provides a query task, you need to write the corresponding SQL query statement based on the database information and assign this statement to the "sql" field of that task. If the value of the "sql" field of the task is an SQL statement and a database error message, it means that the SQL query has encountered an error, and you need to regenerate the correct SQL query statement based on this information. Execute the structured query statements of each of the query subtasks, obtain the query results, and write them into the structured task chain; Specifically, executing the structured query statements of each of the query-type subtasks, obtaining query results, and writing them into the structured task chain means traversing the query statement fields of each of the query-type subtasks in the structured task chain, executing the structured query statements to obtain the query results, and writing them into the subtask execution result field of the corresponding query-type subtask.
[0106] When the execution of the structured query statement of the query subtask fails, the error message is written to the query statement field, and the structured task chain is re-input into the SQL generation agent to regenerate each of the structured query statements.
[0107] The structured task chain is input into a preset result aggregation agent, which generates a response to the user's question based on the query results and the aggregated subtasks.
[0108] Specifically, the result aggregation agent generates the results of each aggregation subtask based on a preset third prompt word, according to the content of the subtask execution result field of the query / aggregation subtask corresponding to the dependent subtask field in each aggregation subtask, and the content of the accurate description field of the subtask in each aggregation subtask, and writes the results into the subtask execution result field accordingly. Then, based on the structured task chain model containing the results of each of the aggregated subtasks and the question input by the user, the response to the user's question is generated; the response to the user's question includes a direct answer to the user's question, the question analysis process, and other findings and additional suggestions.
[0109] The preset third prompt word is used to prompt the result aggregation agent which knowledge system to call and the task to be performed by the result aggregation agent.
[0110] The preset third prompt word includes two parts. The first part of the prompt word is used to prompt the result aggregation agent to generate the result of each aggregation subtask according to the content of the subtask execution result field of the query / aggregation subtask corresponding to the dependent subtask field in each aggregation subtask, and the content of the accurate description field of the subtask in each aggregation subtask, and write the result of each subtask execution result field accordingly. Those skilled in the art should know how to design this part of the prompt word, and it will not be described in detail here.
[0111] The second part of the prompt words is used to prompt the result aggregation agent to generate the response to the user's question based on the structured task chain model written into the results of each of the aggregated subtasks and the question input by the user; the response to the user's question includes a direct answer to the user's question, the question analysis process, and other findings and additional suggestions.
[0112] Preferably, the second part of the prompt words is as follows: "You are an intelligent answer generator. You will receive a task chain and a user's question. The task chain is constructed by breaking down the user's question, containing sub-tasks and dependencies between them. Each sub-task contains a corresponding execution result. Please integrate and analyze the task chain and the user's question to provide an answer. The answer should include ① a direct answer to the user's question; ② the question analysis process; ③ other findings and additional suggestions (if applicable)." The second aspect of this application discloses a database question-answering assistant construction system based on a database question-answering assistant construction method; see appendix. Figure 3It includes a database learning module, a first prompt keyword construction module, a structured task chain generation module, a structured query statement generation module, a structured query statement execution module, and a result aggregation and response generation module. The database learning module is used to read the metadata of the target database and the preset number of rows of data; The first prompt word construction module constructs the first prompt word based on the metadata, the preset number of rows of data, and the preset task planning requirements; When the structured task chain generation module receives a question input by the user, a preset task planning agent generates a structured task chain based on the first prompt word. The structured task chain includes query sub-tasks and / or aggregation sub-tasks obtained by decomposing the question input by the user based on the first prompt word. The structured query statement generation module, based on a preset SQL generation agent, determines whether the query class subtask exists. If it does, it generates a corresponding structured query statement for the query class subtask and writes it into the structured task chain. The structured query statement execution module is used to execute the structured query statements of each of the query class subtasks, obtain the query results respectively, and write them into the structured task chain. When the execution of the structured query statement of the query subtask fails, the error message is written to the query statement field, and the structured task chain is re-input into the SQL generation agent to regenerate each of the structured query statements.
[0113] The result aggregation and response generation module is used to input the structured task chain into a preset result aggregation agent, which generates a response to the user's question based on the query results and the aggregation sub-tasks.
[0114] This invention automates the entire process from natural language input to task planning, database querying, and structured business responses through modular collaborative execution based on multi-agent construction. It can not only accurately answer quantitative questions, but also generate content such as cause analysis, trend judgment, and operation and maintenance suggestions.
[0115] A third aspect of this invention discloses a central air conditioning display terminal, which runs the database question-and-answer assistant construction system. This invention can be well integrated into the central air conditioning display terminal, providing a better user experience during human-computer interaction.
[0116] A fourth aspect of this invention discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the database question-answering assistant construction method. This invention can be applied to any computer program and has a wide range of applications.
[0117] This disclosure can be a system, method, and / or computer program product. A computer program product may include a computer-readable storage medium having computer-readable program instructions loaded thereon for causing a processor to implement various aspects of this disclosure.
[0118] Computer-readable storage media can be tangible devices capable of holding and storing instructions for use by an instruction execution device. Computer-readable storage media can be, for example—but not limited to—electrical storage devices, magnetic storage devices, optical storage devices, electromagnetic storage devices, semiconductor storage devices, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable compact disc read-only memory (CD-ROM), digital multifunction disc (DVD), memory sticks, floppy disks, mechanical encoding devices, such as punch cards or recessed protrusions storing instructions thereon, and any suitable combination of the foregoing. The computer-readable storage media used herein are not to be construed as transient signals themselves, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through waveguides or other transmission media (e.g., light pulses through fiber optic cables), or electrical signals transmitted through wires.
[0119] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.
[0120] Computer program instructions used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages such as Smalltalk, C++, etc., and conventional procedural programming languages such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing the status information of the computer-readable program instructions to implement various aspects of this disclosure.
[0121] 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 it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the protection scope of the claims of the present invention.
Claims
1. A method for constructing a database question-answering assistant, characterized in that, include: Read the metadata of the target database, as well as the preset number of rows of data; The first prompt word is constructed based on the metadata, the preset number of rows of data, and the preset task planning requirements; When the user inputs a question, the pre-defined task planning agent generates a structured task chain based on the first prompt word; The structured task chain includes query-type subtasks and / or aggregation-type subtasks obtained by decomposing the user-input question based on the first prompt word; Based on a preset SQL generation agent, determine whether the query class subtask exists. If it exists, generate a corresponding structured query statement for the query class subtask and write it into the structured task chain. Execute the structured query statements of each of the query subtasks, obtain the query results, and write them into the structured task chain; The structured task chain is input into a preset result aggregation agent, which generates a response to the user's question based on the query results and the aggregated subtasks.
2. The database question-answering assistant construction method according to claim 1, characterized in that: The metadata includes the table structure, field names, data types, and field comments in the target database.
3. The database question-answering assistant construction method according to claim 1, characterized in that: The task planning requirements include the fields required to construct the query subtasks and the aggregation subtasks, the filling requirements for each required field, and the principles for dividing the subtasks.
4. The database question-answering assistant construction method according to claim 1, characterized in that: The first prompt also includes the first agent role setting, database-related business descriptions, and a structured task chain model.
5. The database question-answering assistant construction method according to claim 4, characterized in that: The first intelligent agent role setting is used to clarify the knowledge system that the task planning intelligent agent needs to invoke, and the tasks that the task planning intelligent agent needs to execute.
6. The database question-answering assistant construction method according to claim 4, characterized in that: The structured task chain model is a preset structured task chain framework, including the writing format of the fields required for the query subtasks and the aggregation subtasks; The required fields include a subtask number field, a precise description of the subtask field, a query statement field, a dependent subtask field, and a subtask execution result field.
7. The database question-answering assistant construction method according to claim 1 or 6, characterized in that: When the task planning agent generates the structured task chain, it only writes the contents corresponding to the subtask number field, the accurate description field of the subtask, and the dependent subtask field.
8. The database question-answering assistant construction method according to claim 1 or 6, characterized in that: The SQL generation agent, based on a preset SQL, determines whether the query subtask exists. If it does, it generates a corresponding structured query statement for the query subtask and writes it into the structured task chain. This means that the SQL generation agent determines whether the query subtask exists based on a preset second prompt word and the content written in the accurate description field of each query subtask. If it exists, a corresponding structured query statement is generated for each query class subtask, and written into the query statement field of the corresponding query class subtask.
9. The database question-answering assistant construction method according to claim 1 or 6, characterized in that: The step of executing the structured query statements of each query subtask, obtaining query results, and writing them into the structured task chain means traversing the query statement fields of each query subtask in the structured task chain, executing the structured query statements to obtain the query results, and writing them into the subtask execution result field of the corresponding query subtask.
10. The database question-answering assistant construction method according to claim 1 or 6, characterized in that: When the execution of the structured query statement of the query subtask fails, the error message is written to the query statement field, and the structured task chain is re-input into the SQL generation agent to regenerate each of the structured query statements.
11. The database question-answering assistant construction method according to claim 1 or 6, characterized in that: The result aggregation agent generates a response to the user's question based on the query results and the aggregation subtasks, including: The result aggregation agent generates the results of each aggregation subtask based on a preset third prompt word, according to the content of the subtask execution result field of the query / aggregation subtask corresponding to the dependent subtask field in each aggregation subtask, and the content of the accurate description field of the subtask in each aggregation subtask, and writes the results into the subtask execution result field accordingly. Then, based on the structured task chain model containing the results of each of the aggregated subtasks and the question input by the user, the response to the user's question is generated; the response to the user's question includes a direct answer to the user's question, the question analysis process, and other findings and additional suggestions.
12. A database question-answering assistant construction system utilizing the database question-answering assistant construction method according to any one of claims 1-11, characterized in that, It includes a database learning module, a first prompt word construction module, a structured task chain generation module, a structured query statement generation module, a structured query statement execution module, and a result aggregation and response generation module. The database learning module is used to read the metadata of the target database and the preset number of rows of data; The first prompt word construction module constructs the first prompt word based on the metadata, the preset number of rows of data, and the preset task planning requirements; When the structured task chain generation module receives a question input by the user, the preset task planning agent generates a structured task chain based on the first prompt word. The structured task chain includes query-type subtasks and / or aggregation-type subtasks obtained by decomposing the user-input question based on the first prompt word; The structured query statement generation module, based on a preset SQL generation agent, determines whether the query class subtask exists. If it does, it generates a corresponding structured query statement for the query class subtask and writes it into the structured task chain. The structured query statement execution module is used to execute the structured query statements of each of the query class subtasks, obtain the query results respectively, and write them into the structured task chain. The result aggregation and response generation module is used to input the structured task chain into a preset result aggregation agent, which generates a response to the user's question based on the query results and the aggregation sub-tasks.
13. A central air conditioning display terminal, characterized in that: The central air conditioning display terminal operates the database question-and-answer assistant construction system as described in any one of claims 12.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps of the database question-answering assistant construction method according to any one of claims 1-11.
Citation Information
Patent Citations
Intelligent SQL query generation method and system based on large language model
CN118861081A
Data query method and device based on task planning and storage medium
CN119782334A
Response content generation method and device, storage medium and program product
CN120579629A
Database interaction method and device based on multi-agent cooperation, equipment and medium
CN120821738A