Context management method and device in workflow and related equipment
By acquiring and managing the dialogue turn sequence of historical dialogue data in the AI question-answering system, and controlling the data length using storage and summary variables, the workflow failure problem caused by multiple rounds of follow-up questions was solved, and effective context management was achieved.
Patent Information
- Application Number
- CN202511733899.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-24
- Publication Date
- 2026-02-27
AI Technical Summary
Existing AI question-answering systems suffer from workflow failures due to excessive historical messages accumulated during multiple rounds of follow-up questions, making it difficult to effectively manage context.
By acquiring the historical dialogue data of the current node, the dialogue turn sequence is extracted, and the historical dialogue data is saved and summarized according to the save variables and summary variables in the configuration information, ensuring that the data length does not exceed the upper limit of the input allowed by the model.
This achieves the goal of avoiding workflow failures without losing the semantics of historical messages, accurately managing the context, and improving the stability and efficiency of the system.
Smart Images

Figure CN121579616A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information processing technology, and in particular to a context management method, apparatus and related equipment in a workflow. Background Technology
[0002] Many current AI question-answering systems support follow-up questions. For AI question-answering systems, the backend is often implemented using a workflow system. Follow-up questions are typically achieved by running the same workflow multiple times. During follow-up questions, the questions from previous rounds and the output (answer) of the final workflow are treated as historical messages and then processed at each workflow node. For large model nodes in the workflow, if there are too many follow-up rounds, the accumulated historical messages can become very large. Eventually, with the continuous increase in follow-up questions (rounds), the historical messages may cause a massive model context problem, leading to workflow failure. To solve this problem, a context management scheme needs to be designed to ensure that the semantics of historical messages are not lost while preventing workflow failure. Summary of the Invention
[0003] The embodiments of the present invention provide a method, apparatus and related equipment for context management in workflow, which aims to solve the technical problem that traditional technologies are difficult to effectively manage context.
[0004] In a first aspect, embodiments of the present invention provide a context management method in a workflow, comprising:
[0005] Obtain the historical dialogue data of the current node, and extract the dialogue round sequence from the historical dialogue data;
[0006] Receive context management configuration information, and parse the saved variables and summary variables in the configuration information according to the dialogue round sequence. The saved variables represent the retention of a specified number of historical dialogue data, and the summary variables represent the summarization of a specified number of historical dialogue data.
[0007] The specified number of historical dialogue data are to be saved according to the specified save variable, and the specified number of historical dialogue data are to be summarized according to the specified summary variable.
[0008] Secondly, embodiments of the present invention provide a context management device in a workflow, comprising:
[0009] The acquisition module is used to acquire the historical dialogue data of the current node and extract the dialogue round sequence from the historical dialogue data.
[0010] The parsing module is used to receive context management configuration information and parse the variables and summary variables stored in the configuration information according to the dialogue round sequence.
[0011] The save and summarize module is used to save a specified number of historical dialogue data according to the save variable, and to summarize the specified number of historical dialogue data according to the summarize variable.
[0012] Thirdly, embodiments of the present invention provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the context management method in the workflow described in the first aspect above.
[0013] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to perform the context management method in the workflow described in the first aspect.
[0014] This invention provides a context management method, apparatus, and related equipment for workflow. The method acquires historical dialogue data of the current node and extracts the dialogue round sequence from it; receives context management configuration information and parses the saved variables and summary variables in the context management configuration information according to the dialogue round sequence; specifies the number of historical dialogue data to be saved based on the saved variables; and summarizes the specified number of historical dialogue data based on the summary variables. This method, by configuring saved variables and summary variables, enables users to manage historical dialogue data, overcoming the problem that the actual runtime state cannot be known during workflow orchestration, making it difficult to accurately specify context management configurations. Attached Figure Description
[0015] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a flowchart illustrating an embodiment of the context management method in workflow provided by the present invention.
[0017] Figure 2 A schematic block diagram of a context management device in a workflow provided in an embodiment of the present invention. Detailed Implementation
[0018] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0020] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0021] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0022] Please see Figure 1 This is a flowchart illustrating a context management method in a workflow provided by an embodiment of the present invention, which includes steps S110 to S130.
[0023] Step S110: Obtain the historical dialogue data of the current node, and extract the dialogue round sequence from the historical dialogue data;
[0024] Step S120: Receive the context management configuration information, and parse the saved variables and summary variables in the configuration information according to the dialogue round sequence;
[0025] Step S130: Save a specified number of historical dialogue data according to the specified storage variable, and summarize the specified number of historical dialogue data according to the specified summary variable.
[0026] In this embodiment, each time the workflow is run, the question-and-answer data for that workflow is stored, and the question-and-answer data for each round is numbered to construct a dialogue round sequence of historical dialogue data. A storage variable `m` and a summary variable `n` are configured. The storage variable `m` represents the number of historical dialogue data rounds to be retained, and the summary variable `n` represents the number of historical dialogue data rounds to be summarized, where n ≥ m ≥ 0. Specific combinations are shown in Table 1.
[0027]
[0028]
[0029] Table 1
[0030] In one embodiment, step S130 includes:
[0031] Step S210: Save a specified number of historical dialogue data according to the saved variables to obtain the target saved data;
[0032] Step S220: Real-time detection of whether the message length of the target stored data exceeds the upper limit of the input length allowed by the model;
[0033] Step S231: If the length exceeds the limit, the target data is digested, and the digest data is checked again to see if it exceeds the length limit. If it does, the digest data is digested until the message length of the digest data does not exceed the length limit. Then the digest data is sent to the large model.
[0034] Step S232: If the value does not exceed the limit, the target saved data is sent to the large model.
[0035] In this embodiment, historical dialogue data is processed according to the above configuration. Based on the save variable and summary variable in the configuration information, it is checked whether the message length of the target save data exceeds the maximum length allowed by the model. If the target save data does not exceed the maximum length, the target save data is directly appended to the request as a historical message and sent to the large model. If the target save data exceeds the maximum length, the target save data is first summarized to generate summary data. It is then checked whether the summary data exceeds the maximum length allowed by the model. If the summary data still exceeds the maximum length, the summary data is summarized again or multiple times, and the output length of the summary processing is specified not to exceed the maximum length. If the summary data obtained with the specified output length not exceeding the maximum length still exceeds the maximum length, the summary data corresponding to the historical dialogue data of the most recent x rounds is taken, and the total message length of the extracted summary data is controlled not to exceed the maximum length.
[0036] Furthermore, in one embodiment, the workflow supports specified context configuration, allowing users to dynamically adjust rules according to the actual question-and-answer scenario, overriding preset node configurations. All large model nodes uniformly follow this custom rule: based on the dialogue round sequence, obtain dialogue data from a specified round as target processing data; determine whether the target processing data exceeds the length limit; if it does, summarize the target processing data, and continue to check whether the obtained summary data exceeds the length limit; if it does, summarize the summary data until the message length of the summary data does not exceed the length limit, and send the summary data to the large model; if it does not exceed the length limit, send the target processing data to the large model. The system allows users to specify the dialogue data for a target round using a list of numbers (supporting regular expressions). For example, (1,3,5) indicates that only messages from rounds 1, 3, and 5 are retained, and (2-6) indicates that messages from rounds 2 to 6 are retained. The system directly extracts the dialogue data from the specified rounds to construct a historical message set. If the historical message set does not exceed the length limit, it is directly added to the request and sent to the large model. If the historical message set exceeds the length limit, all messages from the specified rounds are summarized to obtain summary data. If the summary data exceeds the length limit allowed by the model, the summary data is summarized again, and the output length during this summary processing is specified not to exceed the length limit. If the summary data still exceeds the length limit, the historical dialogue data from the most recent x rounds is taken, and the message length of the historical dialogue data from the most recent x rounds is controlled to not exceed the length limit.
[0037] This method acquires historical dialogue data from the current node and extracts the dialogue turn sequence from it. It receives context management configuration information and parses the saved variables and summary variables from the configuration information based on the dialogue turn sequence. It then saves a specified number of historical dialogue data points based on the saved variables and summarizes the specified number of historical dialogue data points based on the summary variables. By configuring saved and summary variables, this method enables users to manage historical dialogue data, overcoming the problem of difficulty in accurately specifying context management configurations due to the lack of information about the actual runtime state during workflow orchestration.
[0038] This invention also provides a context management device in a workflow, which is used to execute any embodiment of the aforementioned context management method in a workflow. Specifically, please refer to... Figure 2 , Figure 2 This is a schematic block diagram of a context management device in a workflow provided in an embodiment of the present invention. The context management device 100 in this workflow can be configured in a server.
[0039] like Figure 2 As shown, the context management device 100 in the workflow includes an acquisition module 110, a parsing module 120, and a saving and summarizing module 130.
[0040] The acquisition module 110 is used to acquire the historical dialogue data of the current node and extract the dialogue round sequence from the historical dialogue data.
[0041] The parsing module 120 is used to receive context management configuration information and parse the variables and summary variables stored in the configuration information according to the dialogue round sequence;
[0042] The save and summarize module 130 is used to save a specified number of historical dialogue data according to the save variable, and to summarize the specified number of historical dialogue data according to the summarize variable.
[0043] In one embodiment, the storage and summarization module 130 includes:
[0044] A storage unit is used to save a specified number of historical dialogue data according to the storage variable to obtain the target saved data;
[0045] The detection unit is used to detect in real time whether the message length of the target stored data exceeds the upper limit of the input length allowed by the model;
[0046] The first summarizing unit is used to, if the length exceeds the limit, summarize the target saved data, continue to detect whether the obtained summary data exceeds the upper limit of length, and if it does, summarize the summary data until the message length of the summary data does not exceed the upper limit of length, and then send the summary data to the large model; the sending unit is used to, if the length does not exceed the upper limit of length, send the target saved data to the large model.
[0047] In one embodiment, the first summarizing unit includes:
[0048] The detection subunit is configured to specify that the output length during summary processing does not exceed the upper limit if the summary data exceeds the upper limit.
[0049] An extraction subunit is used to extract the summary data corresponding to the most recent historical dialogue data according to the dialogue round sequence if the summary data obtained after specifying the output length still exceeds the upper limit of the length, and the total length of the extracted messages does not exceed the upper limit of the length.
[0050] In one embodiment, the storage and summarization module 130 further includes:
[0051] The acquisition unit is used to acquire dialogue data of a specified round as target processing data based on the dialogue round sequence.
[0052] The judgment unit is used to determine whether the target processing data exceeds the upper limit of length;
[0053] The second summarization unit is used to, if the length exceeds the limit, summarize the target processing data, continue to detect whether the obtained summary data exceeds the upper limit of length, and if it does, summarize the summary data until the message length of the summary data does not exceed the upper limit of length, and then send the summary data to the large model; if it does not exceed the upper limit of length, then send the target processing data to the large model.
[0054] This invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the context management method in the workflow described above.
[0055] In another embodiment of the invention, a computer-readable storage medium is provided. This computer-readable storage medium may be a non-volatile computer-readable storage medium. The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the context management method in the workflow described above.
[0056] Those skilled in the art will readily understand that, for the sake of convenience and brevity, the specific working processes of the devices, apparatuses, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention.
[0057] In the embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Units with the same function may be grouped into one unit. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices, or units, or it may be an electrical, mechanical, or other form of connection.
[0058] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of the present invention, depending on actual needs.
[0059] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0060] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks.
[0061] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A context management method for an AI question-answering system, characterized in that, include: Obtain the historical dialogue data of the current node, and extract the dialogue round sequence from the historical dialogue data; Receive context management configuration information, and parse the saved variables and summary variables in the configuration information according to the dialogue round sequence. The saved variables represent the retention of a specified number of historical dialogue data, and the summary variables represent the summarization of a specified number of historical dialogue data. The specified number of historical dialogue data are to be saved according to the specified save variable, and the specified number of historical dialogue data are to be summarized according to the specified summary variable.
2. The context management method in workflow as described in claim 1, characterized in that, The step of saving a specified number of historical dialogue data according to the specified storage variable, and summarizing the specified number of historical dialogue data according to the specified summary variable, includes: The target data to be saved is obtained by saving a specified amount of historical dialogue data according to the saved variables; Real-time detection of whether the message length of the target stored data exceeds the maximum length allowed by the model input; If the length exceeds the limit, the target data is digested, and the digest data is checked again to see if it exceeds the length limit. If it does, the digest data is digested until the message length of the digest data does not exceed the length limit, and then the digest data is sent to the large model. If the target data does not exceed the limit, the target data will be sent to the large model.
3. The context management method in workflow as described in claim 2, characterized in that, The statement that the message length up to the digest data does not exceed the upper limit includes: If the summary data exceeds the specified length limit, then the output length during summary processing shall not exceed the specified length limit. If the summary data obtained after specifying the output length still exceeds the upper limit of the length, then the summary data corresponding to the most recent historical dialogue data is extracted according to the dialogue round sequence, and the total length of the extracted messages does not exceed the upper limit of the length.
4. The context management method in workflow as described in claim 1, characterized in that, The step of saving a specified number of historical dialogue data according to the specified storage variable, and summarizing the specified number of historical dialogue data according to the specified summary variable, further includes: Based on the dialogue round sequence, the dialogue data of the specified round is obtained as the target processing data; Determine whether the target data to be processed exceeds the maximum length limit; If the length exceeds the limit, the target processing data is digested, and the digest data is checked again to see if it exceeds the length limit. If it does, the digest data is digested until the message length of the digest data does not exceed the length limit, and then the digest data is sent to the large model. If the target data does not exceed the limit, the target processing data will be sent to the large model.
5. A context management device in a workflow, characterized in that, include: The acquisition module is used to acquire the historical dialogue data of the current node and extract the dialogue round sequence from the historical dialogue data. The parsing module is used to receive the configuration information for context management and parse the saved variables and summary variables in the configuration information according to the dialogue round sequence. The saved variables represent the retention of a specified number of historical dialogue data, and the summary variables represent the summarization of a specified number of historical dialogue data. The save and summarize module is used to save a specified number of historical dialogue data according to the save variable, and to summarize the specified number of historical dialogue data according to the summarize variable.
6. The context management method in workflow as described in claim 5, characterized in that, The storage and summarization module includes: A storage unit is used to save a specified number of historical dialogue data according to the storage variable to obtain the target saved data; The detection unit is used to detect in real time whether the message length of the target stored data exceeds the upper limit of the input length allowed by the model; The first summarizing unit is used to, if the length exceeds the limit, summarize the target saved data, continue to detect whether the obtained summary data exceeds the upper limit of length, and if it does, summarize the summary data until the message length of the summary data does not exceed the upper limit of length, and then send the summary data to the large model; the sending unit is used to, if the length does not exceed the upper limit of length, send the target saved data to the large model.
7. The context management method in workflow as described in claim 6, characterized in that, The first summary unit includes: The detection subunit is configured to specify that the output length during summary processing does not exceed the upper limit if the summary data exceeds the upper limit. An extraction subunit is used to extract the summary data corresponding to the most recent historical dialogue data according to the dialogue round sequence if the summary data obtained after specifying the output length still exceeds the upper limit of the length, and the total length of the extracted messages does not exceed the upper limit of the length.
8. The context management method in workflow as described in claim 5, characterized in that, The storage and summarization module also includes: The acquisition unit is used to acquire dialogue data of a specified round as target processing data based on the dialogue round sequence. The judgment unit is used to determine whether the target processing data exceeds the upper limit of length; The second summarization unit is used to, if the length exceeds the limit, summarize the target processing data, continue to detect whether the obtained summary data exceeds the upper limit of length, and if it does, summarize the summary data until the message length of the summary data does not exceed the upper limit of length, and then send the summary data to the large model; if it does not exceed the upper limit of length, then send the target processing data to the large model.
9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the context management method in a workflow as described in any one of claims 1 to 4.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the context management method in the workflow as described in any one of claims 1 to 4.