Data analysis methods, devices, media, and software products based on large language models
By detecting structured tags in real time and displaying confirmation cards during the data analysis process of a large language model, obtaining target query parameters, and performing capacity control in iterative analysis, the problems of analysis interruption and inaccurate query results caused by context window limitations are solved, thus improving the efficiency and accuracy of data analysis.
Patent Information
- Application Number
- CN202611009192.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-07
- Publication Date
- 2026-11-17
AI Technical Summary
In the process of data analysis based on large language models, deep attribution analysis is prone to interruption due to context window limitations, and the accuracy of query results is not high. In particular, when user input is ambiguous, there is a lack of effective structured interactive confirmation mechanisms, which leads to problems with the continuity and accuracy of analysis.
By detecting structured labels to display confirmation cards during the inference process flow, the target query parameters are obtained after confirmation. Capacity control operations are performed in the iterative analysis, including maintaining a finite state machine, caching query parameters, and generating structured summaries, to ensure the accuracy of query parameters and the continuity of iterative analysis.
It enables accurate confirmation of query parameters during data analysis, reduces the probability of result deviation, maintains the continuity of reasoning state in multi-round iterative analysis, and improves the execution efficiency of data analysis tasks and the accuracy of analysis conclusions.
Smart Images

Figure CN123117313A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a data analysis method based on a large language model, an electronic device, a readable storage medium, and a computer program product. Background Technology
[0002] In the field of enterprise data analytics, especially in the service operations of online travel platforms, data analysis has become a core element driving decision-making. During the analysis process, operations personnel need to frequently query key metrics such as GMV (Gross Merchandise Volume), order volume, and conversion rates, and analyze them according to dimensions such as service lines, destinations, and time periods. This data analysis requires operations personnel to be proficient in various technical skills, including SQL (Structured Query Language) writing, BI (Business Intelligence) tool operation, and Python data processing, making it difficult for them to complete the task independently.
[0003] With the development of large language model technology, data analysis agents based on natural language dialogue have gradually become the corresponding solutions. By building a corresponding agent architecture, they realize full-link automation from user natural language input to data query, calculation and analysis, and visualization report generation, which significantly reduces the technical threshold of data analysis and compresses the traditional analysis process that takes several hours to minutes of interaction.
[0004] However, in practical applications, data analysis agent solutions based on large language models face at least two key problems: First, during deep attribution analysis, a single analysis often generates 5-7 query results and 3-5 Python script execution outputs. The accumulated dialogue content from multiple rounds quickly consumes the model's context window capacity. When the context window limit is exceeded, the analysis process is forced to be interrupted, and the user needs to restart the entire analysis process, which seriously undermines the continuity of the analysis and the user experience. Second, when user input is ambiguous (e.g., the service metric "GMV" may refer to order GMV or fulfillment GMV, or the time range may be unclear), the relevant solutions lack an effective structured interactive confirmation mechanism. The system often directly guesses the query conditions and executes them, resulting in query results that are inconsistent with service expectations, leading to decision bias. Furthermore, users cannot edit and confirm parameters such as metrics, dimensions, and filtering conditions item by item before query execution. Summary of the Invention
[0005] This application provides a data analysis method, apparatus, electronic device, and readable storage medium based on a large language model to solve or partially solve the problems of easy interruption of in-depth analysis and low accuracy of query results due to the limitation of context windows during data analysis.
[0006] This application discloses a data analysis method based on a large language model, including: In response to a user's query request, if a structured tag carrying candidate query parameters is detected in the inference process flow corresponding to the query request, a confirmation card for the structured tag is displayed. In response to the confirmation operation for the confirmation card, the target query parameters after confirmation are obtained, and the data query operation corresponding to the target query parameters is executed to obtain the corresponding query return result; During the iterative analysis based on the query results, a capacity control operation is performed on the dialogue history context of the iterative analysis, and a visualization report corresponding to the query request is output after the iterative analysis is completed.
[0007] In some feasible implementations, displaying the confirmation card for the structured label includes: Display the reasoning process flow corresponding to the query request; During the token sequence output process of the inference process flow, a finite state machine is maintained, which includes at least one of an idle state, a buffer state, and a tag completion state. When the finite state machine is in an idle state, if the current token successfully matches the starting tag prefix of the structured tag, it enters the buffer state. In the buffer state, subsequent tokens are cached until the end tag of the structured tag is detected, after which the tag completion state is entered. The content between the start tag and the end tag is extracted as the candidate query parameter, and a confirmation card for the candidate query parameter is displayed.
[0008] In some feasible implementations, performing capacity control operations on the dialogue history context of the iterative analysis includes: Metadata query results are extracted from the historical dialogue context and marked as protected content. The protected content is not removed or compressed during the capacity control operation. The metadata query results include at least one of the following: a list of available metrics, a list of available dimensions, and a list of available filter options. And / or, before each round of inference invocation, detect duplicate tool call records in the historical dialogue context, and replace duplicate call results with the same tool name and the same input parameters in the duplicate tool call records with reference markers pointing to the most recent call result; And / or, before each round of inference invocation, estimate the current number of tokens in the historical dialogue context. If the current number of tokens is greater than or equal to a preset compression threshold, then take the historical dialogue messages in the dialogue history context, excluding the protected content and the original dialogue messages from the most recent preset rounds, as the target dialogue messages to be compressed. Determine the structured summary of the target dialogue messages, replace the target dialogue messages with the structured summary, and re-inject the protected content into the compressed dialogue history context.
[0009] In some feasible implementations, determining the structured summary of the target dialogue message includes: Send a summary generation request carrying the target dialogue message to the large language model. The summary generation request is used to instruct the large language model to generate a structured summary according to at least one of the following dimensions: user intent and feedback dimension, completed query and calculation dimension, analysis discovery and attribution path dimension, error and repair dimension, and current progress and next step plan dimension. Receive a structured summary of the target dialogue message returned by the large language model.
[0010] In some feasible implementations, after obtaining the corresponding query return results, the method further includes: Convert the query results into a structured data file; The structured data files are distributed to local storage in the isolated computing environment; When calling code execution tools to perform data computation, the isolated computing environment reads the structured data file from the local storage through pre-injected runtime auxiliary code; The pre-injected runtime helper code includes at least one of a data loading function, a file upload function, and a cross-script variable sharing function. Each instance in the instance pool of the isolated computing environment loads the pre-injected runtime helper code during initialization. The data loading function is used to read the structured data file from the local storage and convert it into a data frame object. The file upload function is used to upload the computation result file to persistent data storage. The cross-script variable sharing function is used to pass variables between multiple code execution calls.
[0011] In some feasible implementations, the method further includes: In response to invoking the code execution tool, the script code to be executed is obtained, and a query identifier is detected in the script code, the query identifier being used to point to the target query return result; If the structured data file corresponding to the query identifier does not exist in the local storage of the isolated computing environment, the target query result is read from the persistent data storage. Convert the results returned by the target query into a target structured data file; The target structured data file is uploaded to the local storage.
[0012] In some feasible implementations, the method further includes: During the inference process flow and / or the inference process of the iterative analysis, inference events and tool call events are received; Convert inference events and tool call events into target event streams that are adapted to different protocol formats; During the transmission of the target event stream, in response to the end of this inference output, a termination processing operation is performed on the target event stream, and a heartbeat event is sent periodically during the connection maintenance period.
[0013] In some feasible implementations, after responding to a user-input query request, the method further includes: Obtain a target summary of at least one domain knowledge module corresponding to the query request; Inject the target summary into the system prompt word; If the query request is detected to match the target domain knowledge module, the complete content corresponding to the target domain knowledge module is obtained and stored in the dialogue history context.
[0014] In some feasible implementations, the visualization report includes at least one of the following visualization elements: An interactive chart generated using the query results; Charts and images generated by code execution tools; The report document generated by the code execution tool.
[0015] This invention also discloses a data analysis device based on a large language model, comprising: The confirmation card display module is used to respond to a query request input by the user. If a structured tag carrying candidate query parameters is detected in the inference process flow corresponding to the query request, a confirmation card for the structured tag is displayed. The query execution module is used to respond to the confirmation operation for the confirmation card, obtain the confirmed target query parameters, and execute the data query operation corresponding to the target query parameters to obtain the corresponding query return result; The capacity control module is used to perform capacity control operations on the dialogue history context of the iterative analysis during the process of iterative analysis based on the query return results. The report output module is used to output a visual report corresponding to the query request after the iterative analysis is completed.
[0016] In some feasible implementations, the confirmation card display module is specifically used for: Display the reasoning process flow corresponding to the query request; During the token sequence output process of the inference process flow, a finite state machine is maintained, which includes at least one of an idle state, a buffer state, and a tag completion state. When the finite state machine is in an idle state, if the current token successfully matches the starting tag prefix of the structured tag, it enters the buffer state. In the buffer state, subsequent tokens are cached until the end tag of the structured tag is detected, after which the tag completion state is entered. The content between the start tag and the end tag is extracted as the candidate query parameter, and a confirmation card for the candidate query parameter is displayed.
[0017] In some feasible implementations, the capacity control module is specifically used for: Metadata query results are extracted from the historical dialogue context and marked as protected content. The protected content is not removed or compressed during the capacity control operation. The metadata query results include at least one of the following: a list of available metrics, a list of available dimensions, and a list of available filter options. And / or, before each round of inference invocation, detect duplicate tool call records in the historical dialogue context, and replace duplicate call results with the same tool name and the same input parameters in the duplicate tool call records with reference markers pointing to the most recent call result; And / or, before each round of inference invocation, estimate the current number of tokens in the historical dialogue context. If the current number of tokens is greater than or equal to a preset compression threshold, then take the historical dialogue messages in the dialogue history context, excluding the protected content and the original dialogue messages from the most recent preset rounds, as the target dialogue messages to be compressed. Determine the structured summary of the target dialogue messages, replace the target dialogue messages with the structured summary, and re-inject the protected content into the compressed dialogue history context.
[0018] In some feasible implementations, the capacity control module is specifically used for: Send a summary generation request carrying the target dialogue message to the large language model. The summary generation request is used to instruct the large language model to generate a structured summary according to at least one of the following dimensions: user intent and feedback dimension, completed query and calculation dimension, analysis discovery and attribution path dimension, error and repair dimension, and current progress and next step plan dimension. Receive a structured summary of the target dialogue message returned by the large language model.
[0019] In some feasible implementations, the apparatus further includes a data preheating module, used after the query execution module obtains the corresponding query return result: Convert the query results into a structured data file; The structured data files are distributed to local storage in the isolated computing environment; When calling code execution tools to perform data computation, the isolated computing environment reads the structured data file from the local storage through pre-injected runtime auxiliary code; The pre-injected runtime helper code includes at least one of a data loading function, a file upload function, and a cross-script variable sharing function. Each instance in the instance pool of the isolated computing environment loads the pre-injected runtime helper code during initialization. The data loading function is used to read the structured data file from the local storage and convert it into a data frame object. The file upload function is used to upload the computation result file to persistent data storage. The cross-script variable sharing function is used to pass variables between multiple code execution calls.
[0020] In some feasible implementations, the data preheating module is also used for: In response to invoking the code execution tool, the script code to be executed is obtained, and a query identifier is detected in the script code, the query identifier being used to point to the target query return result; If the structured data file corresponding to the query identifier does not exist in the local storage of the isolated computing environment, the target query result is read from the persistent data storage. Convert the results returned by the target query into a target structured data file; The target structured data file is uploaded to the local storage.
[0021] In some feasible implementations, the device further includes a protocol adaptation module, used for: During the inference process flow and / or the inference process of the iterative analysis, inference events and tool call events are received; Convert inference events and tool call events into target event streams that are adapted to different protocol formats; During the transmission of the target event stream, in response to the end of this inference output, a termination processing operation is performed on the target event stream, and a heartbeat event is sent periodically during the connection maintenance period.
[0022] In some feasible implementations, the apparatus further includes a domain knowledge loading module, used after the confirmation card display module responds to a user-input query request: Obtain a target summary of at least one domain knowledge module corresponding to the query request; Inject the target summary into the system prompt word; If the query request is detected to match the target domain knowledge module, the complete content corresponding to the target domain knowledge module is obtained and stored in the dialogue history context.
[0023] In some feasible implementations, the visualization report includes at least one of the following visualization elements: An interactive chart generated using the query results; Charts and images generated by code execution tools; The report document generated by the code execution tool.
[0024] This application also discloses an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; The memory is used to store computer programs; When the processor executes a program stored in the memory, it implements the method described in the embodiments of this application.
[0025] This application also discloses a readable storage medium storing instructions that, when executed by one or more processors, cause the processors to perform the methods described in this application.
[0026] This application also discloses a computer program product, including computer execution instructions, which, when executed by a processor, implement the method described in this application.
[0027] The embodiments of this application have the following advantages: In this embodiment, during the data analysis process, the data analysis system first responds to the user's input query request. If a structured tag carrying candidate query parameters is detected in the inference process flow corresponding to the query request, a confirmation card for the structured tag is displayed. Then, in response to the confirmation operation for the confirmation card, the confirmed target query parameters are obtained, and the data query operation corresponding to the target query parameters is executed to obtain the corresponding query return result. During the iterative analysis based on the query return result, a capacity control operation is performed on the dialogue history context of the iterative analysis. After the iterative analysis is completed, a visual report corresponding to the query request is output. Thus, through the real-time detection of structured tags in the inference process flow and the human-computer interaction mechanism of the confirmation card, not only is the confirmation of the query before execution achieved, but the probability of result deviation caused by ambiguity of query parameters can also be reduced. Furthermore, through the capacity control operation of the dialogue history context, the continuity and integrity of the inference state during multiple rounds of iterative analysis can be effectively maintained. At the same time, through the fully automated closed loop from data query to iterative analysis to report output, the execution efficiency of the data analysis task and the accuracy of the analysis conclusion are significantly improved. Attached Figure Description
[0028] Figure 1 This is a flowchart illustrating the steps of a data analysis method based on a large language model provided in the embodiments of this application; Figure 2 This is a schematic diagram of the system structure provided in the embodiments of this application; Figure 3 This is an interactive flowchart of the streaming label and caliber confirmation mechanism provided in the embodiments of this application; Figure 4 This is a schematic diagram of the capacity control operation provided in the embodiments of this application; Figure 5 This is a structural block diagram of a data analysis device based on a large language model provided in the embodiments of this application. Detailed Implementation
[0029] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0030] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0031] As examples, in various scenarios requiring data querying and intelligent analysis, users (such as service personnel, data analysts, or operations personnel) frequently need to query core operational indicators and perform drill-down analysis and attribution investigations across different dimensions. In related technologies, completing an attribution analysis typically requires manually writing SQL statements to extract data, then importing the query results into spreadsheets or BI tools for secondary calculations and chart creation, ultimately generating an analysis report. The entire process, from "posing a question" to "obtaining a conclusion," usually takes several hours or even days. Existing Text-to-SQL solutions based on large language models can only complete a single data query. They cannot autonomously determine the next analytical direction based on intermediate query results, nor can they complete analytical tasks requiring multiple calculations, such as growth rate calculations and contribution breakdowns. Therefore, they cannot support a complete attribution analysis process. Furthermore, the intensive tool calls in data analysis scenarios cause the context window of large language models to be quickly exhausted. Completing an attribution analysis usually requires multiple data queries and multiple calculations. The return results and inference text of each tool call continuously occupy the context window. When the number of context tokens exceeds the upper limit of the model window, the existing solution can only simply discard the earliest historical messages. However, the early query results of data analysis (such as overall trend data) are often the reference basis for subsequent drill-down analysis. Once lost, it will cause the analysis logic chain to break and the in-depth analysis to be interrupted.
[0032] In response, this application employs a single-agent architecture driven by a large language model. When the data analysis system receives a query request from a user, it can detect structured tags in real time during the inference process to confirm the definition, execute the query based on the confirmed parameters, perform capacity control on the dialogue history context during iterative analysis, and output a visual report after the iterative analysis is completed. Thus, through a complete closed loop of "definition confirmation - iterative analysis - capacity control - report output", the entire process from user question to analysis conclusion is automated.
[0033] Furthermore, during the caliber confirmation phase, the data analysis system maintains a finite state machine during the token sequence output process of the inference flow, detects the boundaries of the start and end tags in real time, extracts the candidate query parameters carried within the tags, and generates confirmation cards for users to check and edit item by item, ensuring the accuracy of the query parameters. In addition, during the capacity control phase, the data analysis system marks the metadata query results as protected content before each round of inference calls and prevents them from being compressed or removed. It deduplicates the results of repeated calls with the same tool name and the same input parameters, retaining only the most recent record. When the number of tokens in the dialogue history context reaches a preset compression threshold, it calls the large language model to generate a structured summary, replaces the compressed historical messages with the summary and the original messages from the most recent preset rounds, and re-injects the protected content into the compressed dialogue history context. This way, while compressing the historical dialogue, it retains the key analysis state and maintains the integrity of the inference chain.
[0034] Furthermore, after the data query operation is completed, the asynchronous data preheating service converts the query results into structured data files and distributes them to the local storage of the isolated computing environment. This allows the code execution tool to read data directly from the local storage through pre-injected runtime auxiliary code when executing in the sandbox, achieving zero-latency data flow across execution environments. At the same time, a unified callback state machine converts inference events and tool call events into target event streams adapted to different protocol formats, and supports two standardized outputs: the front-end UI protocol and the inter-agent communication protocol, thereby realizing multi-protocol streaming output.
[0035] To enable those skilled in the art to better understand the technical solutions in the embodiments of this application, some technical features involved in the embodiments of this application are explained and described below: OLAP (Online Analytical Processing): A multidimensional data query technology for analysis, supporting aggregated queries by indicators, dimensions, and filtering conditions.
[0036] AG-UI Protocol (Agent-UI Interaction Protocol): The Agent-UI interaction protocol defines a standardized event system based on SSE (Server-Sent Events) between the Agent and the front end, including event types such as inference, tool invocation, and text output.
[0037] A2A Protocol (Agent-to-Agent Protocol): An inter-agent communication standard based on JSON-RPC over SSE.
[0038] MCP (Model Context Protocol): A standard protocol used by LLM (Model-View-Led) systems to access external tools and data sources. For example, data analysis systems can use the MCP protocol to access external search engines and other tools to obtain real-time external information during attribution analysis.
[0039] Sandbox: An isolated code execution environment. In this application, it refers to a Python runtime based on Kubernetes containers, possessing security features such as network isolation, resource limits, and timeout control. For example, when a data analysis system calls a code execution tool, the Python script to be executed is submitted to a sandbox instance for execution. The sandbox instance achieves process-level isolation from the host machine and other instances, ensuring that the execution process of the code generated by the LLM (Large Language Model) does not affect other tasks or system security.
[0040] Prelude Injection: The runtime helper code (prelude.py) is uploaded in advance when the sandbox container is initialized. It is loaded by exec when the script is executed, avoiding repeated transmission each time.
[0041] Data Preloading: After an OLAP query is completed, the result data is asynchronously uploaded to the sandbox instance so that the data is ready when the subsequent Python script is executed, reducing waiting time.
[0042] Definition Confirmation: Before executing a data query, the system automatically identifies ambiguous items in the query conditions (such as multiple meanings of indicators, ambiguity of time range, etc.) and confirms them with the user through structured cards to ensure that the query results meet service expectations.
[0043] Skill: A domain knowledge module defined in Markdown document format, including analysis methodologies, code generation standards, etc., which is loaded into the context on demand by the LLM to guide its behavior. In addition, this solution also encapsulates its complete data analysis capabilities into an installable Skill package (zip format), supporting cross-platform distribution to third-party intelligent agents.
[0044] Context Window: The maximum number of tokens that a large language model can process in a single inference. If this number is exceeded, the model cannot perceive earlier dialogue content, resulting in a loss of analytical coherence.
[0045] Context Compaction: When the number of dialogue tokens approaches the upper limit of the context window, a structured summary of the historical dialogue is generated using LLM, and the original messages are replaced with the summary to release the context space to continue the dialogue.
[0046] Reference Figure 1 The diagram illustrates a flowchart of a data analysis method based on a large language model provided in an embodiment of this application, which may specifically include the following steps: Step 101: In response to a query request input by the user, if a structured tag carrying candidate query parameters is detected in the inference process flow corresponding to the query request, a confirmation card for the structured tag is displayed. In this embodiment, the data analysis method can be applied to various scenarios requiring data querying and intelligent analysis. For example, users (such as service personnel, data analysts, or operations personnel) can input query requests in natural language form through a front-end interface, such as "Why did GMV decline in March?" or "Please check the performance of each service line yesterday." The front-end interface can be a web application, a mobile application, or a conversational analysis plugin integrated into a BI platform. After receiving the user's query request, the data analysis system can pass it as input to a large language model for inference.
[0047] Optionally, the query request entered by the user can take many forms. In some scenarios, the user can directly enter a natural language description, such as "Why did GMV decline in March?", and the data analysis system will pass this natural language description as is to the large language model for intent recognition.
[0048] In other scenarios, users can initiate queries by specifying an analysis template ID. The analysis template ID is used to associate pre-defined query conditions. For example, the "Daily Morning Meeting Data Report" template has pre-defined query parameters such as "Metrics: GMV, Order Quantity, Conversion Rate", "Dimension: By Service Line", and "Time Range: T-1". Users can trigger the query with one click by clicking the template button without having to re-enter natural language descriptions.
[0049] In other scenarios, users can also directly input structured query criteria JSON data. For example, they can copy confirmed query criteria from other systems and pass them in directly, skipping the natural language understanding and caliber confirmation process.
[0050] It should be noted that the data analysis system supports all three input methods mentioned above, providing users with a multi-level interactive entry point from natural language to precise parameters, and this application does not impose any restrictions on this.
[0051] Furthermore, after detecting a user-input query request, the data analysis system can preload the domain knowledge module corresponding to the query request. Optionally, the data analysis system can obtain a target summary of at least one domain knowledge module corresponding to the query request, then inject the target summary into the system prompt, and then, if the query request is detected to match the target domain knowledge module, obtain the complete content corresponding to the target domain knowledge module and store the complete content in the dialogue history context.
[0052] In its implementation, the data analysis system can maintain a knowledge base containing multiple domain-specific knowledge modules (Skills). Each domain-specific knowledge module can be defined in Markdown document format, including the analysis methodology, code generation standards, etc., for that domain. For example, the "Data Analysis Methodology" Skill includes the "hypothesis-validation-iteration" analysis framework, five major analysis paradigms (trend analysis, comparative analysis, structural analysis, attribution analysis, predictive analysis, etc.), and drill-down strategies; the "Python Code Generation Standards" Skill includes sandbox API calling standards (such as the correct usage of data loading functions, chart beautification parameter configuration), script template structure, etc. Each Skill file header contains YAML-formatted frontmatter metadata, recording the Skill's name, description, version number, and tags. Upon startup, the data analysis system scans all Skill files, parses the metadata in the frontmatter, and constructs a catalog summary containing only the names and descriptions of each Skill.
[0053] When a data analysis system receives a query request from a user, it first retrieves a summary of the domain knowledge modules corresponding to the query request and injects this summary into the system prompt (SystemPrompt) of the large language model. The system prompt also includes the data analysis system's role definition (e.g., "You are a data analysis assistant") and tool invocation specifications. Since the system prompt already contains the names and brief descriptions of all available skills when the large language model receives the query request, it knows which domain knowledge is currently available. However, because the summary only contains names and descriptions (not complete content), it does not consume a large amount of context space.
[0054] During the inference process, when the large language model determines that a certain domain knowledge module has guiding value for the current analysis task, it proactively calls the SkillTools tool (e.g., calling the getSkillContent tool, passing the Skill name as a parameter) to obtain the complete content of that target domain knowledge module. For example, when the large language model recognizes that the user's question "Why did GMV decline in March?" belongs to the attribution analysis task, it proactively calls getSkillContent("data-analysis-methodology") to obtain the complete content of the "Data Analysis Methodology" Skill, which includes the standard steps of attribution analysis and common drill-down paths. When the large language model is preparing to generate Python code to perform data calculations, it proactively calls getSkillContent("python-code-generation") to obtain the complete content of the "Python Code Generation Specification" Skill to understand the correct way to call the sandbox API. The data analysis system stores the obtained complete Skill content in the dialogue history context as the result of the tool call for the large language model to refer to in subsequent inference.
[0055] In the above process, a two-stage mechanism between "directory summary injection" and "on-demand full-text loading" is used to achieve a balance between domain knowledge and context window. If the complete content of all skills is injected into the system prompt words, the total number of skills can reach tens of thousands of tokens, which will occupy a lot of valuable context space. However, by injecting only the directory summary (which only contains the name and description, and each skill only costs about 50-100 tokens), the large language model can still know the scope of available knowledge and actively load the complete skill content when needed. This ensures the integrity of domain knowledge and maximizes the utilization of context window.
[0056] Furthermore, in response to user-inputted queries, the data analysis system can invoke the corresponding large language model to infer the query and obtain the corresponding query results. During the large language model inference process, it can generate output content token by token in a streaming manner. This output content is the inference process stream, which includes the inference text of the large language model, such as "I need to query the overall GMV trend in March, first view it by day", as well as structured tags interspersed in the inference text.
[0057] The structured tags can be predefined pairs of tags with a specific format. In the embodiments of this application, the structured tags can use XML-like or HTML-like tag formats, for example, <query-confirm> and< / query-confirm> As a start tag and an end tag.
[0058] Furthermore, the structured tags can also carry candidate query parameters in JSON format, such as "metrics":["GMV"], "dimensions":["by day"], "timeRange":"2026-03-01 to 2026-03-31", "comparePeriod":"same period last month", and "filters":{"businessLine":"all"}, etc. This application does not impose any restrictions on this.
[0059] Candidate query parameters are structured representations of query conditions automatically generated by the large language model based on the user's input query request. These parameters can include metrics (such as GMV, order volume, conversion rate), dimensions (such as by day, by service line, by destination), filtering conditions (such as specific service line or specific region), time range (such as March 1, 2026 to March 31, 2026), and comparison periods (such as the same period last month, the same period last year, etc.).
[0060] In the above process, the design of structured tags allows the inference text and structured data to be transmitted in parallel in the same streaming output. That is, the text outside the tags can be displayed to the user as inference content, while the JSON data inside the tags can be captured by the system and used in subsequent interaction processes. Furthermore, by parsing the structured tags in real time in the streaming output, it is also possible to realize the confirmation of the query criteria through human-computer collaboration, so that users can see the query criteria more intuitively, making it easier for users to check and edit item by item, and ensuring the accuracy of the query parameters.
[0061] Accordingly, during the receipt of the inference process flow, the data analysis system can detect in real time whether the inference process flow contains structured tags. If a corresponding structured tag is detected, indicating the existence of candidate query parameters that require user confirmation, the system can pause the data query operation corresponding to the candidate query parameter in the inference process flow, while maintaining the continuous display of other inference content besides the confirmation card, and displaying the confirmation card for the structured tag. This allows the system to present the candidate query parameter requiring confirmation to the user through the confirmation card. The confirmation card can be a structured interactive component that centrally displays the various fields of the candidate query parameter in the form of a form or card, allowing the user to check and edit them. This presents the candidate query parameter to the user in a visual and editable manner, enabling the user to complete the checking, modification, and confirmation of all parameters on a single interface, improving the intuitiveness of content presentation and optimizing the human-computer interaction.
[0062] In some feasible implementations, the detection process of structured tags can be implemented using a finite state machine. This involves displaying the inference process flow corresponding to the query request and maintaining the finite state machine during the token sequence output of the inference process flow. The finite state machine includes at least one of the following states: idle state, buffer state, and tag completion state. When the finite state machine is in the idle state, if the current token successfully matches the prefix of the starting tag of the structured tag, it enters the buffer state. In the buffer state, subsequent tokens are cached until the ending tag of the structured tag is detected, after which the tag completion state is entered. The content between the starting and ending tags is extracted as candidate query parameters, and a confirmation card for the candidate query parameters is displayed.
[0063] In its implementation, the data analysis system maintains a finite state machine during the token sequence output process of the inference flow. This finite state machine includes at least three states: idle (IDLE), buffering (BUFFERING), and tag completion (TAG_COMPLETED). The large language model outputs tokens one by one in a streaming manner, and the data analysis system can then input each token sequentially into the finite state machine for processing.
[0064] When the finite state machine is in an idle state, the data analysis system determines whether the current token successfully matches the starting tag prefix of the structured tag. For example, the starting tag is... <query-confirm>When a token of "<" is received, the system enters a partial matching state and continues to receive subsequent tokens, comparing them character by character with the starting tags "q", "u", "e", "r", "y", "-", "c", "o", "n", "f", "i", "r", "m", and ">". If all matches are successful, the starting tag is confirmed to have been detected, and the finite state machine enters a buffer state. If any token does not match the character at the corresponding position of the starting tag during the matching process, it is determined that the current content is not the beginning of the structured tag. The data analysis system outputs the previously cached content as a plain text event and returns to an idle state to continue detecting subsequent tokens.
[0065] While the finite state machine is in a buffered state, the data analysis system caches each subsequently received token into the buffer until the end tag of the structured tag is detected. During the buffering process, the content inside the tag (i.e., the candidate query parameters in JSON format) is fully stored in the buffer and is not output to the front end as ordinary inference text. When an end tag is detected, the finite state machine enters the tag completion state.
[0066] Once the tag is complete, the data analysis system extracts the content between the start and end tags in the buffer; this content constitutes the candidate query parameters in JSON format. The system can further parse this JSON content, restoring it to a structured candidate query parameter object. A confirmation card is then generated and displayed on the front-end interface, allowing users to verify and modify query parameters.
[0067] By implementing the finite state machine described above, the data analysis system can detect and extract structured tags in real time and accurately during the streaming token output process, while ensuring that tag content is not mistakenly output to the inference text stream, thus guaranteeing a smooth user experience and data accuracy. For example, when the large language model outputs a token sequence of "I need to query the overall GMV trend for March",... <query-confirm> {"metrics":["GMV"],"dimensions":["by day"]}< / query-confirm>Then I will analyze it further. After detecting "<", the finite state machine starts matching. After confirming the start tag, it enters the buffer state and caches the JSON content. After detecting the end tag, it extracts the JSON. "I need to query the overall GMV trend in March" and "Then I will analyze it further" are output to the front end as normal reasoning text. Thus, the reasoning text seen by the user is coherent, and the system backend obtains structured candidate query parameters.
[0068] Furthermore, the finite state machine performs state transition judgments in real time during streaming token processing, enabling instant tag detection without waiting for the complete string to be generated. Since the finite state machine includes idle, buffer, and tag completion states, it can dynamically process token sequences: when a starting tag prefix is detected, it transitions from the idle state to the buffer state, accumulating subsequent tokens one by one in the buffer state until the end tag is identified, finally entering the tag completion state and extracting the tag content. Therefore, based on the finite state machine design, it is suitable for handling complex scenarios where tag boundaries span multiple tokens (e.g., the starting tag is segmented within adjacent tokens). The state memory mechanism ensures the integrity and robustness of tag parsing while achieving zero-latency real-time response capabilities.
[0069] In addition, confirmation cards can include indicator input fields, dimension input fields, filter condition input fields, time range input fields, and comparison period input fields, and users can directly edit candidate query parameters on the card. For example, a confirmation card may sequentially display the following input fields: "Indicator" (displayed as "GMV," users can click the drop-down menu to switch to other indicators such as "Order Volume" or "Conversion Rate"), "Dimension" (displayed as "By Day," users can click to switch to "By Service Line" or "By Destination"), "Time Range" (displayed as "2026-03-01 to 2026-03-31," users can adjust the start and end dates), "Comparison Period" (displayed as "Same Period Last Month," users can switch to "Same Period Last Year" or "No Comparison"), and "Filter Condition" (displayed as "All Service Lines," users can click to select a specific service line). Each input field is a visual interactive component, and users can directly click, select, or input to modify the corresponding parameter values.
[0070] If a user enters an edit on the confirmation card, the data analysis system can respond to this edit by updating the candidate query parameters displayed on the confirmation card in real time. For example, if a user clicks the "Dimension" input field, a drop-down menu will expand to display options such as "By Day," "By Service Line," "By Destination," and "By Channel." After the user selects "By Service Line," the dimension field on the confirmation card will immediately update to "By Service Line." Similarly, a user can click the date picker on the time range input field to change "2026-03-01 to 2026-03-31" to "2026-02-01 to 2026-02-28." All editing operations are performed before user confirmation and will not trigger actual data queries.
[0071] Furthermore, after completing all edits on the confirmation card and confirming its accuracy, the user clicks the confirmation button (e.g., "Confirm Query" or "Execute Analysis") on the card. The data analysis system responds to this confirmation, retrieves the edited target query parameters, and proceeds to the next steps. The confirmation card can also include a "Cancel" button, which the user clicks to close the confirmation card and cancel the query. Through this visual and editable confirmation card mechanism, users no longer need to repeatedly modify query conditions using natural language; they can simply select and edit directly on the card to complete the confirmation, significantly reducing the number of dialogue rounds and communication costs during the confirmation process.
[0072] Step 102: In response to the confirmation operation for the confirmation card, obtain the confirmed target query parameters, and perform the data query operation corresponding to the target query parameters to obtain the corresponding query return result; In this embodiment, after verifying the candidate query parameters on the confirmation card of the front-end interface, the user can edit each parameter item to correct ambiguities or errors. For example, if the user finds that the time range "2026-03-01 to 2026-03-31" should be changed to "2026-03-01 to 2026-03-30", they can directly adjust it on the date picker; or they can change the comparison period from "same period last month" to "same period last year". After confirming that all parameters are correct on the confirmation card, the user clicks the confirmation button on the confirmation card (e.g., "Confirm Query" or "Execute Analysis") to trigger the confirmation operation. The data analysis system responds to this confirmation operation and obtains the target query parameters after user confirmation. These target query parameters are the final query conditions after user verification and editing, containing clear indicators, dimensions, filtering conditions, time ranges, and comparison periods.
[0073] In its implementation, after obtaining the relevant target query parameters, the data analysis system can invoke a data query tool to execute data query operations. This data query tool can be a pre-packaged data access component decoupled from the large language model, connecting to the enterprise's OLAP query engine via JDBC (Java Database Connectivity) or HTTP interfaces. Specifically, the data query tool can convert the target query parameters into query statements conforming to the OLAP engine's syntax specifications. For example, for the target query parameters "metric: GMV", "dimension: by day", and "time range: 2026-03-01 to 2026-03-31", the data query tool can convert it into the SQL statement "SELECT date, SUM(gmv) FROM fact_order WHERE date BETWEEN '2026-03-01' AND '2026-03-31' GROUPBY date OR DERBYdate". Then, the data query tool can submit this query request to the OLAP engine, which executes the query and returns the results.
[0074] The query results can include data records that match the target query parameters. For example, the query above returns a sequence of daily GMV values for March 2026: 2026-03-01: 120 million, 2026-03-02: 110 million, ..., 2026-03-31: 130 million, etc. After obtaining the query results, the data query tool can assign a unique query identifier (queryId) to each result, such as "qry_20260301_001".
[0075] Furthermore, the data query tool can generate a data summary with a preset data summary size, such as a Markdown-formatted summary of the top 30 records (if more than 30 records are returned, only the first 30 are extracted as a summary), which is returned to the data analysis system along with the queryId. In subsequent inference, the large language model can understand the overall picture of the query results (such as the approximate distribution of data, peak and trough positions, and overall trends) by reading this Markdown summary, without having to read all the detailed data, thus saving context space.
[0076] Optionally, the full details of the query results can also be stored in a persistent data store (such as OTS) for use in subsequent steps.
[0077] In some feasible implementations, after obtaining the corresponding query results, the data analysis system can distribute the query results to the local storage of the isolated computing environment via an asynchronous data preheating service to accelerate data loading during subsequent Python script execution. Optionally, the data analysis system can convert the query results into structured data files, and then distribute the structured data files to the local storage of the isolated computing environment. When calling code execution tools to perform data computation, the isolated computing environment reads the structured data files from the local storage through pre-injected runtime auxiliary code.
[0078] In its implementation, after the data analysis system executes a data query operation and obtains the query results, the asynchronous data preloading service (Sandbox Data Preloader) can immediately start the data preloading process. This asynchronous data preloading service is a background service independent of the main inference process; its execution does not block subsequent inference of the large language model, thus avoiding increased end-to-end latency.
[0079] For asynchronous data preheating services, the first step is to convert the full detailed data returned by the query into a structured data file, such as a CSV (Comma-Separated Values) file. A CSV file is a common tabular data storage format, with each row corresponding to one data record and each column corresponding to different fields (such as date, GMV value, etc.). Compared to the original JSON format, CSV files have a smaller file size and faster parsing speed, making them suitable for rapid loading in computing environments. After the conversion is complete, the asynchronous data preheating service can distribute the CSV file to local storage in an isolated computing environment.
[0080] The isolated computing environment can be a Python sandbox cluster based on Kubernetes containers. In some examples, each sandbox instance can be an independent Kubernetes Pod, running a Python runtime environment with its own local file system, network namespace, and resource quotas (e.g., 2 CPU cores, 4GB memory). Furthermore, the isolated computing environment can maintain an instance pool (SandboxInstancePool) containing multiple pre-created sandbox instances, each loaded with pre-injected runtime helper code (prelude.py) during initialization. The asynchronous data preheating service distributes CSV files to a fixed data directory (e.g., / data / preload / ) on the local storage of each instance in the instance pool. Since the number of instances in the instance pool is pre-configured and relatively fixed (e.g., 10 instances), the asynchronous data preheating service can distribute query result data to all instances, ensuring that the data is already ready locally on that instance regardless of which instance the subsequent Python script is scheduled to execute.
[0081] When a large language model needs to perform data computation tasks during iterative analysis, it calls a code execution tool (such as the runPython tool) and submits a Python script to be executed. Correspondingly, the data analysis system can submit the Python script to the target sandbox instance in the isolated computing environment for execution. Since the query data has been pre-distributed to the target instance's local storage, the Python script can directly read CSV files from local storage and convert them into DataFrame objects through data loading functions provided in the pre-injected runtime helper code.
[0082] Specifically, in a Python script, you can call just one line of code: "df = load_query_data_as_dataframe(queryId)". The data loading function will automatically locate the corresponding CSV file path in local storage based on the passed queryId, read the file, and convert it into a Pandas DataFrame object. Correspondingly, the data loading function can also automatically print a data summary during the reading process (e.g., "Loaded data: 100 rows, 5 columns, column names: ['date', 'gmv', 'order_cnt', 'conversion_rate']"), allowing the large language model to understand the basic structure of the data.
[0083] Through the aforementioned asynchronous data warm-up mechanism, Python scripts executed in the sandbox do not need to fetch data from remote storage in real time via HTTP interfaces; the data is already ready in the local file system. This effectively reduces data loading latency and significantly accelerates the execution of Python computing tasks. Furthermore, because the warm-up process is asynchronous, the main inference process can continue to the next inference step without waiting for the data upload to complete, further reducing end-to-end response time.
[0084] In addition, the pre-injected runtime helper code may include at least one of a data loading function, a file upload function, and a cross-script variable sharing function; each instance in the instance pool of the isolated computing environment loads the pre-injected runtime helper code during initialization. The data loading function is used to read structured data files from local storage and convert them into data frame objects. The file upload function is used to upload computation result files to persistent data storage. The cross-script variable sharing function is used to pass variables between multiple code execution calls.
[0085] In the implementation, the pre-injected runtime helper code (prelude.py) is a Python script that the data analysis system pre-uploads to a fixed path in the sandbox container (e.g., / tmp / _prelude.py) during sandbox instance initialization. Each sandbox instance loads this code at startup using "exec(open(' / tmp / _prelude.py').read())", injecting data loading functions, file upload functions, and cross-script variable sharing functions into the Python script's global namespace. The Python script can then directly call these functions during execution, without needing to redefine or import external dependencies.
[0086] Correspondingly, the data loading function (load_query_data_as_dataframe) can be used to read a CSV file from local storage and convert it into a Pandas DataFrame object. Its function signature is "def load_query_data_as_dataframe(queryId:str)->pd.DataFrame". Internally, the function constructs the local CSV file path based on the queryId (e.g., " / data / preload / preload_{queryId}.csv"), reads the file using pd.read_csv, and automatically prints a data summary, including the number of rows (e.g., "100 records"), a list of column names (e.g., "['date', 'gmv', 'order_cnt']"), the data type of each column, and statistical information for each column (e.g., mean, maximum, minimum, etc.). This summary information is captured and output as part of the tool's results to the large language model, helping the large language model understand the basic characteristics of the current data.
[0087] Correspondingly, the file upload function (attach_file) can be used to upload the calculation result file to persistent data storage (OSS, Object Storage Service), returning an access link that can be referenced by the front end. Its function signature is "defattach_file(obj,filename:str,optional_args)->str". The function supports two input types: matplotlib Figure objects and local file paths. For Figure objects, the function automatically performs a series of enhancements: first, it checks for available CJK fonts in the current runtime environment; if a font is found, it modifies matplotlib's global font configuration to ensure correct CJK character display, avoiding garbled characters in the chart; then, it automatically prevents overlapping labels by adjusting the tight_layout parameter; for large values on the Y-axis (such as "100000000"), it automatically formats them into a readable format (such as "100 million"). After enhancement, the Figure is saved as a PNG image and uploaded to OSS, returning the OSS access link for the image. For local file path input, the function directly uploads the file to OSS and returns the access link.
[0088] Correspondingly, cross-script variable sharing functions (save_vars and load_vars) can be used to pass variables between multiple code execution calls. The function signatures are "def save_vars(**kwargs)" and "def load_vars(*keys)". The functions achieve data persistence through disk pickle serialization: save_vars serializes the passed key-value pairs and saves them to a specific directory in the sandbox's local storage (e.g., / tmp / shared_vars.pkl), and load_vars deserializes them from that file and returns the value corresponding to the specified key. For example, intermediate results calculated in the first runPython call can be saved using "save_vars(intermediate_result=result)", and loaded in the second runPython call using "intermediate_result=load_vars('intermediate_result')", thus achieving data transfer across script calls and avoiding redundant calculations.
[0089] With the aforementioned pre-injected runtime helper code, the execution code of the Python script is greatly simplified, allowing the script generated by the large language model to focus only on the core computational logic (such as calculating the growth rate, drawing charts, etc.), while common operations such as data loading, file uploading, and variable persistence are all completed by the pre-injected functions. This reduces the complexity of the code generated by the large language model and improves the accuracy and stability of the generated code.
[0090] Furthermore, during the invocation of the code execution tool, the data analysis system can also perform a fallback loading operation to ensure that if pre-warmed data is not present in the target sandbox instance, it can proactively retrieve it from persistent storage in a timely manner. Optionally, in response to the invocation of the code execution tool, the data analysis system can obtain the script code to be executed and detect the query identifier in the script code. The query identifier is used to point to the target query return result. If the structured data file corresponding to the query identifier does not exist in the local storage of the isolated computing environment, the target query return result is read from the persistent data storage, then the target query return result is converted into a target structured data file, and then the target structured data file is uploaded to the local storage. Conversely, if the structured data file corresponding to the query identifier exists in the local storage of the isolated computing environment, the structured data file is read directly.
[0091] In practical implementation, due to various circumstances, the target sandbox instance may not receive the structured data file distributed by the asynchronous data preheating service. For example, an instance in the instance pool might start only after the asynchronous data preheating service has completed data distribution, and therefore its local storage may not yet contain the query result data; or the data distribution process may fail to complete successfully during network fluctuations. To address this, and to ensure that data computation tasks can still execute normally under these abnormal scenarios, the data analysis system introduces a fallback loading mechanism when executing code execution tools.
[0092] Specifically, after receiving the Python script submitted by the large language model, the data analysis system first detects the query identifier (queryId) from the Python script to be executed. The query identifier points to the target query's returned result. In the Python script, the data loading function passes the queryId as a parameter, for example, "load_query_data_as_dataframe('qry_20260301_001')". The data analysis system extracts the queryId parameter value from this function call using regular expressions. For example, the regular expression "load_query_data_as_dataframe" is used to match and extract the queryId. After extracting the queryId, the data analysis system can check if a CSV file corresponding to the queryId exists in the local storage of the target sandbox instance. Optionally, the check can be performed by searching for a file named "preload_{queryId}.csv" in the target instance's local storage data directory. If the file exists, it means the data has been pre-warmed up, and the Python script can be executed normally. If the file does not exist, a fallback loading process is triggered: the data analysis system reads the original query result (JSON format) corresponding to the queryId from the persistent data store (OTS), converts the query result into a CSV file, and then uploads the CSV file to the local storage of the target sandbox instance. After the upload is complete, the Python script continues to execute, reading the CSV file from the local storage using the data loading function.
[0093] Through the aforementioned fallback loading mechanism, even in the event of abnormal data warm-up, the data analysis system can still ensure the normal execution of Python scripts, thus improving the system's robustness. Furthermore, since fallback loading is only triggered when the local data is absent, it does not incur any additional overhead under normal circumstances.
[0094] Step 103: During the iterative analysis based on the query results, a capacity control operation is performed on the dialogue history context of the iterative analysis, and after the iterative analysis is completed, a visualization report corresponding to the query request is output.
[0095] In this embodiment, after obtaining the query result, the data analysis system can store the query result as part of the dialogue history context in the corresponding memory module. The dialogue history context records the complete dialogue process between the large language model and the user, including each round of user input, the large language model's inference text, tool call requests, and return results. The memory module in the data analysis system implements the LangChain4j ChatMemory interface, supporting persistent storage of dialogue history and isolation by session.
[0096] In its implementation, after obtaining the query results, the large language model, combined with the user's original query request, determines whether the current data is sufficient to answer the user's question. If the current data is insufficient (for example, a user asks "Why did GMV decline in March?", but only overall trend data is available, without drill-down analysis by dimension), the large language model autonomously constructs the next query or calculation task. For example, it calls a data query tool to further drill down by service line dimension, or calls a code execution tool to calculate the month-on-month growth rate to identify inflection points and conduct a second round of analysis. If the current data is sufficient to answer the user's question, the large language model comprehensively analyzes all query results and calculation outputs to generate an analysis conclusion. This process is executed cyclically, forming an iterative analysis loop of "query-analysis-re-query-re-analysis" until the large language model confirms that it can provide a complete analysis conclusion.
[0097] Furthermore, during the iterative analysis process, before each round of inference calls, the data analysis system can perform capacity control operations on the dialogue history context. As the number of iterations increases, the number of messages in the dialogue history context continues to grow. Each query return result contains a data summary (approximately several hundred tokens), each Python execution output contains calculation results and graph descriptions (approximately several hundred to several thousand tokens), and when combined with the inference text from the large language model, the number of tokens in the dialogue history context rapidly expands. Without control, after several iterations, the number of tokens may exceed the context window limit of the large language model (e.g., 128K tokens), preventing subsequent inference. Therefore, the capacity control operation aims to maintain the number of tokens in the dialogue history context below a preset compression threshold, ensuring that the large language model can continue to perform in-depth analysis in long dialogue chains.
[0098] After the iterative analysis is completed, the data analysis system integrates all the data generated during the analysis process, including data records returned by OLAP queries, statistical results and charts generated by Python calculations, and inference text generated by the large language model, into a visual analysis report and outputs it to the front-end interface. This visual report can be a richly illustrated analysis document, including data tables, trend charts, attribution analysis conclusions, and next steps recommendations. Users can directly read the report to obtain the complete analysis results without manual processing.
[0099] In some feasible implementations, the capacity control operation described above can include multiple parallel sub-operations: marking metadata query results as protected content, deduplicating duplicate tool calls, and triggering dialogue summary compression when the number of tokens reaches a preset threshold. Optionally, metadata query results can be extracted from the historical dialogue context and marked as protected content. This protected content is not removed or compressed during the capacity control operation. The metadata query results include at least one of a list of available metrics, a list of available dimensions, and a list of available filters. And / or, before each round of inference calls, duplicate tool call records in the historical dialogue context are detected, and duplicate call results with the same tool name and the same input parameters in the duplicate tool call records are replaced with a reference marker pointing to the most recent call result. And / or, before each round of inference invocation, estimate the current number of tokens in the historical dialogue context. If the current number of tokens is greater than or equal to a preset compression threshold, then take the historical dialogue messages in the dialogue history context, excluding the protected content and the original dialogue messages from the most recent preset rounds, as the target dialogue messages to be compressed, determine the structured summary of the target dialogue messages, replace the target dialogue messages with the structured summary, and re-inject the protected content into the compressed dialogue history context.
[0100] In its implementation, the data analysis system can perform corresponding capacity control operations before each round of inference calls, including: First, extract the metadata query results from the dialogue history context. These results can be the content returned by a metadata retrieval tool (such as `getMetadata`), and may include a list of available metrics (e.g., "GMV", "order volume", "conversion rate", "average order value"), a list of available dimensions (e.g., "by day", "by service line", "by destination", "by channel"), and a list of available filters (e.g., "service line", "region", "store type"). The data analysis system can mark this metadata query result as protected content. This protected content will not be removed, compressed, or deduplicated in subsequent capacity control operations and will be permanently retained in the dialogue history context. This is because metadata contains a complete list of all available metrics, dimensions, and filters, which is the foundation for the large language model to construct subsequent query parameters. In other words, the large language model needs to know "which metrics can be queried", "which dimensions can be drilled down", and "which filters can be used" to correctly construct the parameters for the next query. Any reduction or removal will cause the large language model to be unable to correctly select query parameters in subsequent inference, resulting in incorrect queries or incomplete analysis.
[0101] Second, before each round of inference, the system checks for duplicate tool call records in the dialogue history context. During data analysis, the large language model may call the same tool multiple times with identical input parameters. For example, in multi-round drill-down analysis, the large language model may re-call the `getMetadata` tool to retrieve metadata at the beginning of each round to ensure parameter correctness; or it may repeatedly execute the same query on the same data domain to verify the data. The data analysis system calculates the hash value of the tool name and input parameters for each tool call. For example, the tool name string and the input parameter JSON string can be concatenated and hashed (e.g., MD5 or SHA-256) to generate a unique hash key identifying this call. Then, this hash value is used as the key to check if there is a historical call record with the same key in the dialogue history. If a record with the same key exists, it means that the current tool call is exactly the same as a previous call, such as the same tool or the same input parameters. Data analysis systems can retain only the tool return result corresponding to the most recent call (i.e., the latest return content), and replace the earlier call results with a reference marker pointing to the most recent call, such as "[Same as above, see the result of the Nth round of calls]". This ensures that the large language model can find the latest call result, while reducing the repeated occupation of context space by redundant data.
[0102] During the deduplication process, the judgment is based on the tool name and the hash value of the input parameter, without comparing the returned content. Therefore, the computational overhead is minimal (only string concatenation and hash calculation are required), which can effectively ensure the overall performance of the inference call.
[0103] Third, before each round of inference, the current number of tokens in the dialogue history context is estimated. One exemplary estimation method is to obtain the total number of bytes in the dialogue history context and divide it by 4 to obtain the estimated token value (for large language model scenarios involving both Chinese and English, bytes / 4 is a commonly used fast estimation method in engineering, although its accuracy is not as high as calling the API's token counting interface, it is faster and requires no additional API call overhead). After calculating the current number of tokens, the data analysis system can determine whether the current number of tokens is greater than or equal to a preset compression threshold. This preset compression threshold can be 80% of the maximum number of tokens in the large language model's context window, etc. For example, if the context window of the large language model is 128K tokens, then the preset compression threshold is 102K tokens. By choosing a threshold smaller than the window's upper limit, a safety margin can be reserved, thus reserving corresponding context space for the summary generation process. If compression is triggered only when the window is completely full, the summary generation request may fail due to exceeding the window's upper limit.
[0104] If the current number of tokens is greater than or equal to a preset compression threshold, the data analysis system can use historical dialogue messages in the dialogue history context, excluding protected content (i.e., metadata query results) and the original dialogue messages from the most recent preset rounds, as the target dialogue messages to be compressed. For example, the most recent preset rounds could be the most recent 5 rounds of original dialogue messages, where a round refers to a complete dialogue round (one round of dialogue includes one UserMessage and all subsequent AiMessages and tool call results). By retaining the original text of the most recent 5 rounds, it ensures that recent query parameters and calculation results still exist in their original form within the context after compression, avoiding the loss of accurate recent data due to compression.
[0105] In its implementation, the structured summary is not a simple text summary, but rather a structured summary of the analysis status organized according to predefined dimensions. Optionally, the data analysis system can send a summary generation request carrying the target dialogue message to the large language model. The summary generation request instructs the large language model to generate a structured summary according to at least one of the following dimensions: user intent and feedback dimension, completed query and calculation dimension, analysis findings and attribution path dimension, error and repair dimension, and current progress and next step plan dimension. The system then receives the structured summary of the target dialogue message returned by the large language model.
[0106] In its implementation, the data analysis system can call a large language model (either reusing the currently executing large language model or forking a separate lightweight model) to process the target dialogue message, requiring the generation of corresponding structured summaries according to the following multiple dimensions: (1) User intent and feedback dimension: Record the user's original request, follow-up questions and corrections raised during the analysis process, to ensure that the compressed large language model still knows the user's core needs and feedback.
[0107] (2) Completed query and calculation dimensions: Record the key parameters of each query (e.g., "queried March GMV, by day"), key conclusions and values of Python calculation (e.g., "daily month-on-month decrease of 23%, inflection point is March 15"), to ensure that the compressed large language model knows what analysis work has been completed and what intermediate results have been obtained.
[0108] (3) Analysis of findings and attribution path dimensions: Record the anomalies that have been located (such as "GMV plummeted on March 15"), drill-down logic (such as "drill down by service line and locate that domestic hotels contributed 70% of the drop"), and external attribution results (such as "extreme weather caused a surge in cancellations") to ensure that the attribution path and existing findings of the compressed large language model are not lost.
[0109] (4) Error and Repair Dimension: Record the errors encountered during the analysis process (such as "query field 'order_cnt' does not exist" or "variable is not defined in Python script") and the corresponding solutions to help the large language model avoid repeating the same errors in subsequent inference.
[0110] (5) Current progress and next step plan dimension: Record the work currently in progress and the clear next step plan (such as "the current domestic hotel service line has been located as abnormal, and the next step is to analyze the contribution of domestic hotels in various cities"), to ensure that the compressed large language model clearly understands the current analysis stage and the subsequent actions in the plan.
[0111] The structured summary returned by the large language model received by the data analysis system can be configured in length, for example, limited to 512 tokens, to ensure that the summary itself does not occupy too much context space. Then, the data analysis system can replace the compressed target dialogue message with the structured summary and the original dialogue messages from the most recent preset number of rounds, and re-inject the protected content (metadata query results) into the compressed dialogue history context. Thus, the compressed dialogue history context consists of a "structured summary (summarizing early history)," "original messages from the last 5 rounds (recent precise data)," and "protected content (metadata)," preserving both long-term key analytical states and recent precise data, while also ensuring the integrity of the metadata.
[0112] Furthermore, if the sum of the number of tokens in the structured summary and the number of tokens in the original messages from the most recent preset rounds still exceeds the preset compression threshold (i.e., the compressed context is still too long), the data analysis system can delete unprotected historical messages one by one from the earliest position in the dialogue history until the number of tokens in the remaining messages does not exceed the preset compression threshold. For example, it can delete the earliest unprotected message one by one (which may be inference text or tool return results from an earlier round) until the length requirement is met. If summary generation fails three times in a row (e.g., the large language model interface times out or returns an exception), the data analysis system stops the summary generation operation to avoid infinitely consuming system resources.
[0113] Furthermore, during the inference process flow and / or the inference process of the iterative analysis, the data analysis system can also implement the reception, conversion, and streaming output of inference events and tool call events through a unified callback state machine. Optionally, the analysis system can receive inference events and tool call events, convert them into target event streams adapted to different protocol formats, and during the transmission of the target event streams, in response to the end of the current inference output, perform a termination processing operation for the target event streams, and periodically send heartbeat events during the connection maintenance period.
[0114] In its implementation, the data analysis system can receive inference events and tool call events through a unified callback state machine (BaseTokenStreamHandler) during both the inference process flow (such as the initial inference in step 101) and the inference process of iterative analysis (such as the multi-round iterative inference in step 103). Inference events can include states such as inference start (REASONING_START), inference content append (REASONING_MESSAGE_CONTENT), and inference end (REASONING_END); correspondingly, tool call events can include states such as tool call start (TOOL_CALL_START), tool call end (TOOL_CALL_END), and tool return result (TOOL_RESULT).
[0115] In addition, the unified callback state machine can maintain an internal state machine that includes states such as Idle, Reasoning, Tool Execution, Text Output, and Completion. It also supports multi-round tool call loops, meaning that when the tool finishes execution, the state automatically switches back to Reasoning to continue the next round of reasoning.
[0116] Optionally, the unified callback state machine converts inference events and tool call events into target event streams adapted to different protocol formats through a protocol adaptation layer. This protocol adaptation layer can be an abstraction layer for the externally output protocol, defining a unified internal event callback contract (such as onReasoningStart(), onReasoningContent(), onToolCallStart(), etc.). The protocol adaptation layer includes a front-end UI protocol adapter (AG-UI adapter) and an inter-Agent communication protocol adapter (A2A adapter). The front-end UI protocol adapter maps each callback event to a fine-grained event of the AG-UI protocol; for example, it maps onReasoningStart to the REASONING_START event, onReasoningContent to the REASONING_MESSAGE_CONTENT event, onReasoningEnd to the REASONING_END event, onToolCallStart to the TOOL_CALL_START event, and onToolCallEnd to the TOOL_CALL_END event. The inter-agent communication protocol adapter merges multiple callback events into a task status update event (TaskStatusUpdateEvent) or task artifact update event (TaskArtifactUpdateEvent) of the A2A protocol. For example, it merges the entire "inference-tool call-inference" loop into a single TaskStatusUpdateEvent, which contains a complete description of the status change.
[0117] Through the above protocol adaptation layer design, the data analysis system can support two different protocol requirements simultaneously without modifying the core inference logic: front-end UI (which requires fine-grained events to achieve real-time rendering) and inter-agent calls (which require merging events to reduce communication overhead). This achieves an architecture of "one set of callback logic, multiple protocol outputs".
[0118] During the transmission of the target event stream, the data analysis system can also create a heartbeat timer when the connection is established. During the connection maintenance period, it sends heartbeat events in SSE comment format (i.e., ":heartbeat\n\n" format) at fixed intervals (e.g., every 15 seconds) to prevent the reverse proxy or load balancer from disconnecting due to idle timeout. When the inference output ends normally, the unified callback state machine performs a termination operation: flushing the remaining text in the buffer and writing a stream end flag (e.g., "data:[DONE]\n\n") to notify the client that inference is complete. Optionally, the termination operation can be guaranteed to execute only once using an atomic state flag (AtomicBoolean) to avoid repeated execution due to race conditions between the SSE disconnection callback and the LLM completion callback. When the client actively disconnects (e.g., the user closes the browser), the unified callback state machine detects the SSE disconnection and sets a canceled flag. If this canceled flag is detected in the callback before tool execution, an interrupt exception is thrown, interrupting the Agent loop and preventing invalid tool calls from continuing even after the client has disconnected.
[0119] Furthermore, the final output visualization report in the above embodiments may include at least one of the following visualization elements: The first type of visualization element can be an interactive chart generated from the query results. Specifically, the data analysis system can convert the data records returned by the OLAP query into an ECharts chart configuration (ECharts is an open-source JavaScript visualization library that supports a rich variety of interactive chart types). The front-end rendering engine then renders this configuration into an interactive ECharts chart. These interactive charts can include line charts (suitable for trend analysis), bar charts (suitable for comparative analysis), pie charts (suitable for percentage analysis), indicator cards (suitable for displaying key values), and box plots (suitable for distribution analysis), among other chart types. Users can interact with the charts on the front-end interface, such as zooming to view specific time periods, hovering to view the values of specific data points, and switching chart types.
[0120] The second type of visualization element can be charts and images generated through code execution tools. Specifically, the data analysis system can generate advanced analysis charts and images using the `attach_file` function when executing data calculation scripts in the Python sandbox. These advanced charts include waterfall charts (suitable for showing the contribution breakdown of different factors), heatmaps (suitable for showing two-dimensional distribution density), and dumbbell charts (suitable for showing comparisons of change magnitude). Correspondingly, the `attach_file` function automatically performs aesthetic enhancements on the charts, such as injecting CJK fonts (ensuring correct display of Chinese characters), preventing label overlap (adjusting label positions to avoid obstruction), and formatting large Y-axis values (e.g., formatting "100000000" as "100 million"). The chart is then saved as a PNG image and uploaded to OSS storage, returning an OSS access link for the image. The front-end interface references this OSS link using Markdown image syntax, rendering it as a static image displayed in the analysis report. Because the charts are in image format, they can be loaded and rendered quickly even on low-performance devices.
[0121] The third type of visualization element can be a report document generated through a code execution tool. Specifically, when a user explicitly requests the generation of an HTML report (e.g., stating "generate a complete analysis report" in the query request), the data analysis system uses a Python code execution tool to generate complete HTML code containing ECharts charts and data tables. This HTML code includes all necessary CSS styles and JavaScript library references (loaded via CDN for ECharts), and can be opened and viewed independently in a browser without relying on backend services. The HTML report is suitable as a deliverable for formal analysis reports, and users can archive, print, or share it with colleagues.
[0122] Optionally, the three visualization elements described above correspond to different use cases: interactive charts are suitable for online browsing and exploratory analysis; chart images are suitable for embedding in report documents or PPT presentations; and HTML reports are suitable for formal delivery and offline viewing. The data analysis system can automatically select the appropriate visualization method based on the user's query request, or the user can specify it in the query request, such as "output in chart image format".
[0123] It should be noted that the embodiments of this application include, but are not limited to, the examples described above. It is understood that those skilled in the art can make further settings according to actual needs under the guidance of the ideas in the embodiments of this application, and this application does not impose any restrictions on this.
[0124] In this embodiment, during the data analysis process, the data analysis system first responds to the user's input query request. If a structured tag carrying candidate query parameters is detected in the inference process flow corresponding to the query request, a confirmation card for the structured tag is displayed. Then, in response to the confirmation operation for the confirmation card, the confirmed target query parameters are obtained, and the data query operation corresponding to the target query parameters is executed to obtain the corresponding query return result. During the iterative analysis based on the query return result, a capacity control operation is performed on the dialogue history context of the iterative analysis. After the iterative analysis is completed, a visual report corresponding to the query request is output. Thus, through the real-time detection of structured tags in the inference process flow and the human-computer interaction mechanism of the confirmation card, not only is the confirmation of the query before execution achieved, but the probability of result deviation caused by ambiguity of query parameters can also be reduced. Furthermore, through the capacity control operation of the dialogue history context, the continuity and integrity of the inference state during multiple rounds of iterative analysis can be effectively maintained. At the same time, through the fully automated closed loop from data query to iterative analysis to report output, the execution efficiency of the data analysis task and the accuracy of the analysis conclusion are significantly improved.
[0125] To enable those skilled in the art to better understand the technical solutions in the embodiments of this application, the following examples are provided for illustrative purposes: As some examples, see Figure 2 The diagram illustrates the system architecture provided in this embodiment. The data analysis system can adopt a "single agent + multiple tools" architecture, using a core agent based on a large language model to uniformly complete intent understanding, tool invocation, analysis and reasoning, and report generation. The data analysis system can consist of the following core modules: (1) User Interaction Layer: This layer serves the front-end user and the external Agent / Skill platform respectively through two standardized protocols, realizing the architecture design of "one set of back-end logic, multi-terminal interactive output". Among them, the user interaction layer can include two parallel interaction channels, namely the Web UI front-end (AG-UI protocol / SSE) and the external Agent / Skill platform (A2A protocol / JSON-RPC). For the Web UI front-end, it can be a Web front-end interface facing the end user, which interacts with the back-end through the AG-UI protocol; for the external Agent / Skill platform, it can be an interface channel facing the external Agent or Skill platform, which communicates through the A2A protocol.
[0126] (2) Protocol adaptation layer: A unified event callback contract is defined through the StreamingProtocolAdapter interface. BaseTokenStreamHandler handles common logic (context closure passing, heartbeat keep-alive, disconnection detection, callback state machine). AG-UI Protocol Adapter and A2A Protocol Adapter each implement protocol-specific event format conversion.
[0127] (3) Core Agent Module: Built on LangChain4j AiServices, it adopts a single agent architecture. This core agent module can isolate dialogue history by session through @MemoryId, dynamically inject system prompt words containing the Skill directory through system MessageProvider, support runtime hot switching of large models (without restarting the service) through DynamicStreamingChatModel, and achieve classification protection, deduplication, and summary compression through context capacity management.
[0128] (4) Tool system: The tools that the Agent can call may include: DataQueryTools: This tool encapsulates the OLAP query engine, providing tools for metadata acquisition, dimension validation, query execution, and analysis template loading. It returns Markdown-formatted results for LLM to understand. It supports three data entry points: natural language description, analysis template ID (fixed query conditions), and query condition JSON (for precise control of metrics / dimensions / filters).
[0129] PythonExecutionTool: Submits Python scripts generated by LLM to Kubernetes sandbox containers for execution, supporting data computation, statistical analysis, and advanced visualization.
[0130] SkillTools: LLM loads domain knowledge documents (such as data analysis methodologies and Python coding standards) on demand to guide its analytical behavior.
[0131] Search Tools: Access external search engines (such as XX Search) via the MCP protocol to find real-time external information (changes in the external environment, holidays, extreme weather, etc.) during attribution analysis, providing external explanations for data anomalies.
[0132] External Extension Tools (MCP Tools): A collection of tools that access third-party external tools and services via the MCP protocol.
[0133] (5) Sandbox Execution Layer: A Python sandbox based on Kubernetes containers, including several sub-modules such as instance pool management (SandboxInstancePool), data preheating service (SandboxDataPreloader) (not shown in the figure), and runtime pre-injection (prelude.py). Among them, SandboxInstancePool can be an instance pool processing component in an isolated computing environment, responsible for maintaining a set of pre-created Python sandbox instances based on Kubernetes containers. It can realize the pre-creation and initialization of instance pools, instance allocation (Redis allocation), and health checks. Prelude.py can be runtime auxiliary code that the data analysis system pre-uploads to a fixed path (e.g., / tmp / _prelude.py) in the sandbox container during sandbox instance initialization. It can include, but is not limited to, data loading functions (e.g., load_data), file upload functions (e.g., attach_file), and icon beautification functions.
[0134] (6) Storage Layer: This can include a multi-layered storage structure, such as the OLAP query engine, OTS persistent storage, and OSS object storage. Each of these three layers undertakes different data storage responsibilities, jointly supporting the data flow and persistence requirements of the entire data analysis process. Among them, the OLAP query engine, as the data source layer, is the enterprise's internal multi-dimensional data query system, storing the service fact table and dimension table after ETL processing; OTS (Table Storage), as the persistent storage layer, is responsible for storing two types of core data in the data analysis process: query results and conversation memory; OSS (Object Storage), as the file storage layer, is responsible for storing charts, images, and attachment files generated during the data analysis process.
[0135] Accordingly, in the process of data analysis, refer to Figure 3 This diagram illustrates the interaction flowchart of the streaming tag and caliber confirmation mechanism provided in this embodiment. The interacting entities involved may include: users, front-end interfaces, StreamHandler (including TagParser), Large Language Model (LLM), etc. Specifically: User initiates query request phase: Users input natural language queries through the front-end interface, such as "Help me check the GMV for March". The front-end sends the query request to the back-end system, which then forwards the request to the large language model for inference.
[0136] Large Language Model Streaming Inference and Tag Embedding Stages: The large language model generates the inference process flow token by token in a streaming manner. During the inference process, if the large language model determines that the current query has ambiguity (e.g., "GMV" may refer to "order GMV" or "fulfillment GMV", and "March" may refer to "calendar month" or "March including orders in transit"), it embeds structured tags into the streaming output. <query-confirm>. The tag carries candidate query parameters in JSON format, including five elements: metrics, dimensions, filter conditions, time range, and comparison period, for example: "metrics":["GMV"], "dimensions":["by day"], "timeRange":"2026-03-01 to 2026-03-31", "comparePeriod":"the same period of last month" and "filters":{"businessLine":"all"}, etc.
[0137] Correspondingly, the inference text outside the tag (such as "OK, I will query the GMV data for March") is normally output to the front end in a streaming manner, for the user to read the inference process of the large language model in real time.
[0138] StreamHandler streaming tag parsing phase: The TagParser component in StreamHandler performs token-by-token detection on the token sequence output by the LLM. When the tag prefix is not detected, the token is normally output to the front end as an ordinary text event. When the starting tag is detected <query-confirm> When a tag is detected, TagParser enters buffering mode, pausing the output of tag content as text events and instead continuously accumulating the JSON content within the tag into the buffer.< / query-confirm> , TagParser extracts the complete JSON content and wraps it as a CUSTOM event to send to the front end. If a token is truncated at the tag boundary (for example, "<query-" and "confirm>" belong to two consecutive tokens), TagParser maintains a buffered state through the finite state machine's partial matching detection mechanism (couldBePartialTag), and waits for subsequent tokens to arrive before completing tag matching. If the parsing fails (for example, the tag format is incomplete), TagParser executes a degradation strategy, outputs the original content as ordinary text, and does not affect the normal progress of the main process.
[0139] Front-end confirmation card display and user editing and confirmation phase: After the front end receives the CUSTOM event sent by TagParser, it parses the JSON content and renders to generate a caliber confirmation card. The confirmation card displays the five elements in a structured form: metrics (such as "GMV"), dimensions (such as "by day"), filter conditions (such as "all service lines"), time range (such as "2026-03-01 to 2026-03-31"), and comparison period (such as "the same period of last month"). The user can check and edit each parameter item item by item on the confirmation card, for example, modify the comparison period from "the same period of last month" to "the same period of last year", or adjust the time range to "2026-03-01 to 2026-03-30". After confirming that there is no error, the user clicks the confirmation button, and the front end passes the target query parameters confirmed by the user through <query-confirmed>The tag is sent back to the backend.
[0140] Agent execution query phase: After receiving the user's confirmed target query parameters, the Agent directly calls the data query tool (executeQueryString) to perform the data query operation and obtain the corresponding query results. The large language model continues to stream the analysis results based on the query results, and the front end displays the final analysis report and charts.
[0141] Throughout the entire interaction process, the detection, buffering, and extraction of structured tags are all completed in the backend streaming process. The frontend does not need to be aware of the technical details of tag parsing; it only needs to render the confirmation card based on the received CUSTOM event. The reasoning text outside the tags is displayed normally in a streaming manner, ensuring the continuity of the user's reading and reasoning process. The structured data within the tags is captured by the system and converted into a visual card, achieving a "non-interrupted conversation flow" confirmation interaction experience.
[0142] Furthermore, in the context capacity handling of data analysis scenarios, refer to Figure 4 This diagram illustrates the capacity control operation provided in this embodiment, executed before each API call, to control the number of tokens in the dialogue history context within a preset range, thereby maintaining the continuity of inference state in long dialogue chains. Specifically, as shown... Figure 4 As shown, four core phases are executed sequentially before each round of API calls: ① Tool result classification and protection: The system employs differentiated protection strategies for the results returned by different types of tools. Metadata-related tools return results (such as lists of available metrics, available dimensions, and available filters) marked as protected content. These results are never truncated, deduplicated, or compressed in subsequent processing to ensure the model always possesses the fundamental ability to construct correct queries. Query result tools output results in a Top 30 summary + queryId format, with manageable size, and are normally preserved. Python execution tools and search tools also have manageable size and are normally preserved under normal circumstances; however, as a defensive fallback, protective truncation is performed only when the output is abnormally long (exceeding the configured token budget)—retaining the header (data overview or chart description) and tail (calculation conclusions), while replacing the middle portion with a truncation marker. Since the current round of the model has already seen the complete output, truncation only affects the historical context usage of subsequent rounds.
[0143] ② Using the same tools and parameters to remove duplicates: The system uses the tool name and the hash value of the input JSON parameter as keys to check if there are any historical call records with the same key in the dialogue history. If they exist, it means that the same tool has been called repeatedly with the exact same input parameters. Only the complete tool return result corresponding to the most recent call is retained, and earlier duplicate results are replaced with reference markers pointing to the most recent call (e.g., "[Same as above, see the result of the Nth round of calls]"). This significantly reduces the amount of redundant data occupying the context space. The deduplication judgment is based on matching the hash value of the tool name and the input parameter, without comparing the returned content, resulting in minimal computational overhead.
[0144] ③ LLM five-dimensional structured digest compression (triggered when total tokens > compression threshold): Before each API call, the system uses a quick token estimation (bytes / 4) to determine whether the number of tokens in the current dialogue history context exceeds the preset compression threshold (e.g., 80% of the maximum number of tokens in the model context window). If it does, the summary compression process is triggered. The system calls the large language model to generate a structured summary of the historical dialogue messages, excluding protected content and the original messages of the most recent preset rounds, according to five dimensions: (1) User intent and feedback dimension (the user's original request, follow-up questions and corrections during the process); (2) Completed queries and calculations dimension (the key parameters of each query, the key conclusions and values of Python calculations); (3) Analysis findings and attribution path dimension (the anomalies that have been located, drill-down logic, and external attribution results); (4) Errors and repairs dimension (the problems such as missing query fields and Python script errors and their solutions); (5) Current progress and next step plan dimension (the work in progress and the clear next step plan). After compression, the compressed historical messages are replaced with the structured summary and the original dialogue messages of the most recent preset rounds (e.g., the most recent 5 rounds) to ensure that the recent query parameters and results are preserved in their original form. If the sum of the number of tokens in the compressed structured digest and the original message of the most recent preset round still exceeds the preset compression threshold, the system will delete the unprotected historical messages one by one from the earliest position in the historical messages until the number of tokens in the remaining messages does not exceed the preset compression threshold.
[0145] ④ Re-injection of critical content after compression: After compression, the following key content is automatically re-injected into the context: SystemPrompt (including Skill directory summary), dynamically injected each time by the system prompt word provider (systemMessageProvider), independent of historical messages; metadata query results, if the dialogue before compression contained metadata query results, the most recent metadata is automatically re-injected after compression to ensure the model can still correctly construct queries; InsightContext analysis findings, loaded from persistent storage (Redis) as supplementary context injection. Skill documents are not actively restored—the model will automatically call the SkillTools tool to reload them when needed, avoiding wasting context space.
[0146] After the above four stages of processing, the system sends an API request normally, submitting the compressed dialogue history context to the large language model for the next round of inference.
[0147] Furthermore, in some example scenarios, suppose a user asks, "Why did GMV decline in March?" Users can enter "Why did GMV decline in March?" on the front-end interface and submit it. User messages enter the system via ChatController.send(), SessionContext.init() binds the session context (including sessionId, userId, modelName, etc.), and the message is passed to DataAnalysisAgent.chat() for unified processing.
[0148] Next, the data analysis system identifies the query as an analytical intent and calls the SkillTools tool to load the "data analysis methodology" Skill (getSkillContent("data-analysis-methodology")), obtaining guidance from the "hypothesis-validation-iteration" analytical framework. This means the large language model understands that attribution analysis should follow an analytical path of "holistic first, local second; location first, explanation second": first, examine the overall trend to identify anomalies; then, drill down by dimension to locate the source of the problem; and finally, combine external information to explain the cause. Then, the Agent calls the getMetadata tool to obtain a list of available metrics and dimensions, returning metadata information such as "metrics: GMV, order volume, conversion rate" and "dimensions: by day, by service line, by destination." It calls the getDimensionKeys tool to verify dimension compatibility (e.g., confirming whether the "by day" dimension and the "GMV" metric can be queried together). This metadata query result is marked as protected content and stored in the dialogue history context, ensuring it is never truncated in subsequent capacity control.
[0149] Furthermore, the large language model determines that "GMV" has ambiguity (it may refer to "order GMV" or "fulfillment GMV"), and "March" may have ambiguity regarding its time range (whether it includes orders in transit). Therefore, the large language model generates the inference text "I need to query the overall GMV trend for March, please confirm the following definitions" in the inference process flow, and embeds it in the streaming output. <query-confirm>The tag contains JSON data including "metric: GMV", "dimension: by day", "time range: 2026-03-01 to 2026-03-31", and "comparison period: February same period". The data analysis system's QueryConfirmTagParser detects this structured tag in the token sequence, enters buffer mode to accumulate JSON content, extracts the complete JSON, packages it into a CUSTOM event, and sends it to the front end. The front end parses the CUSTOM event, renders a confirmation card, and displays the five elements: metric, dimension, filter, time, and comparison. The user verifies the parameters on the confirmation card, changes "comparison period: February same period" to "comparison period: 2025 same period", and clicks confirm. The front end then sends the confirmed target query parameters through... <query-confirmed>Tag return.
[0150] Furthermore, the data analysis system obtains the confirmed target query parameters and calls the executeQueryString tool to perform the first round of OLAP query, querying the daily GMV in March 2026 and the daily GMV in March 2025 as comparative data, returning queryId + Top 30 summary (overall GMV trend in March) + caliber footnote ("GMV caliber: Ordered GMV, including canceled orders"). Simultaneously, SandboxDataPreloader asynchronously converts the full query results into a CSV file and distributes it to the local storage of all instances in the sandbox instance pool.
[0151] Furthermore, the data analysis system can load the "Python code generation specification" skill (python-code-generation), call the code execution tool (runPython) to generate Python scripts, calculate the daily month-on-month growth rate and year-on-year change rate, and identify inflection points. The script reads pre-warmed CSV data using load_query_data_as_dataframe(queryId), calculating that a sharp drop occurred on March 15th, with a 23% decrease month-on-month and an 18% decrease year-on-year. The script generates a trend chart using attach_file(fig,"gmv_trend.png"), automatically performing aesthetic enhancements such as CJK font injection, label anti-overlap, and large value formatting on the Y-axis, saving it as a PNG file and uploading it to OSS, returning the image link.
[0152] Furthermore, based on the calculation results, the data analysis system discovered a sharp drop on March 15th. It autonomously constructed a drill-down query by service line dimension, calling `executeQueryString` to query the GMV changes for each service line on March 15th. The results showed that the GMV of the "Domestic Hotels" service line decreased by 70% compared to the previous day, contributing 70% of the overall decline. The data analysis system further constructed a drill-down query by city dimension, pinpointing that the "Sanya" region contributed 60% of the decline in domestic hotel GMV. The data analysis system called an online search tool (accessing Quark Search via the MCP protocol) to query for any major external events on March 15th, obtaining external information that "a sudden extreme rainstorm in Sanya on March 15th led to a surge in hotel cancellations," providing an external attribution explanation for the data anomaly.
[0153] During the aforementioned multi-round analysis, the data analysis system automatically performs context capacity management before each round of API calls: Before the 5th round of calls, the Python execution outputs approximately 8000 tokens. The system truncates the output according to the budget (e.g., 5000 tokens), retaining only the header (data overview) and tail (calculation results), replacing the middle portion with "... (truncated)..." markers; Before the 8th round of calls, the metadata query results are marked as protected content. Deduplication detection identifies duplicate calls to getMetadata (same data domain, same input parameters), replacing them with "[same as above, see the results of the 2nd round of calls]", reducing redundancy by approximately 2000 tokens; In the 12th round... Before the call, the number of dialogue history tokens reached 85% of the context window (approximately 110K / 128K), triggering LLM summary compression. The large language model was invoked to generate a structured summary based on five dimensions (user intent and feedback, completed queries and calculations, analysis findings and attribution paths, errors and fixes, current progress and next steps). The summary, along with the original text from the last five rounds, replaced the historical messages. After compression, the number of dialogue history tokens decreased to 45% of the context window (approximately 58K / 128K). The metadata query results and analysis findings from InsightContext ("Anomalies in domestic hotels in Sanya have been located") were then re-injected into the context. The compressed data analysis system can continue analysis based on the compressed context without needing to start over.
[0154] Finally, the data analysis system integrates all analysis results to generate a visually appealing analysis report: The report begins with the conclusion, "The decline in GMV in March was mainly due to a surge in cancellations in the Sanya hotel market caused by extreme rainstorms on March 15th, resulting in a 23% decrease compared to the same period last year." This is followed by an interactive line chart embedded in the `chart` tag (showing the daily changes in March GMV, with the steepest points marked in red). The "Attribution Analysis" section uses Markdown image syntax to reference a waterfall chart generated by Python (showing the contribution of each service line to the decline, with domestic hotels contributing the most). Download links are also provided for the detailed query CSV file and the Excel file exported from the Python calculations. If the user explicitly requests an HTML report, the complete HTML code containing ECharts charts and data tables will also be output and can be viewed independently.
[0155] Throughout the analysis process, the state machine of BaseTokenStreamHandler manages the reasoning process (REASONING event, which displays the reasoning thinking of the large language model in real time), tool calls (TOOL_CALL event, which displays the status of each call to executeQueryString or runPython), and the final text (TEXT_MESSAGE event, which displays the text content of the analysis report) which are pushed to the front end in real time. Users can see the thinking and execution process of the data analysis system throughout the entire process.
[0156] Through the above process, this application's embodiments achieve end-to-end automation from natural language processing to data querying, iterative analysis, and visualization reporting. In the caliber confirmation stage, streaming tag parsing and confirmation card interaction compress the traditional caliber confirmation process, which requires 2-3 rounds of text communication, into a single round of card interaction, reducing the number of confirmation rounds by more than 50%. In the iterative analysis stage, autonomous reasoning using a single-agent architecture achieves a closed-loop analysis of "hypothesis-verification-iteration." A complete attribution analysis typically includes 5-7 OLAP queries and 3-5 Python calculations, all without manual intervention. Regarding context management, a four-layer mechanism of classification protection, deduplication, summary compression, and key content re-injection increases the maximum number of dialogue rounds in data analysis scenarios from approximately 10 rounds (interrupted by context overflow) to over 50 rounds. Furthermore, the continuity of the compressed analysis is maintained through structured summaries and key content re-injection, increasing the proportion of effective contextual information from approximately 40% to approximately 75%. Ultimately, the traditional manual analysis process, which requires hours, is compressed into a few minutes of conversational interaction, significantly reducing the technical threshold and time cost of data analysis.
[0157] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of this application are not limited to the described order of actions, because according to the embodiments of this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of this application.
[0158] Reference Figure 5 The diagram illustrates a structural block diagram of a data analysis device based on a large language model provided in an embodiment of this application, which may specifically include the following modules: The confirmation card display module 501 is used to respond to a query request input by a user, and if a structured tag carrying candidate query parameters is detected in the inference process flow corresponding to the query request, a confirmation card for the structured tag is displayed. The query execution module 502 is used to respond to the confirmation operation for the confirmation card, obtain the confirmed target query parameters, and perform a data query operation corresponding to the target query parameters to obtain the corresponding query return result; The capacity control module 503 is used to perform capacity control operations on the dialogue history context of the iterative analysis during the process of iterative analysis based on the query return results. The report output module 504 is used to output a visualization report corresponding to the query request after the iterative analysis is completed.
[0159] In some feasible implementations, the confirmation card display module 501 is specifically used for: Display the reasoning process flow corresponding to the query request; During the token sequence output process of the inference process flow, a finite state machine is maintained, which includes at least one of an idle state, a buffer state, and a tag completion state. When the finite state machine is in an idle state, if the current token successfully matches the starting tag prefix of the structured tag, it enters the buffer state. In the buffer state, subsequent tokens are cached until the end tag of the structured tag is detected, after which the tag completion state is entered. The content between the start tag and the end tag is extracted as the candidate query parameter, and a confirmation card for the candidate query parameter is displayed.
[0160] In some feasible implementations, the capacity control module 503 is specifically used for: Metadata query results are extracted from the historical dialogue context and marked as protected content. The protected content is not removed or compressed during the capacity control operation. The metadata query results include at least one of the following: a list of available metrics, a list of available dimensions, and a list of available filter options. And / or, before each round of inference invocation, detect duplicate tool call records in the historical dialogue context, and replace duplicate call results with the same tool name and the same input parameters in the duplicate tool call records with reference markers pointing to the most recent call result; And / or, before each round of inference invocation, estimate the current number of tokens in the historical dialogue context. If the current number of tokens is greater than or equal to a preset compression threshold, then take the historical dialogue messages in the dialogue history context, excluding the protected content and the original dialogue messages from the most recent preset rounds, as the target dialogue messages to be compressed. Determine the structured summary of the target dialogue messages, replace the target dialogue messages with the structured summary, and re-inject the protected content into the compressed dialogue history context.
[0161] In some feasible implementations, the capacity control module 503 is specifically used for: Send a summary generation request carrying the target dialogue message to the large language model. The summary generation request is used to instruct the large language model to generate a structured summary according to at least one of the following dimensions: user intent and feedback dimension, completed query and calculation dimension, analysis discovery and attribution path dimension, error and repair dimension, and current progress and next step plan dimension. Receive a structured summary of the target dialogue message returned by the large language model.
[0162] In some feasible implementations, the apparatus further includes a data preheating module, used after the query execution module 502 obtains the corresponding query return result: Convert the query results into a structured data file; The structured data files are distributed to local storage in the isolated computing environment; When calling code execution tools to perform data computation, the isolated computing environment reads the structured data file from the local storage through pre-injected runtime auxiliary code; The pre-injected runtime helper code includes at least one of a data loading function, a file upload function, and a cross-script variable sharing function. Each instance in the instance pool of the isolated computing environment loads the pre-injected runtime helper code during initialization. The data loading function is used to read the structured data file from the local storage and convert it into a data frame object. The file upload function is used to upload the computation result file to persistent data storage. The cross-script variable sharing function is used to pass variables between multiple code execution calls.
[0163] In some feasible implementations, the data preheating module is also used for: In response to invoking the code execution tool, the script code to be executed is obtained, and a query identifier is detected in the script code, the query identifier being used to point to the target query return result; If the structured data file corresponding to the query identifier does not exist in the local storage of the isolated computing environment, the target query result is read from the persistent data storage. Convert the results returned by the target query into a target structured data file; The target structured data file is uploaded to the local storage.
[0164] In some feasible implementations, the device further includes a protocol adaptation module, used for: During the inference process flow and / or the inference process of the iterative analysis, inference events and tool call events are received; Convert inference events and tool call events into target event streams that are adapted to different protocol formats; During the transmission of the target event stream, in response to the end of this inference output, a termination processing operation is performed on the target event stream, and a heartbeat event is sent periodically during the connection maintenance period.
[0165] In some feasible implementations, the apparatus further includes a domain knowledge loading module, used after the confirmation card display module 501 responds to a user-input query request: Obtain a target summary of at least one domain knowledge module corresponding to the query request; Inject the target summary into the system prompt word; If the query request is detected to match the target domain knowledge module, the complete content corresponding to the target domain knowledge module is obtained and stored in the dialogue history context.
[0166] In some feasible implementations, the visualization report includes at least one of the following visualization elements: An interactive chart generated using the query results; Charts and images generated by code execution tools; The report document generated by the code execution tool.
[0167] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0168] In addition, this application also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described data analysis method embodiment based on a large language model and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0169] In addition, this application also discloses a computer program product, including computer execution instructions, which, when executed by a processor, implement the method described in this application.
[0170] This application also provides a readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described data analysis method embodiment based on a large language model and achieves the same technical effect. To avoid repetition, it will not be described again here. The readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.
[0171] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0172] Those skilled in the art will understand that embodiments of this application can be provided as methods, apparatus, or computer program products. Therefore, embodiments of this application can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of this application can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, EEPROM, Flash, and eMMC, etc.) containing computer-usable program code.
[0173] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0174] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0175] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0176] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0177] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only 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 terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0178] The above provides a detailed description of a data analysis method and a data analysis device based on a large language model provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A data analysis method based on a large language model, characterized in that, include: In response to a user's query request, if a structured tag carrying candidate query parameters is detected in the inference process flow corresponding to the query request, a confirmation card for the structured tag is displayed. In response to the confirmation operation for the confirmation card, the target query parameters after confirmation are obtained, and the data query operation corresponding to the target query parameters is executed to obtain the corresponding query return result; During the iterative analysis based on the query results, a capacity control operation is performed on the dialogue history context of the iterative analysis, and a visualization report corresponding to the query request is output after the iterative analysis is completed.
2. The method according to claim 1, characterized in that, The display of the confirmation card for the structured label includes: Display the reasoning process flow corresponding to the query request; During the token sequence output process of the inference process flow, a finite state machine is maintained, which includes at least one of an idle state, a buffer state, and a tag completion state. When the finite state machine is in an idle state, if the current token successfully matches the starting tag prefix of the structured tag, it enters the buffer state. In the buffer state, subsequent tokens are cached until the end tag of the structured tag is detected, after which the tag completion state is entered. The content between the start tag and the end tag is extracted as the candidate query parameter, and a confirmation card for the candidate query parameter is displayed.
3. The method according to claim 1, characterized in that, The capacity control operation performed on the dialogue history context of the iterative analysis includes: Metadata query results are extracted from the historical dialogue context and marked as protected content. The protected content is not removed or compressed during the capacity control operation. The metadata query results include at least one of the following: a list of available metrics, a list of available dimensions, and a list of available filter options. And / or, before each round of inference invocation, detect duplicate tool call records in the historical dialogue context, and replace duplicate call results with the same tool name and the same input parameters in the duplicate tool call records with reference markers pointing to the most recent call result; And / or, before each round of inference invocation, estimate the current number of tokens in the historical dialogue context. If the current number of tokens is greater than or equal to a preset compression threshold, then take the historical dialogue messages in the dialogue history context, excluding the protected content and the original dialogue messages from the most recent preset rounds, as the target dialogue messages to be compressed. Determine the structured summary of the target dialogue messages, replace the target dialogue messages with the structured summary, and re-inject the protected content into the compressed dialogue history context.
4. The method according to claim 3, characterized in that, Determining the structured summary of the target dialogue message includes: Send a summary generation request carrying the target dialogue message to the large language model. The summary generation request is used to instruct the large language model to generate a structured summary according to at least one of the following dimensions: user intent and feedback dimension, completed query and calculation dimension, analysis discovery and attribution path dimension, error and repair dimension, and current progress and next step plan dimension. Receive a structured summary of the target dialogue message returned by the large language model.
5. The method according to claim 1, characterized in that, After obtaining the corresponding query return result, the method further includes: Convert the query results into a structured data file; The structured data files are distributed to local storage in the isolated computing environment; When calling code execution tools to perform data computation, the isolated computing environment reads the structured data file from the local storage through pre-injected runtime auxiliary code; The pre-injected runtime helper code includes at least one of a data loading function, a file upload function, and a cross-script variable sharing function. Each instance in the instance pool of the isolated computing environment loads the pre-injected runtime helper code during initialization. The data loading function is used to read the structured data file from the local storage and convert it into a data frame object. The file upload function is used to upload the computation result file to persistent data storage. The cross-script variable sharing function is used to pass variables between multiple code execution calls.
6. The method according to claim 5, characterized in that, Also includes: In response to invoking the code execution tool, the script code to be executed is obtained, and a query identifier is detected in the script code, the query identifier being used to point to the target query return result; If the structured data file corresponding to the query identifier does not exist in the local storage of the isolated computing environment, the target query result is read from the persistent data storage. Convert the results returned by the target query into a target structured data file; The target structured data file is uploaded to the local storage.
7. The method according to claim 1, characterized in that, Also includes: During the inference process flow and / or the inference process of the iterative analysis, inference events and tool call events are received; Convert inference events and tool call events into target event streams that are adapted to different protocol formats; During the transmission of the target event stream, in response to the end of this inference output, a termination processing operation is performed on the target event stream, and a heartbeat event is sent periodically during the connection maintenance period.
8. The method according to claim 1, characterized in that, Following the response to a user-input query request, the method further includes: Obtain a target summary of at least one domain knowledge module corresponding to the query request; Inject the target summary into the system prompt word; If the query request is detected to match the target domain knowledge module, the complete content corresponding to the target domain knowledge module is obtained and stored in the dialogue history context.
9. The method according to claim 1, characterized in that, The visualization report contains at least one of the following visualization elements: An interactive chart generated using the query results; Charts and images generated by code execution tools; The report document generated by the code execution tool.
10. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; The memory is used to store computer programs; When the processor executes a program stored in the memory, it implements the method as described in any one of claims 1-9.
11. A readable storage medium having instructions stored thereon that, when executed by one or more processors, cause the processors to perform the method as described in any one of claims 1-9.
12. A computer program product, characterized in that, It includes computer execution instructions, which, when executed by a processor, implement the data analysis method based on a large language model as described in any one of claims 1-9.
