Electricity marketing data query system and method based on multi-agent and knowledge base

By adopting a multi-level collaborative architecture based on the Langgraph intelligent agent framework, the accuracy issues of custom queries and complex queries in the power marketing database query system were resolved, achieving efficient and accurate power marketing data processing and display.

CN122309539APending Publication Date: 2026-06-30STATE GRID SHANGHAI MUNICIPAL ELECTRIC POWER CO

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
STATE GRID SHANGHAI MUNICIPAL ELECTRIC POWER CO
Filing Date
2026-03-25
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

Existing power marketing database query systems cannot meet customized query needs, lack vertical domain knowledge, and basic intelligent query products have low accuracy when processing complex queries, and lack collaboration and verification mechanisms.

Method used

A multi-level collaborative architecture based on the Langgraph agent framework is adopted, including a data layer, a knowledge layer, an agent layer, a tool layer, a memory layer, and an interaction layer. Through multiple agents and knowledge bases with different functions and tasks, high accuracy and strong adaptability of complex power marketing data can be achieved.

Benefits of technology

It improved the success rate of handling complex problems by more than 30%, increased the accuracy of field recognition by 45%, reduced the operation threshold by 10 times, and achieved efficient querying and display of power marketing data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122309539A_ABST
    Figure CN122309539A_ABST
Patent Text Reader

Abstract

A data querying system for electricity marketing based on multi-agent and knowledge base is disclosed. The system constructs a multi-level collaborative architecture based on the Langgraph agent framework. This multi-level collaborative architecture includes independent data, knowledge, agent, tool, memory, and interaction layers. The data layer includes a database management platform and electricity marketing business data sources; the knowledge layer includes a vector database and an electricity marketing business rule base; the agent layer includes multiple agents with different functions and collaborate; the tool layer includes a prompt word management platform, an SQL code interpreter, and a unit conversion node module; the memory layer includes short-term memory and long-term memory modules; and the interaction layer includes a multi-turn dialogue module and a result display module. This invention also provides a querying method that achieves high accuracy and strong adaptability in processing complex electricity marketing data, with significant advantages.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electricity marketing data processing technology, specifically to an electricity marketing data query system and method based on multi-agent and knowledge base. Background Technology

[0002] In power data management, existing database query systems have the following shortcomings: First, traditional business systems are rigid and cannot meet the needs of customized queries; second, general BI tools lack vertical domain knowledge and cannot achieve true natural language interaction; third, rudimentary intelligent query products are based on a single model, lack collaboration and verification mechanisms, and have low accuracy when processing complex queries.

[0003] Therefore, there is an urgent need to propose an intelligent question-and-answer solution that can deeply integrate domain knowledge and possess collaborative reasoning and self-correction capabilities.

[0004] It is understood that the above statements only provide background information related to the present invention and do not necessarily constitute prior art. Summary of the Invention

[0005] The purpose of this invention is to provide a system and method for querying electricity marketing data based on multiple agents and a knowledge base, achieving high accuracy and strong adaptability in processing complex electricity marketing data queries.

[0006] To achieve the above objectives, the present invention provides a power marketing data query system based on multiple agents and a knowledge base. The system is based on the Langgraph agent framework to build a multi-level collaborative architecture, which includes mutually independent data layer, knowledge layer, agent layer, tool layer, memory layer and interaction layer.

[0007] The data layer includes a database management platform and a power marketing business data source; the knowledge layer includes a vector database and a power marketing business rule base; the intelligent agent layer includes multiple collaborative intelligent agents, including at least: a tool invocation agent, an SQL result debugging and verification rewriting agent, and a data visualization chart agent; the tool layer includes a prompt word management platform, an SQL code interpreter, and a unit conversion node module; the memory layer includes a short-term memory module and a long-term memory module; and the interaction layer includes a multi-turn dialogue module and a result display module.

[0008] Preferably, the power marketing business data source includes at least a user basic information table and a large user billing table.

[0009] Preferably, the data layer is further configured with a data cleaning module and a data import module to remove invalid billing data and duplicate user information.

[0010] Preferably, the knowledge layer adopts a "dual-path storage" strategy for the rules of the power marketing business rule base; wherein, a part of the business rules are stored in a vector database for real-time retrieval and calling by the intelligent agent, and the other part of the business rules are configured as instant prompt words of the prompt word management platform in the tool layer, and are only embedded in the process when the user asks a question that matches the corresponding business scenario, so as to realize the adaptation of business rules and question scenarios.

[0011] Preferably, the SQL result debug and verification rewrite agent has a retry mechanism. When the SQL query statement fails to execute, the correction process is automatically triggered, and the maximum number of retries is a preset N, where N is an integer greater than or equal to 1.

[0012] Preferably, the data visualization chart intelligent agent supports the generation of multi-dimensional line charts, stacked bar charts, pie charts, and scatter plots to adapt to the display needs of different types of electricity marketing data.

[0013] This invention also provides a method for estimating electricity marketing data based on multi-agent and knowledge base, the method specifically including: S1. Receive natural language questions from users through the interaction layer; S2. Call the intelligent agent through the tools of the intelligent agent layer to recall and query the relevant business rules and data table structures from the knowledge layer and data layer; S3. Determine whether the query is a data query request; If so, then rewrite the agent to perform the following steps through SQL result debugging and validation: S31. Generate SQL logical descriptions based on thought chain reasoning; S32. Generate an SQL query statement based on the SQL logical description; S33. Verify and correct the SQL query statement; S4. Execute the revised SQL query statement, obtain the result data from the data layer, and then convert the result through the tool layer before formatting the content to answer; S5. The data visualization chart agent determines whether the result data is suitable for visualization display. If it is suitable, the corresponding chart is generated. S6. Return the final query result to the user through the interaction layer.

[0014] Preferably, in step S33, the specific steps include: S331, using the "think-act-observe" logic of the React framework and combining it with the power marketing business rules to diagnose errors in the SQL query statement; S332, calling the debugging tool to correct the error based on the diagnosis result; S333, re-verifying the corrected SQL query statement to form a closed-loop verification process.

[0015] Preferably, before step S31, a context judgment step is also included: determining whether the current user query depends on the context information of the historical dialogue; if it does, the user question is redescribed to integrate the context information before generating the SQL logical description.

[0016] Preferably, the method further includes a self-evolution process, specifically: collecting user feedback on query results, newly added business rules and data, and using this information to iteratively optimize the model of the intelligent agent layer in order to update its business rule recognition capability and SQL generation logic.

[0017] In summary, compared with the prior art, the electricity marketing data query system and method based on multi-agent and knowledge base provided by the present invention has at least the following beneficial effects: (1) This invention abandons the traditional single large model driven mode and builds a multi-agent collaborative system of "tool call-SQL description-SQL generation-SQL debugging-data visualization" based on the LangGraph framework. It breaks down complex power marketing data query into controllable steps of "data retrieval → SQL description → SQL generation → verification → chart generation". By solidifying the process, it avoids the uncertainty of single model generation. The success rate of handling complex problems is more than 30% higher than that of traditional Test2SQL. (2) This invention innovatively adds the "SQL description" step, which clarifies the query target and logic through the CoT reasoning, reducing semantic deviation. At the same time, it introduces a dynamic real-time prompt word module, which embeds the corresponding rules only when the user asks a question matching a specific scenario. This avoids redundant information from increasing the cognitive load of the model, and ensures the accurate adaptation of electricity marketing-specific terms and business rules. The field recognition accuracy is 45% higher than that of the traditional model. (3) This invention combines the “think-action-observation” logic of the React framework with the SQL Debug tool for electricity marketing. It achieves closed-loop processing of “error reasoning → automatic correction → result verification” for common problems such as “field error”, “syntax error”, and “business rule inconsistency”. It can solve more than 90% of SQL execution failure problems with a maximum of 3 retries, which is 10 times more efficient than traditional manual debugging and greatly reduces the operation threshold for grassroots marketing personnel. Attached Figure Description

[0018] Figure 1 This is an architecture diagram of the power marketing data query system based on multi-agent and knowledge base in this invention; Figure 2 This is a flowchart of the electricity marketing data query method based on multi-agent and knowledge base in this invention. Detailed Implementation

[0019] The present invention will be further described below with reference to the accompanying drawings and by providing a detailed description of a preferred embodiment.

[0020] It should be noted that the accompanying drawings are in a very simplified form and use non-precise proportions. They are only used to facilitate and clarify the purpose of illustrating the embodiments of the present invention, and are not intended to limit the implementation conditions of the present invention. Therefore, they have no substantial technical significance. Any modifications to the structure, changes in the proportional relationship, or adjustments to the size should still fall within the scope of the technical content disclosed in the present invention, provided that they do not affect the effects and objectives that the present invention can produce.

[0021] It should be noted that, in this invention, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only the expressly listed elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus.

[0022] like Figure 1 As shown, the present invention provides a power marketing data query system based on multiple agents and a knowledge base. The system is based on the Langgraph agent framework to build a multi-level collaborative architecture, which includes mutually independent data layer, knowledge layer, agent layer, tool layer, memory layer and interaction layer.

[0023] The data layer includes the Clickhouse database management platform and the power marketing business data source, which are used to store and preprocess tens of millions of power marketing business data, and provide underlying data support for the execution of SQL query statements. The knowledge layer includes a Milvus vector database and an electricity marketing business rule base, which are used to store electricity marketing business knowledge, data table structure and business rules, and provide knowledge retrieval services for intelligent agents. The intelligent agent layer includes multiple intelligent agents with different functions and functions. The intelligent agents include at least: a tool calling intelligent agent for recalling the data table structure and industry data in the knowledge layer; an SQL result debugging and verification rewriting intelligent agent for verifying the correctness of SQL query statements and automatically correcting erroneous SQL query statements; and a data visualization chart intelligent agent for visualizing the query results. The tool layer includes the Nacos prompt word management platform, the SQL code interpreter, and the unit conversion node module, which are used to manage the prompt word library, execute SQL query statements, and automatically process data unit conversions, respectively. The tools in the tool layer will perform corresponding tasks according to the agent's flow to the SQL execution point and the data conversion node, and the prompt words can be updated or modified at any time without affecting the operation of the entire project. The memory layer includes a short-term memory module and a long-term memory module. The short-term memory module stores user history dialogues based on the Langgraph framework, while the long-term memory module stores data dictionaries, indicator dictionaries, and business knowledge for electricity marketing, enabling multi-round questioning and knowledge reuse. The interaction layer includes a multi-turn dialogue module and a result display module, which are used to realize user natural language input and display the results of the questions, respectively.

[0024] Furthermore, the power marketing business data source includes at least a user basic information table and a large user billing table, with the user basic information table containing 37 fields and the large user billing table containing 51 fields.

[0025] In a preferred embodiment of the present invention, the knowledge of electricity marketing business includes: basic electricity fees, new gains and losses from electricity price cross-subsidies, etc.; and in the present invention, 36 marketing business rules are set, including various aspects such as market-oriented users, residential charging piles, and charging and swapping.

[0026] Furthermore, the data layer is also equipped with a data cleaning module and a data import module, which are used to remove invalid billing data and duplicate user information, improve the quality of the underlying data, realize the standardization and automation of data updates, and reduce errors caused by manual intervention.

[0027] Furthermore, the knowledge layer adopts a "dual-path storage" strategy for the rules of the power marketing business rule base; one part of the business rules are stored in the Milvus vector database for real-time retrieval and calling by the intelligent agent, and the other part of the business rules are configured as instant prompt words of the Nacos prompt word management platform in the tool layer, and are only embedded in the process when the user asks a question that matches the corresponding business scenario, so as to realize the adaptation of business rules and question scenarios.

[0028] Furthermore, the SQL result debug and verification rewrite agent has a retry mechanism. When the SQL query statement fails to execute, a correction process is automatically triggered, and the maximum number of retries is a preset N, where N is an integer greater than or equal to 1. In a preferred embodiment of the present invention, N is set to 3.

[0029] Furthermore, the data visualization chart intelligence agent supports the generation of at least six types of charts, including multi-dimensional line charts, stacked bar charts, pie charts, and scatter plots, to adapt to the display needs of different types of electricity marketing data.

[0030] It is understood that, in the tool layer, the management prompt word library in the Nacos prompt word management platform supports dynamic updates to obtain the latest prompt words; the specific application of the unit conversion node module is to automatically convert the data unit of the query result into the unit specified in the user query or conforming to business conventions, such as the conversion of "kilowatt-hour → ten thousand kilowatt-hours".

[0031] like Figure 2 As shown, this invention also provides a method for querying electricity marketing data based on multi-agent and knowledge base, implemented using the above-described system. The method specifically includes: S1. Receive natural language questions from users through the interaction layer; S2. Call the intelligent agent through the tools of the intelligent agent layer to recall and query the relevant business rules and data table structures from the knowledge layer and data layer; S3. Determine whether the query is a data query request; If so, then rewrite the agent to perform the following steps through SQL result debugging and validation: S31. Generate SQL logical descriptions based on thought chain reasoning; S32. Generate an SQL query statement based on the SQL logical description; S33. Verify and correct the SQL query statement; S4. Execute the revised SQL query statement, obtain the result data from the data layer, and then convert the result through the tool layer before formatting the content to answer; S5. The data visualization chart agent determines whether the result data is suitable for visualization display. If it is suitable, the corresponding chart is generated. S6. Return the final query result to the user through the interaction layer.

[0032] Furthermore, in step S3, if not, then directly provide a formatted response and continue to step S5.

[0033] Furthermore, in step S33, the specific steps for validating and correcting the SQL query statement include: S331. Using the "think-act-observe" logic of the React framework, combined with the rules of electricity marketing business, perform error diagnosis on SQL query statements; S332. Use debugging tools to make corrections based on the diagnostic results; S333. The revised SQL query statement is verified again to form a closed-loop verification process.

[0034] It should be noted that in this invention, the verification process can be retried a maximum of 3 times; if it still fails after 3 retries, an error message will be returned and the problem type will be recorded for subsequent model iterations.

[0035] Furthermore, before step S31, a context judgment step is included: determining whether the current user query depends on the context information of the historical dialogue; if it depends, the user question is redescribed to integrate the context information before generating the SQL logical description; if it does not depend, step S31 is started directly.

[0036] Furthermore, the method also includes a self-evolution process, which is manifested in: collecting user feedback on query results, new business rules and data, and using this information to iteratively optimize the model of the intelligent agent layer in order to update its business rule recognition capabilities and SQL generation logic.

[0037] In summary, this invention provides a multi-agent and knowledge-based system and method for querying electricity marketing data. Firstly, it abandons the traditional single large model-driven model and constructs a multi-agent collaborative system based on the LangGraph framework, encompassing "tool invocation - SQL description - SQL generation - SQL debugging - data visualization." This breaks down complex electricity marketing data queries into controllable steps of "data retrieval → SQL description → SQL generation → verification → chart generation." By solidifying the process, it avoids the uncertainty of single-time model generation, improving the success rate of handling complex problems by more than 30% compared to traditional Test2SQL. Secondly, it innovatively adds an "SQL description" stage, clarifying the query target and logic through CoT reasoning, reducing semantic bias. Simultaneously, it introduces a dynamic, real-time prompt word module, embedding corresponding rules only when the user's question matches a specific scenario. This avoids redundant information increasing the model's cognitive load while ensuring accurate adaptation of electricity marketing-specific terminology and business rules, improving field recognition accuracy by 45% compared to traditional methods. Thirdly, it integrates the "think-act-observe" logic of the React framework with electricity marketing-specific SQL. Combined with debugging tools, it achieves a closed-loop processing of "error reasoning → automatic correction → result verification" for common problems such as "field errors", "syntax errors" and "business rule inconsistencies". It can solve more than 90% of SQL execution failure problems with a maximum of 3 retries, which is 10 times more efficient than traditional manual debugging and significantly reduces the operation threshold for front-line marketing personnel.

[0038] Although the present invention has been described in detail through the preferred embodiments above, it should be understood that the above description should not be considered as a limitation of the present invention. Various modifications and substitutions to the present invention will be apparent to those skilled in the art after reading the above description. Therefore, the scope of protection of the present invention should be defined by the appended claims.

Claims

1. A data query system for electricity marketing based on multi-agent and knowledge base, characterized in that, The system is based on the Langgraph agent framework to build a multi-level collaborative architecture, which includes mutually independent data layer, knowledge layer, agent layer, tool layer, memory layer and interaction layer. The data layer includes a database management platform and a power marketing business data source; the knowledge layer includes a vector database and a power marketing business rule base; the agent layer includes multiple collaborative agents, including at least: a tool invocation agent, an SQL result debugging and verification rewriting agent, and a data visualization chart agent; the tool layer includes a prompt word management platform, an SQL code interpreter, and a unit conversion node module; the memory layer includes a short-term memory module and a long-term memory module; and the interaction layer includes a multi-turn dialogue module and a result display module.

2. The power marketing data query system based on multi-agent and knowledge base as described in claim 1, characterized in that, The data source for the electricity marketing business includes at least a user basic information table and a large user billing table.

3. The power marketing data query system based on multi-agent and knowledge base as described in claim 2, characterized in that, The data layer is also equipped with a data cleaning module and a data import module, which are used to remove invalid billing data and duplicate user information.

4. The power marketing data query system based on multi-agent and knowledge base as described in claim 1, characterized in that, The knowledge layer employs a "dual-path storage" strategy for the rules in the power marketing business rule base. Some of the business rules are stored in a vector database for real-time retrieval and invocation by the intelligent agent, while others are configured as instant prompt words in the prompt word management platform in the tool layer. These prompt words are only embedded in the process when the user asks a question that matches the corresponding business scenario, thus achieving the adaptation of business rules to question scenarios.

5. The power marketing data query system based on multi-agent and knowledge base as described in claim 1, characterized in that, The SQL result debug and verification rewrite agent has a retry mechanism. When the SQL query statement fails to execute, the correction process is automatically triggered, and the maximum number of retries is a preset N, where N is an integer greater than or equal to 1.

6. The power marketing data query system based on multi-agent and knowledge base as described in claim 1, characterized in that, The data visualization chart agent supports the generation of multi-dimensional line charts, stacked bar charts, pie charts, and scatter plots to adapt to the display needs of different types of electricity marketing data.

7. A method for querying electricity marketing data based on multi-agent and knowledge base, implemented using the system described in any one of claims 1 to 6, characterized in that, The method specifically includes: S1. Receive natural language questions from users through the interaction layer; S2. Call the intelligent agent through the tools of the intelligent agent layer to recall and query the relevant business rules and data table structures from the knowledge layer and data layer; S3. Determine whether the query is a data query request; If so, then rewrite the agent to perform the following steps through SQL result debugging and validation: S31. Generate SQL logical descriptions based on thought chain reasoning; S32. Generate an SQL query statement based on the SQL logical description; S33. Verify and correct the SQL query statement; S4. Execute the revised SQL query statement, obtain the result data from the data layer, and then convert the result through the tool layer before formatting the content to answer; S5. The data visualization chart agent determines whether the result data is suitable for visualization display. If it is suitable, the corresponding chart is generated. S6. Return the final query result to the user through the interaction layer.

8. The electricity marketing data query method based on multi-agent and knowledge base as described in claim 7, characterized in that, In step S33, the specific steps include: S331. Utilize the "think-act-observe" logic of the React framework, combined with the rules of electricity marketing business, to perform error diagnosis on SQL query statements; S332. Use debugging tools to make corrections based on the diagnostic results; S333. The revised SQL query statement is verified again to form a closed-loop verification process.

9. The electricity marketing data query method based on multi-agent and knowledge base as described in claim 7, characterized in that, Before step S31, a context judgment step is also included: determining whether the current user query depends on the context information of the historical dialogue; If dependent, the user question is redescribed to integrate contextual information before generating the SQL logical description.

10. The electricity marketing data query method based on multi-agent and knowledge base as described in claim 7, characterized in that, The method also includes a self-evolution process, specifically: Collect user feedback on query results, new business rules and data, and use this information to iteratively optimize the model of the intelligent agent layer in order to update its business rule recognition capabilities and SQL generation logic.