Multi-level dialogue context adaptive management method, apparatus, device and storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-08
- Publication Date
- 2026-08-14
AI Technical Summary
[0003](1)上下文窗口溢出:工具调用结果、工具调用参数和对话历史消息三类内容共同膨胀,超出LLM的最大token(词元)限制,导致对话无法继续
[0021]The technical solution of this invention includes: obtaining the current number of tokens in the dialogue context; if the current number of tokens is greater than a first preset threshold, performing tool result summary compression on the tool return results, and performing multi-strategy structure-aware compression on the tool call parameters using field semantic role classification, recursive deep-aware truncation, and cross-reference retention checks; after compressing the tool return results and tool call parameters, re-obtaining the current number of tokens; if the current number of tokens is greater than a second preset threshold, performing query-aware dialogue summary compression on the dialogue history messages to obtain a dialogue summary, and reconstructing the dialogue context message sequence based on the dialogue summary. This technical solution uses a three-layer progressive compression to cover all token sources, solving the technical problem of existing technologies having a single compression dimension and failing to cover all token sources, leading to window overflow. Through multi-strategy structure-aware compression, it solves the technical problem of existing dialogue summary methods indiscriminately compressing all historical messages without distinguishing the relevance of information to the current task, resulting in the loss of key information during compression, thus improving the information retention accuracy during the compression process.
Smart Images

Figure CN122346543B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence, and more particularly to a multi-level dialogue context adaptive management method, apparatus, device, and storage medium. Background Technology
[0002] In AI agent systems based on Large Language Models (LLM), the agent needs to continuously invoke various tools (such as code execution, file operations, and database queries) in multi-turn dialogues to complete complex tasks. As the number of dialogue turns increases, a large amount of tool call parameters, tool return results, and historical dialogue content accumulate in the context window, leading to the following technical problems:
[0003] (1) Context window overflow: The three types of content—tool call results, tool call parameters, and dialogue history messages—expand together, exceeding the maximum token limit of LLM, causing the dialogue to be unable to continue. Existing technologies only compress one type (tool results or dialogue history), which cannot cover all token sources.
[0004] (2) Compression leads to loss of key information: Existing dialogue summarization methods compress all historical messages indiscriminately, without distinguishing the relevance of information to the current task. This may discard key data that is highly relevant to the current task (such as obtained query results, ongoing analysis steps, specific file paths and code snippets), while retaining early dialogue content that is irrelevant to the current task. Summary of the Invention
[0005] This invention provides a multi-level dialogue context adaptive management method, apparatus, device, and storage medium to overcome dialogue length limitations, improve information retention accuracy during compression, and effectively ensure the continuity of task execution.
[0006] According to one aspect of the present invention, a multi-level dialogue context adaptive management method is provided, comprising:
[0007] Obtain the current number of lexical units in the dialogue context; wherein, the dialogue context includes tool return results, tool call parameters, and dialogue history messages;
[0008] If the number of current lexical units is greater than a first preset threshold, the tool result summary compression is performed on the tool return result, and multi-strategy structure-aware compression is performed on the tool call parameters using field semantic role classification, recursive deep-aware truncation and cross-reference retention checks.
[0009] After compressing the results returned by the tool and the parameters invoked by the tool, the current number of lexical units is retrieved again;
[0010] If the number of current lexical units is greater than a second preset threshold, query-aware dialogue summary compression is performed on the dialogue history messages to obtain a dialogue summary, and the dialogue context message sequence is reconstructed based on the dialogue summary.
[0011] According to another aspect of the present invention, a multi-level dialogue context adaptive management device is provided, comprising:
[0012] The lexical count acquisition module is used to acquire the current lexical count in the dialogue context; wherein, the dialogue context includes tool return results, tool call parameters, and dialogue history messages;
[0013] The tool-side compression module is used to perform tool result summary compression on the tool return results when the number of current lexical units is greater than a first preset threshold, and to perform multi-strategy structure-aware compression on the tool call parameters by using field semantic role classification, recursive deep-aware truncation and cross-reference retention checks.
[0014] The lexical count update module is used to re-obtain the current lexical count after performing compression processing on the results returned by the tool and the parameters called by the tool;
[0015] The historical message compression and reconstruction module is used to perform query-aware dialogue summary compression on the dialogue history messages when the current number of lexical units is greater than a second preset threshold, to obtain a dialogue summary, and to reconstruct the dialogue context message sequence based on the dialogue summary.
[0016] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0017] At least one processor;
[0018] and a memory communicatively connected to the at least one processor;
[0019] The memory stores a computer program that can be executed by the at least one processor, which is then executed by the at least one processor to enable the at least one processor to perform the multi-level dialogue context adaptive management method according to any embodiment of the present invention.
[0020] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the multi-level dialogue context adaptive management method according to any embodiment of the present invention.
[0021] The technical solution of this invention includes: obtaining the current number of tokens in the dialogue context; if the current number of tokens is greater than a first preset threshold, performing tool result summary compression on the tool return results, and performing multi-strategy structure-aware compression on the tool call parameters using field semantic role classification, recursive deep-aware truncation, and cross-reference retention checks; after compressing the tool return results and tool call parameters, re-obtaining the current number of tokens; if the current number of tokens is greater than a second preset threshold, performing query-aware dialogue summary compression on the dialogue history messages to obtain a dialogue summary, and reconstructing the dialogue context message sequence based on the dialogue summary. This technical solution uses a three-layer progressive compression to cover all token sources, solving the technical problem of existing technologies having a single compression dimension and failing to cover all token sources, leading to window overflow. Through multi-strategy structure-aware compression, it solves the technical problem of existing dialogue summary methods indiscriminately compressing all historical messages without distinguishing the relevance of information to the current task, resulting in the loss of key information during compression, thus improving the information retention accuracy during the compression process.
[0022] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0024] Figure 1 A flowchart of a multi-level dialogue context adaptive management method provided in an embodiment of the present invention;
[0025] Figure 2 A flowchart of another multi-level dialogue context adaptive management method provided in an embodiment of the present invention;
[0026] Figure 3 A flowchart of yet another multi-level dialogue context adaptive management method provided in an embodiment of the present invention;
[0027] Figure 4 A schematic diagram of the structure of a multi-level dialogue context adaptive management device provided in an embodiment of the present invention;
[0028] Figure 5 A schematic diagram of the structure of an electronic device for implementing the multi-level dialogue context adaptive management method of this invention. Detailed Implementation
[0029] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0030] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0031] To further clarify the technical effects of the present invention, the prior art, existing defects, and the overall technical solution of the present invention will be described before introducing specific embodiments.
[0032] Defect 1: The compression granularity is limited, failing to cover all token sources.
[0033] Existing technologies (such as Agno single-layer compression) only process the return results of tool calls, ignoring that the tool call parameters themselves may be very long (e.g., large chunks of code sent by the LLM to the code writing tool, or the complete file content sent to the file writing tool), and that the dialogue history messages themselves (the inference process text of the LLM, the user's multi-turn instructions, etc.) are also constantly expanding.
[0034] Defect 2: The compression process is unaware of the semantic relevance of information to the current task.
[0035] Existing technologies (such as Claude Code auto-compact) do not distinguish the priority of information when generating dialogue summaries. This may result in the compression and loss of key information that is highly relevant to the current task, while retaining earlier requirements discussions that are less relevant to the current task.
[0036] Defect 3: Compression and task state management are completely decoupled, resulting in the loss of task state after compression.
[0037] In an agent with task management capabilities, after context compression, the agent loses its awareness of the current task list, resulting in: (1) forgetting tasks that have not yet been completed; (2) repeatedly executing completed tasks; and (3) being unable to correctly report task progress.
[0038] To address the three shortcomings mentioned above, this invention proposes a three-layer progressive context compression and intelligent task state recovery scheme, with the specific improved design as follows:
[0039] To address the limitation of single-granularity compression: a three-layer progressive compression method is adopted to fully cover all word source sources.
[0040] This invention designs a three-layer progressive compression architecture, which performs progressive compression from fine to coarse for three types of token sources: tool return results, tool call parameters, and dialogue history messages.
[0041] Layer 1 – Tool Result Summary Compression: Before each LLM call, estimate the total number of tokens. When the number exceeds a first preset threshold, call LLM to generate a summary for each tool return result, replace the original result with the summary, and reduce the size of the tool return result.
[0042] Layer 1.5 – Multi-strategy Structure-Aware Compression of Tool Call Parameters: This is a unique compression layer in this invention. After Layer 1 is completed, structure-aware compression is performed on extremely long tool call parameters—differentiation is achieved through field semantic role classification (identifier class / metadata class / content class), recursive depth-aware truncation applies a truncation threshold that decreases with depth to nested structures, and cross-reference retention checks prevent key identifiers related to the current dialogue from being truncated. This layer achieves efficient compression while maintaining the syntactic integrity of structured data.
[0043] The second layer (Layer2) – query-aware dialogue summary compression based on relevance pre-scoring: After Layer1 and Layer1.5 are executed, the number of tokens is recalculated. If it still exceeds the second preset threshold, dialogue-level summary compression is triggered.
[0044] The three layers are linked by conditional triggers: the compression effect of Layer 1 and Layer 1.5 is determined by recounting the token to decide whether Layer 2 is triggered. In the case of mild expansion, only light local compression is performed, and in the case of heavy expansion, it is automatically upgraded to full compression, so as to achieve adaptive adjustment of compression intensity.
[0045] To address the deficiency of semantic relevance, a three-stage summarization strategy combining relevance pre-scoring and budget allocation is adopted.
[0046] In Layer 2, a three-stage query-aware summarization pipeline is adopted: (1) In the first stage, the semantic relevance score of each historical message to the user's current query is calculated through lightweight text vectorization. The scoring formula integrates three dimensions: semantic similarity, temporal proximateness, and message type bonus; (2) In the second stage, the messages are divided into three priority groups based on the scoring results, and the token reservation budget of each group is allocated according to a preset ratio (55% for high priority group, 30% for medium priority group, and 15% for low priority group); (3) In the third stage, the pre-scoring results and budget constraints are embedded into the summary request, and the LLM performs refined summarization under quantitative guidance. After compression, the message list is reconstructed into a structure of system message + summary merged message, and the output security is ensured by accurate counting by the tokenizer and ratio-based truncation protection.
[0047] To address the deficiency of task status loss: An intelligent task status recovery and adaptive continuous monitoring mechanism has been added.
[0048] Upon Layer 2 triggering, the system automatically queries the task status management module for a list of incomplete tasks. Tasks are then sorted by query relevance (using a vectorized relevance scoring method) to prioritize tasks most relevant to the current query. Task dependency topology annotation explicitly labels the execution order constraints between tasks. After filtering out fully completed task groups, the remaining task statuses are injected into the context. Simultaneously, an adaptive control model (step threshold, maximum number of reminders, real-time step counter, frequency decay factor) is introduced for continuous monitoring: when the agent has not used the task management tool for several consecutive steps, a reminder message is automatically injected. After each reminder, the step threshold increases by the decay factor to reduce the frequency of subsequent interference.
[0049] The technical solution of the present invention has at least the following technical effects:
[0050] (1) Unlimited dialogue length: The three-layer progressive compression covers all token sources, allowing the agent to work continuously for dozens or even hundreds of rounds of dialogue without being interrupted by context overflow. Since the second layer of compression compresses the historical dialogue into a summary with a fixed upper limit (such as 2000 tokens) after each trigger, the total amount of context changes from linear growth O(k) to a bounded constant O(1) mode, fundamentally eliminating the risk of context overflow.
[0051] (2) High accuracy in information preservation in compression: The three-stage query-aware summary pipeline provides an objective and quantitative relevance measure through vector similarity pre-scoring. Through algorithmic three-level budget allocation, the summary token budget is tilted towards high-priority information that is directly related to the current task, so that the budget obtained is significantly higher than the uniform allocation of the indiscriminate summary scheme. This effectively preserves key error stacks, file paths and code snippets and other specific data, and avoids these information being replaced by general descriptions in compression.
[0052] (3) Task continuity guarantee: After compression, the list of unfinished tasks is automatically restored from the task status management module. The agent is guided to focus on the most relevant tasks by sorting the task-query relevance. The execution order is guaranteed by task dependency topology labeling. The adaptive control model (including frequency attenuation factor) achieves a balance between continuous monitoring and avoiding interference.
[0053] Figure 1 This is a flowchart illustrating a multi-level dialogue context adaptive management method provided in an embodiment of the present invention. This embodiment is applicable to context window management in long dialogue scenarios for intelligent agents. The method can be executed by a multi-level dialogue context adaptive management device, which can be implemented in hardware and / or software and can be configured in a computer device. Figure 1 As shown, the method specifically includes the following steps:
[0054] S110. Obtain the current number of lexical units in the dialogue context; wherein, the dialogue context includes the tool return results, tool call parameters, and dialogue history messages.
[0055] The dialogue context can be understood as data generated in long dialogue scenarios, such as tool return results, tool call parameters, and dialogue history messages. The current word count can be the current token count.
[0056] Specifically, the current number of tokens in the dialogue context can be obtained in real time. For example, before each LLM call, the tokenizer can be used to accurately estimate the total number of tokens in the current message list.
[0057] S120. If the current number of lexical units is greater than a first preset threshold, perform tool result summary compression on the tool return result, and perform multi-strategy structure-aware compression on the tool call parameters using field semantic role classification, recursive deep-aware truncation and cross-reference retention checks.
[0058] The first preset threshold can be a pre-defined value used to determine whether the tool's context data needs to be compressed. The tool return result can be the data returned after the tool is called, and the tool call parameters can be the parameters required to call the tool.
[0059] Understandably, as the number of dialogue rounds increases, a large number of tool call parameters and tool return results accumulate in the context window.
[0060] In this embodiment of the invention, the current number of lexical units can be compared with a first preset threshold. If the current number of lexical units is greater than the first preset threshold, it indicates that a large number of tool call parameters and tool return results have accumulated in the context window. Therefore, the tool call parameters and tool return results can be compressed separately.
[0061] For the tool's returned results, a tool result summary compression can be performed, which simplifies the returned results. For the tool's call parameters, multi-strategy structure-aware compression can be performed based on field semantic role classification, recursive deep-aware truncation, and cross-reference retention checks.
[0062] It should also be noted that multi-strategy structure-aware compression combines multiple processing mechanisms. It performs multi-strategy structure-aware compression on extremely long tool call parameters. Specifically, it achieves differentiated preservation through field semantic role classification (identifier class / metadata class / content class), applies a truncation threshold that decreases with depth to nested structures through recursive depth-aware truncation, and avoids truncating key identifiers relevant to the current dialogue through cross-reference preservation checks. In this way, efficient compression can be achieved while maintaining the syntactic integrity of structured data.
[0063] In some possible implementations, the step of performing tool result summary compression on the tool return results when the current number of lexical units is greater than a first preset threshold includes: when the number of lexical units is greater than the first preset threshold, traversing the tool return results of each tool corresponding to the dialogue context; generating a concise summary that retains key business semantics for each tool return result, and replacing the tool return results with the concise summary.
[0064] The number of tools can be multiple, and the types of tools can also be various. For example, they can include code execution tools, file operation tools, and database query tools. This embodiment does not impose specific restrictions on the type and number of tools.
[0065] Specifically, when the number of current lexical units exceeds a first preset threshold, the tool return results corresponding to all tools within the dialogue context can be traversed. For each return result, a corresponding concise summary can be generated, and then the concise summary is used to replace the tool return result.
[0066] For example, when the total number of tokens exceeds the first preset threshold T1, the return results of each tool call in the message list are traversed, and LLM is called to generate summary text for each tool return result, and the original result is replaced with the summary text.
[0067] The first preset threshold T1 is a configurable parameter, and its value needs to balance two factors: if T1 is too low, unnecessary compression will be triggered frequently in the early stages of the dialogue (increasing LLM call overhead and response latency); if T1 is too high, too many tokens may accumulate before compression is triggered in scenarios with intensive tool calls, squeezing the available space for subsequent dialogues. In typical AI-encoded agent scenarios (approximately 1000-1500 new tokens per round), a T1 value range of 6000-10000 tokens is recommended, with a default value of 8192.
[0068] The compression of the tool's returned results can be referred to as the first layer of compression. The goal of this layer is to reduce the size of the tool's returned results (approximately 40% of the total tokens) while preserving key semantic information in the results through LLM digests. Optionally, this layer can inherit from the CompressionManager implementation of the open-source framework Agno, serving as the first layer of the multi-layer compression system of this invention.
[0069] S130. After performing compression processing on the tool's returned results and the tool's calling parameters, the current number of lexical units is obtained again.
[0070] The current number of lexical units in this step is the latest number of lexical units obtained after the tool result summary compression and multi-strategy structure-aware compression have been completed.
[0071] S140. If the number of current lexical units is greater than the second preset threshold, perform query-aware dialogue summary compression on the dialogue history messages to obtain a dialogue summary, and reconstruct the dialogue context message sequence based on the dialogue summary.
[0072] The second preset threshold can be another pre-set value used to determine whether the dialogue history messages need to be compressed. The second preset threshold is greater than the first preset threshold.
[0073] In this embodiment of the invention, if the current number of lexical units is greater than a second preset threshold, it indicates that the number of lexical units in the dialogue context is very large. The dialogue history messages in the dialogue context can then be further compressed. These dialogue history messages can be data generated during historical question-and-answer processes that differs from tool return results and tool call parameters. They can also be interaction messages between the user and the large language model, such as text-based interaction data like past user questions and the large language model's responses.
[0074] It should be understood that query-aware dialogue summary compression refers to summarizing historical dialogue messages based on query semantics. In compressing historical dialogue messages, instead of a uniform, general compression, the process is guided by the core semantics of the current user's query, prioritizing the retention of highly relevant historical content and simplifying irrelevant content. For example, if the user's latest query is "view last week's report data," then the query semantics could be "retrieve last week's report." When compressing historical dialogue messages, priority can be given to retaining historical dialogues related to reports and data queries, while removing irrelevant content.
[0075] Furthermore, the compressed summary is used to reconstruct the dialogue context message sequence. This step specifically compresses historical dialogue data to further control the overall data volume and ensure the normal operation of the dialogue process.
[0076] The technical solution of this invention includes: obtaining the current number of tokens in the dialogue context; if the current number of tokens is greater than a first preset threshold, performing tool result summary compression on the tool return results, and performing multi-strategy structure-aware compression on the tool call parameters using field semantic role classification, recursive deep-aware truncation, and cross-reference retention checks; after compressing the tool return results and tool call parameters, re-obtaining the current number of tokens; if the current number of tokens is greater than a second preset threshold, performing query-aware dialogue summary compression on the dialogue history messages to obtain a dialogue summary, and reconstructing the dialogue context message sequence based on the dialogue summary. This technical solution uses a three-layer progressive compression to cover all token sources, solving the technical problem of existing technologies having a single compression dimension and failing to cover all token sources, leading to window overflow. Through multi-strategy structure-aware compression, it solves the technical problem of existing dialogue summary methods indiscriminately compressing all historical messages without distinguishing the relevance of information to the current task, resulting in the loss of key information during compression, thus improving the information retention accuracy during the compression process.
[0077] Figure 2 This flowchart illustrates another multi-level dialogue context adaptive management method provided by an embodiment of the present invention. Based on the above embodiments, this embodiment further optimizes the multi-strategy structure-aware compression process. Technical terms that are the same as or corresponding to those in the above embodiments will not be repeated here. Figure 2 As shown, the method specifically includes the following steps:
[0078] S210. Obtain the current number of lexical units in the dialogue context; wherein, the dialogue context includes tool return results, tool call parameters, and dialogue history messages.
[0079] S220. If the current number of lexical units is greater than a first preset threshold, perform tool result summary compression on the results returned by the tool.
[0080] After the first layer of compression is completed, multi-strategy structure-aware compression is performed on the tool call parameters (arguments in the tool_calls field) in all historical assistant messages. Unlike the token-level statistical compression method in the prior art, this layer comprehensively uses three complementary mechanisms, namely field semantic role classification, recursive deep-aware truncation, and cross-reference retention checks, while maintaining the syntactic integrity of structured data, corresponding to steps S230-S260.
[0081] S230. Parse the tool call parameters and generate a hierarchical key-value tree corresponding to the tool call parameters.
[0082] Specifically, the parameters invoked by the tool can be parsed and converted into a hierarchical key-value tree data structure.
[0083] S240. According to the preset field naming rules, for all fields in the hierarchical key-value tree, the field semantic role classification is used to divide them into non-truncation fields and truncation fields.
[0084] The preset field naming rules can be pre-defined rules used to distinguish field types. Non-truncation fields cannot have their content deleted, while truncation fields can have their content simplified.
[0085] Specifically, all fields in the tree can be categorized according to preset naming rules, distinguishing between fields that cannot be truncated and fields that can be truncated.
[0086] In one possible implementation, according to a preset field naming rule, all fields within the hierarchical key-value tree are classified using field semantic roles to obtain untruncation fields and truncation fields: according to the preset field naming rule, the fields within the hierarchical key-value tree are divided into identifier fields, metadata fields, and content fields; the identifier fields and the metadata fields are determined as the untruncation fields, and the content fields are determined as the truncation fields.
[0087] Specifically, according to the preset field naming rules, the fields in the hierarchical key-value tree are divided into identifier fields, metadata fields, and content fields. Furthermore, identifier fields and metadata fields are defined as non-truncation fields, while content fields are defined as truncation fields.
[0088] It should be understood that, unlike a simple approach that applies a uniform truncation threshold to all fields, this embodiment of the invention automatically categorizes fields into three roles—identifier, metadata, and content—based on the semantic patterns of their names. Identifier fields (such as file_path, user_id) and metadata fields (such as encoding, format) are typically short but have extremely high semantic value and are retained in their entirety without truncation; content fields (such as content, code, output) are typically long and contain a large amount of compressible redundancy, and are selectively truncated.
[0089] The classification of field semantic roles is achieved through configurable field name pattern matching rules. The default rule set covers common AI agent tool parameter naming conventions (such as file_path, content, query, result, etc.), and users can customize and extend the rule set according to the parameter naming specifications of specific tools. When a field name does not match any preset rules, the processing method is determined by the length of the field value: fields exceeding the truncation threshold are treated as content fields and truncated; otherwise, they are retained in their entirety.
[0090] For example, the Layer 1.5 multi-strategy structure-aware compression process is as follows:
[0091] This process takes the tool_call.arguments parameter as input and performs layered compression on the structured parameter data. The overall process is as follows:
[0092] Step 0: Tool-level Admission Determination
[0093] Perform a pre-compression check on the current tool call parameters:
[0094] If the tool name is in the exemption list, compression will be skipped and the complete parameters will be retained;
[0095] If the total length of the parameters is less than the preset character threshold, then compression is skipped.
[0096] Other cases will proceed to the next processing step.
[0097] Step 1: Structured parsing and type identification
[0098] Parse the input parameter data into a unified structure:
[0099] If it is in JSON format, the key-value tree structure will be obtained directly after successful parsing.
[0100] If it is a YAML, XML or other structured format, convert it into a unified key-value tree structure;
[0101] If parsing fails (for plain text data), a degradation strategy is adopted: the first N characters are retained, and a truncated note is appended, and the process ends.
[0102] Step 2: Field Semantic Role Classification
[0103] For each field in the key-value tree, it is divided into three categories based on field name pattern matching:
[0104] Identifier field: Matching In the same mode, marked as "fully preserved", no truncation is performed;
[0105] Metadata field: Matching The mode is marked as "fully preserved";
[0106] Content-related fields: Matching patterns such as content, body, data, text, code, output, and result, marked as "truncation-friendly", and proceeding to the subsequent truncation processing flow.
[0107] S250. Perform recursive depth-aware truncation processing on the truncation field to obtain the field to be processed.
[0108] Specifically, for truncated fields, the depth of their nesting level can be determined, and the truncated fields can be truncated based on this depth to obtain the fields to be processed.
[0109] In one possible implementation, the recursive deep-aware truncation process performed on the truncation field to obtain the field to be processed includes: identifying the nesting level of the truncation field in the hierarchical key-value tree, and matching the corresponding text retention threshold according to the nesting level; traversing the nested objects and array structure of the truncation field, and performing point-to-point truncation on the excessively long text at each level based on the text retention threshold; and retaining the original structure identifier and truncation remarks information of the field after truncation to obtain the field to be processed.
[0110] Nesting level refers to the hierarchical position of a field in a hierarchical key-value tree, and the text retention threshold can be a pre-set maximum allowed character length. The deeper the nesting level, the smaller the matching text retention threshold. Targeted truncation refers to performing content deletion operations at a specified position in excessively long text. The structure identifier and truncation remarks are used to maintain the field structure and record the truncation behavior, respectively.
[0111] Specifically, the nesting level of the truncated field within the key-value tree is identified, and a corresponding text retention threshold is matched based on the level. The deeper the nesting level, the smaller the text retention threshold is set. Furthermore, the nested objects and array structures of the field can be traversed layer by layer, and excessively long texts can be truncated at specific points according to the text retention threshold. After truncation, the original structural identifiers and remarks are retained, generating the field to be processed.
[0112] It is understood that the recursive depth-aware truncation in this embodiment of the invention involves a truncation threshold that decreases with nesting depth for tool call parameters containing nested structures. Let the truncation threshold function be... Where d is the current nesting depth (root node d=0), and a is the depth decay coefficient (default value 0.5). For example, when T_content=200 characters and a=0.5, the truncation threshold for the root-level content class field is 200 characters, 133 characters at depth 1, and 100 characters at depth 2. This design is based on the following observation: In intelligent agent tool invocation scenarios, shallow fields usually carry core operation information (such as the main body of the written code), while deeply nested fields usually contain auxiliary details (such as nested configuration items and formatted metadata), and their contribution to the LLM's understanding of the operation intent decreases.
[0113] The depth attenuation coefficient 'a' is a configurable parameter that controls the aggressiveness of truncation in deep nesting. The larger 'a' is, the more aggressive the deep truncation; the smaller 'a' is, the more uniform the truncation thresholds are across all layers. The default value is 0.5, at which point the truncation thresholds for layers at depths of 0 / 1 / 2 / 3 are T, 0.67T, 0.5T, and 0.4T, respectively, ensuring that each layer retains at least 40% of the basic truncation length.
[0114] The field length truncation threshold T_content is a configurable parameter. If T_content is too small, too much information in content-type fields will be lost; if T_content is too large, the compression effect will be insignificant. The default value is 200 characters. In typical AI coding tool scenarios, 200 characters are usually sufficient to cover key semantic information such as import statements and function signatures, and the beginning of the file content.
[0115] For example, the Layer 1.5 multi-strategy structure-aware compression process also includes:
[0116] Step 3: Recursive Depth-Aware Truncation
[0117] For field values marked "truncate", hierarchical truncation is performed according to the following rules:
[0118] If the field value is a string and its length is greater than the current truncation threshold T(d), then retain the first T(d) characters and append a truncation note...(truncated, original {len} chars);
[0119] If the field value is a nested object or array (recursive structure), then calculate the nesting depth d of the current field and apply the formula. Calculate the truncation threshold, where a is the depth attenuation coefficient; then recursively apply steps 2 to 3 to the nested structure.
[0120] If the field value is a basic type such as number, boolean, or null, and the length does not exceed T(d), then the content remains unchanged.
[0121] S260. Obtain the set of key identifiers in the dialogue history messages, and perform cross-reference retention checks on the fields to be processed based on the set of key identifiers to obtain the multi-strategy structure-aware compressed tool call parameters.
[0122] In one possible implementation, the cross-reference retention check performed on the field to be processed based on the set of key identifiers includes: determining whether the field to be processed contains any identifier in the set of key identifiers; if so, retaining the associated text of the preset interval before and after the corresponding identifier, and keeping the original content of the remaining fields after truncation.
[0123] The preset range can be a fixed character range defined around the identifier. Associated text refers to semantically related content surrounding the identifier. The truncated original content refers to the text formed after the field is truncated.
[0124] In this embodiment of the invention, to avoid accidental deletion of cross-reference key identifiers and related content during truncation operations and to ensure the integrity and usability of parameter reference relationships, it can be determined whether the field to be processed contains any identifier within the set of key identifiers. If a corresponding identifier is detected, the associated text within a preset interval before and after the identifier needs to be retained, while the rest of the field content remains in the truncated state.
[0125] For example, the Layer 1.5 multi-strategy structure-aware compression process also includes:
[0126] Step 4: Cross-reference retention check
[0127] For the truncated field values in step 3, add cross-reference related text protection:
[0128] Scan the K most recent messages in the current dialogue context (K is a configurable backtracking window size) and extract the set S of identifiers that appear in them, including file paths, variable names, URLs, etc.
[0129] If the truncated field value contains any identifier in S, then retain the local associated text of ±W characters before and after the identifier (W is a configurable context window), and the rest maintains the truncation result of step 3.
[0130] If no identifier is included, the truncation result from step 3 remains unchanged.
[0131] Step 5: Reserialization
[0132] The processed key-value tree is reserialized into a string consistent with the original format to obtain the compressed tool call parameters.
[0133] Understandably, even if a content field is marked as needing to be truncated, if its value contains a key identifier that has recently appeared in the current dialog context (such as the file path being discussed or the name of the function being debugged), then an additional local area containing that identifier (a context window of W characters before and after the identifier position) will be retained in the truncation result.
[0134] The method for extracting the cross-reference identifier set S is as follows: From the K most recent messages, extract file path patterns (matching path formats separated by / or \), URL patterns (matching strings starting with http(s): / / ), and code identifier patterns (matching variable / function names with camelCase or underscore names) using regular expression matching. After deduplication, set S is formed. When set S is empty (e.g., at the beginning of the conversation before any specific files or code are involved), step 4 is equivalent to not executing it, and the compression result is entirely determined by steps 2-3. This is a reasonable degradation behavior—at this point, there are no critical identifiers in the conversation that need to be retained across references.
[0135] Specific example: Parameters for calling a file writing tool:
[0136] {
[0137] "file_path": " / src / api / handler.py",
[0138] ,
[0139] "encoding": "utf-8",
[0140] "create_dirs": true,
[0141] "metadata": {
[0142] "author": "agent",
[0143] "timestamp": "2024-01-15T10:30:00Z",
[0144] "related_config": {
[0145] "db_connection": "postgresql: / / localhost:5432 / app ... (500-character connection configuration)"
[0146] }
[0147] }
[0148] }
[0149] After Layer 1.5 processing: file_path (identifier class), encoding (metadata class), and create_dirs (basic type) are fully preserved; content (content class, root level, T=200) is truncated to 200 characters; metadata.related_config.db_connection (content class, depth 2, T=100) is truncated to 100 characters; metadata.author and metadata.timestamp (short values) are fully preserved. If the current conversation is discussing a bug in the handle_login function, the area in the content field containing "handle_login" will be additionally preserved under cross-reference retention checks.
[0150] Optionally, embodiments of the present invention also include a selective tool exemption mechanism: through a configurable exemption list, specific tools (such as analysis tools that need to retain complete parameters for debugging or auditing) can skip the parameter compression step.
[0151] S270. After performing compression processing on the tool's returned results and the tool's calling parameters, the current number of lexical units is obtained again.
[0152] S280. If the number of current lexical units is greater than the second preset threshold, perform query-aware dialogue summary compression on the dialogue history messages to obtain a dialogue summary, and reconstruct the dialogue context message sequence based on the dialogue summary.
[0153] The technical solution of this invention includes: obtaining the current number of tokens in the dialogue context; if the current number of tokens is greater than a first preset threshold, performing tool result summary compression on the tool return results, and performing multi-strategy structure-aware compression on the tool call parameters using field semantic role classification, recursive deep-aware truncation, and cross-reference retention checks; after compressing the tool return results and tool call parameters, re-obtaining the current number of tokens; if the current number of tokens is greater than a second preset threshold, performing query-aware dialogue summary compression on the dialogue history messages to obtain a dialogue summary, and reconstructing the dialogue context message sequence based on the dialogue summary. This technical solution uses a three-layer progressive compression to cover all token sources, solving the technical problem of existing technologies having a single compression dimension and failing to cover all token sources, leading to window overflow. Through multi-strategy structure-aware compression, it solves the technical problem of existing dialogue summary methods indiscriminately compressing all historical messages without distinguishing the relevance of information to the current task, resulting in the loss of key information during compression, thus improving the information retention accuracy during the compression process.
[0154] Figure 3 This is a flowchart illustrating another multi-level dialogue context adaptive management method provided by an embodiment of the present invention. Based on the above embodiments, this embodiment further optimizes the query-aware dialogue summary compression process. Technical terms that are the same as or corresponding to those in the above embodiments will not be repeated here.
[0155] like Figure 3 As shown, the method specifically includes the following steps:
[0156] S310. Obtain the current number of lexical units in the dialogue context; wherein, the dialogue context includes the tool return results, tool call parameters, and dialogue history messages.
[0157] S320. If the number of current lexical units is greater than a first preset threshold, perform tool result summary compression on the tool return result, and perform multi-strategy structure-aware compression on the tool call parameters using field semantic role classification, recursive deep-aware truncation and cross-reference retention checks.
[0158] S330. After performing compression processing on the tool's returned results and the tool's calling parameters, the current number of lexical units is obtained again.
[0159] To address the problem of key information loss caused by indiscriminate summarization in existing technologies, this invention introduces a three-stage query-aware summarization pipeline in the second layer of compression: the first stage pre-scores the relevance of each historical message to the current query through lightweight vector similarity calculation; the second stage allocates token retention budgets for each level according to three priority levels based on the scoring results; and the third stage generates refined summaries by LLM under budget constraints. The specific process can be found in steps S340-S370.
[0160] S340. If the current number of lexical elements is greater than the second preset threshold, separate the system messages, current user queries, and pending rating history messages from the dialogue history messages.
[0161] System messages can be understood as prompts and configuration messages pushed by the dialogue system itself. Current user query refers to the question or command currently entered by the user. Pending rating history messages refer to past dialogue content that needs to be relevance determined.
[0162] Specifically, the dialogue history messages can be broken down into system messages, current user queries, and pending rating history messages.
[0163] It should also be noted that after Layer 1 and Layer 1.5 have finished executing, the total number of tokens in the message list is recalculated. If it still exceeds the second preset threshold T2, the second layer of compression is triggered.
[0164] The second preset threshold T2 is a configurable parameter, and it must satisfy T2 > T1. The gap between T2 and T1 determines the triggering frequency of Layer2: the larger the gap, the more the system relies on the local compression of Layer1 and Layer1.5, and the lower the triggering frequency of Layer2; the smaller the gap, the more aggressively Layer2 is triggered, and the more frequently full compression occurs. It is recommended that the value of T2 be 1.3-2.0 times that of T1, with a default value of 12800 (approximately 1.56 times the default value of T1, 8192).
[0165] S350. Calculate the comprehensive relevance score corresponding to each of the historical messages to be scored based on semantic similarity, temporal proximateness, and message type bonus.
[0166] Semantic similarity, temporal recency, and message type bonus are reference dimensions used to evaluate message relevance. A comprehensive relevance score can be calculated for each historical message to be scored based on these three dimensions: semantics, temporal sequence, and message type. This comprehensive relevance score characterizes the degree of relevance between the historical message to be scored and the current user query.
[0167] In one possible implementation, the step of calculating the comprehensive relevance score corresponding to each of the historical messages to be scored based on semantic similarity, temporal proximateness, and message type weighting includes: performing text vectorization processing on the current user query and each of the historical messages to be scored to generate corresponding semantic representation vectors; calculating the semantic similarity between the two sets of semantic representation vectors, and introducing message temporal features and role type features; and performing weighted operations on the semantic similarity, the temporal features, and the role type features to obtain the comprehensive relevance score corresponding to each of the historical messages to be scored.
[0168] Specifically, the current user query and each historical message to be rated can be vectorized into text to generate corresponding semantic representation vectors. Then, the semantic similarity between the two sets of vectors is calculated, while temporal and role-type features are introduced. A weighted operation is performed on the three types of feature data to obtain a comprehensive relevance score for each historical message.
[0169] For example, the first stage: message-level relevance pre-scoring
[0170] Step 1: Separate the messages. Divide the message list into three parts: system messages (retained and not included in the scoring), the last user query Q (retained and used as the scoring anchor), and all other messages M1, M2, ..., Mn (the set to be scored).
[0171] Step 2: Text Representation Extraction. For the user's current query Q and each message Mi to be rated, semantic vector representations are obtained through text vectorization. Specifically, a pre-trained lightweight text encoding model (such as a multilingual sentence-transformer model with approximately 120 million parameters) is used to vectorize the text, obtaining the query vector v_Q and the message vector v_Mi.
[0172] To control encoding overhead, a truncation sampling strategy is adopted for each message: the first L_head characters and the last L_tail characters of the message text are concatenated as the encoding input (default L_head=200, L_tail=100), covering the beginning context and the end conclusion of the message, thus avoiding the computational overhead of encoding the complete long text.
[0173] The reasons for choosing the sentence-transformer model instead of using the main LLM itself for encoding are: (1) Controllable encoding overhead - the total time for vectorizing the truncated sampled text of 30 messages is about 50-200 milliseconds, which is much lower than the several-second delay of an LLM call; (2) The model supports multilingual input; (3) The encoding model is independent of the main LLM, is not limited by the context window, and does not occupy the token budget of the main LLM.
[0174] Step 3: Relevance Score Calculation. Calculate the relevance score of each message to the user's current query:
[0175]
[0176] Among them, 1. To calculate the cosine similarity between the query vector and the message vector, the original value range is [-1, 1]. This is achieved using the formula... Normalization to [0,1] reflects semantic relevance;
[0177] 2. The time-series position normalized value of the message (n is the total number of messages, and the value of i is larger for newer messages), which reflects the time proximateness;
[0178] 3. Bonuses for message types: Messages containing tool call results (role=tool) receive a bonus of 0.1, assistant messages containing tool calls (including the tool_calls field) receive a bonus of 0.05, and plain text conversation messages receive a bonus of 0.
[0179] 4. w1, w2, and w3 are weighting coefficients with default values of 0.6, 0.25, and 0.15, respectively, satisfying w1 + w2 + w3 = 1.
[0180] Weight configuration is based on the following factors: semantic relevance (w1=0.6) as the primary factor, temporal proximateness (w2=0.25) as a secondary factor, and message type bonus (w3=0.15) as a fine-tuning factor for scenario specialization.
[0181] S360. Based on the comprehensive relevance score, the priority groups corresponding to the historical messages to be scored are divided, and a corresponding summary term budget is allocated to each priority group.
[0182] Priority groups refer to message levels categorized based on relevance. Summary lexicon budget refers to the maximum lexicon allocation for different groups.
[0183] Specifically, based on the comprehensive relevance score, the historical messages to be scored can be divided into different priority groups, and a summary term budget can be allocated to each group.
[0184] In some possible implementations, the step of dividing the historical messages to be scored into priority groups based on the comprehensive relevance score and allocating corresponding summary term budgets to each priority group includes: dividing the historical messages to be scored into at least two priority groups according to the comprehensive relevance score; and configuring a fixed percentage of the summary term budget for each priority group.
[0185] Wherein, if there are no valid pending messages in any of the at least two priority groups, the summary term budget quota corresponding to that priority group is allocated to the other priority groups.
[0186] Specifically, historical messages to be scored can be divided into at least two priority groups based on the numerical range corresponding to the comprehensive relevance score. Then, a summary term budget is allocated to each group according to a fixed proportion. When a group has no valid messages, the idle term budget for that group is distributed to the other priority groups.
[0187] The advantage of this approach is that different budgets are allocated based on priority. High-priority groups receive more budget to ensure the completeness of core related content, while low-priority groups receive less budget to further compress redundant information. When a group has no valid messages, the idle budget can be reallocated to maximize the utilization of keyword resources.
[0188] For example, Phase Two: Three-Tier Priority Classification and Token Budget Allocation
[0189] Step 4: Three-level priority classification. Messages are classified into three priorities based on their relevance scores:
[0190]
[0191] t1 and t2 are priority thresholds, with default values of 0.65 and 0.35, respectively. Adaptive thresholds are supported: when the number of messages in a certain priority group exceeds 60%, t1 and t2 are automatically adjusted to the 67th and 33rd percentiles of the scoring list, respectively.
[0192] Step 5: Token Budget Allocation. Let the total digest token budget be B, and allocate it among three priorities according to the following rules:
[0193]
[0194]
[0195] The total summary budget B is a configurable parameter. If B is too small, the summary information density will be insufficient, and key information will be truncated and lost; if B is too large, the compression effect will be insignificant, and context saving will be limited. A recommended value for B is 1000-3000 tokens, with a default value of 2000 tokens. The value of B should be much smaller than the LLM context window size (usually no more than 2% of the window) to ensure sufficient space for subsequent dialogues after compression.
[0196] When a priority group is empty, its budget is redistributed proportionally to adjacent levels. If group P1 is empty, 70% of its budget is allocated to P2 and 30% to P3; if group P3 is empty, its entire budget is allocated to P2.
[0197] Step 6: Message sorting within each priority group. Within each priority group, messages are sorted in descending order of relevance score.
[0198] S370. Based on the priority group and the summary lexical budget, compress the historical message to be scored to obtain the dialogue summary, and reconstruct the dialogue context message sequence based on the dialogue summary.
[0199] In one possible implementation, the compression of the historical message to be scored based on the priority group and the summary lexicon budget includes: constructing a summary generation request based on the priority group, the summary lexicon budget, and the historical message to be scored; and guiding the generation of the dialogue summary corresponding to the historical message to be scored based on the summary generation request.
[0200] Specifically, a summary generation request can be constructed by combining priority groups, summary lexical budget, and historical messages to be scored. The LLM can then respond to this request and generate a dialogue summary of the historical messages to be scored.
[0201] For example, the third stage: LLM-bound summary generation
[0202] Step 7: Construct a summary request with budget constraints. Embed the pre-scoring results and budget allocation as quantitative guidance into the summary generation prompt template:
[0203] You are compressing a conversation to free up context space.
[0204] The user's current query is: [user_query]
[0205] The following messages have been categorized into three priority groups based on their relevance to the current query.
[0206] Please strictly adhere to the token budget limits for each group when generating the digest.
[0207] === P1 High Priority (Budget: Approximately [B1] tokens) ===
[0208] The context directly related to the current query.
[0209] Requirements: Retain specific data, facts, file paths, code snippets, and specific details.
[0210] Avoid general descriptions and retain the original data values.
[0211] [Messages from group P1, sorted in descending order of rating]
[0212] === P2 Medium Priority (Budget: Approximately [B2] tokens) ===
[0213] Important findings that may be useful for future research.
[0214] Requirements: Key findings and conclusions should be retained; the derivation process may be omitted.
[0215] [Messages from group P2, sorted in descending order of rating]
[0216] === P3 Low Priority (Budget: Approximately [B3] tokens) ===
[0217] Decisions and conclusions already made.
[0218] Requirements: Only retain the final decision, summarized in one sentence.
[0219] [Messages from Group P3, sorted in descending order of rating]
[0220] Do not include detailed task list items—these will be provided separately.
[0221] Write summaries in the same language as the users.
[0222] The total number of digests will be strictly controlled to within [B] tokens.
[0223] Step 8: Use LLM to generate the summary. Generate the summary using an independent auxiliary model instance, setting input truncation protection (truncating the text to be compressed if it exceeds 80,000 characters) and output token limits.
[0224] Step 9: Rebuild the message list. Rebuild the message list as a merged list of system messages with summaries and user queries. The format of the merged message is:
[0225] "[Conversation compressed -- auto_compact #N]
[0226] <context_summary> Abstract content< / context_summary>
[0227] Based on the above context, continue to address:
[0228] [Original user query]
[0229] Step 10: Output security verification. Use the tokenizer to calculate the actual number of tokens in the digest. If the limit is exceeded, truncate the data precisely based on the ratio of tokens to characters (leaving a 5% security margin).
[0230] Table 1 is a technical advantage analysis table of the three-stage production line, as shown in Table 1:
[0231] Table 1
[0232]
[0233] Compared to pure vector retrieval schemes: Schemes based solely on vector similarity can only select which messages to retain, and cannot refine or compress the content. This invention combines the quantitative evaluation capability of vector similarity with the semantic generalization capability of LLM, achieving optimal information density allocation through the complementary nature of these three elements.
[0234] It should be noted that the three-layer compression of this invention is not a simple serial superposition, but rather an organically coordinated compression system formed through conditional triggering, data transmission, and status feedback:
[0235] This solution achieves adaptive compression and control of dialogue context through a layered, interconnected process. The specific collaborative triggering logic is as follows:
[0236] 1. Basic compression layer processing
[0237] The system first performs Layer 1 (compression of tool return result summary) and Layer 1.5 (compression of tool call parameters with multi-strategy structure awareness) processing to complete the first round of simplification of the tool-side context data.
[0238] 2. Recounting Lexical Units
[0239] After completing the compression processing of Layer 1 and Layer 1.5, the system recounts the number of lexical units in the dialogue context to provide a basis for subsequent trigger determination.
[0240] 3. High-level compression trigger judgment
[0241] The system will compare the recounted number of tokens with a preset threshold (e.g., 12,800 tokens):
[0242] If the number of tokens does not exceed the threshold, it is determined that no further compression is needed, and the process ends.
[0243] If the number of lexical units exceeds the threshold, Layer2 (dialogue history message query-aware summary compression) processing is triggered.
[0244] 4. Task status synchronization processing
[0245] While triggering Layer2 compression, the system simultaneously calls the task status intelligent recovery module to sort the relevance of incomplete tasks, mark their dependencies, and inject the processed task status information into the reconstructed dialogue context message sequence, thus achieving coordinated linkage between compression and task management.
[0246] The fundamental difference from simple overlay is that the compression effect of Layer 1 and Layer 1.5 directly determines whether Layer 2 needs to be triggered (determined by recounting tokens); the execution of Layer 2, in turn, triggers the linkage of the task state recovery module. This progressive conditional triggering allows the system to perform only light local compression (Layer 1 + Layer 1.5) during mild token expansion, and automatically upgrade to full compression (Layer 1 + Layer 1.5 + Layer 2 + task state recovery) during severe expansion, achieving adaptive adjustment of compression intensity.
[0247] In addition, existing technologies also suffer from the problem of task state loss after compression: in intelligent agents with task management capabilities, the agent loses its awareness of the current task list after context compression, leading to problems such as forgetting tasks that have not yet been completed, repeatedly executing completed tasks, and failing to report progress correctly.
[0248] In some possible implementations, to address the issue of task state loss after compression, after reconstructing the dialogue context message sequence based on the dialogue summary, the set of incomplete tasks stored in the agent's task management module can be retrieved; the set of incomplete tasks can be grouped and filtered, and completed task groups can be removed; the tasks can be sorted based on semantic relevance and the dependency constraints between tasks can be labeled; the task state information after sorting and labeling is encapsulated into standard dialogue messages and injected into the reconstructed dialogue context message sequence.
[0249] In this context, the set of incomplete tasks refers to all task data that the agent has not yet completed. Semantic relevance refers to the degree of association between a task and the current dialogue content. Dependency constraints refer to the restrictions on the sequential execution and interrelationship of multiple tasks. Standard dialogue messages refer to message content whose format conforms to the requirements of the dialogue context.
[0250] Specifically, after reconstructing the dialogue context message sequence, the set of incomplete tasks stored within the intelligent entity can be retrieved. Tasks are grouped and filtered, with completed tasks removed. The remaining tasks are then sorted based on semantic relevance, and the dependencies between tasks are labeled. The information of completed tasks is encapsulated into standard dialogue messages and incorporated into the reconstructed context message sequence.
[0251] For example, after the second layer of compression is completed, the system automatically executes the following intelligent task status recovery process:
[0252] 1. Complete Layer 2 compression.
[0253] 2. To perform condition checks, all three of the following conditions must be met simultaneously:
[0254] `second_layer_compacted == True`
[0255] `todo_toolkit != None`
[0256] `todo_monitor_enabled == True`
[0257] 3. After the condition is met, proceed to step A: Obtain all task data.
[0258] Call the interface `todo_toolkit.get_all_tasks()`
[0259] 4. Step B: Task grouping and completion group filtering
[0260] Group tasks based on their task list IDs and remove all completed task groups.
[0261] 5. Execution Step C: Task - Query Relevance Ranking
[0262] The lightweight vector coding method from Section 6.3.1 is reused to calculate the relevance score of each task description to the current user query, and the tasks are sorted in descending order of the score within each group.
[0263] 6. Execution step D: Task depends on topology annotation
[0264] Read the `blockedBy` and `blocks` fields of the task to identify the dependency relationship, and mark the task dependency chain in the output content.
[0265] 7. Execute step E: Formatted injection
[0266] User messages are encapsulated as role attribute `role="user"` and identifier attribute `injected="todo_state"`. The message content includes task management operation rules, a list of incomplete tasks sorted by relevance, task dependency annotations, and progress statistics for each group of tasks.
[0267] 8. Once the process ends, the agent regains its task awareness and prioritizes processing the task most relevant to the current query.
[0268] Task-query relevance sorting can prioritize tasks most relevant to the current user's query, guiding the agent to focus on unfinished tasks most relevant to the current workflow.
[0269] Task dependency topology annotation can explicitly mark the dependency relationship in the injected task list when there are execution order constraints between tasks (such as "writing unit tests" depends on "implementing API interfaces"). This prevents the agent from trying to execute tasks that have not yet met the prerequisites due to loss of dependency information after compression.
[0270] In some possible implementations, the following are also included: configuring monitoring parameters; accumulating the number of inference steps that the agent has not called the task management tool for a continuous period of time through the step counter; when the number of inference steps reaches the inference step threshold and does not exceed the maximum number of reminders, injecting task reminder information into the dialogue context; after each injection of the task reminder information, adjusting the inference step threshold according to the frequency attenuation coefficient.
[0271] Specifically, when the agent invokes the task management tool, the step counter and the inference step threshold are reset. Monitoring parameters include the inference step threshold, maximum number of reminders, step counter, and frequency decay coefficient. The inference step threshold and maximum number of reminders are pre-configured monitoring values. The step counter is used to count the number of consecutive inferences. The frequency decay coefficient is used to dynamically adjust the threshold correction parameter. Task reminder information refers to the message content used to prompt the agent to handle corresponding tasks.
[0272] Specifically, the system uniformly configures four types of monitoring parameters and uses a step counter to count the number of inference steps the agent continuously calls the tool. When the number of steps reaches the inference step threshold but does not exceed the maximum number of reminders, a task reminder is injected into the dialogue context. After each reminder is completed, the system adjusts the inference step threshold using a frequency decay coefficient. When the agent calls the tool, the system resets the counter and the inference step threshold.
[0273] For example, in addition to the one-time recovery after compression, the present invention also introduces a continuous task status monitoring and reminder mechanism based on an adaptive control model, wherein the relevant parameters are described in Table 2:
[0274] Table 2
[0275]
[0276] Adaptive reminder frequency adjustment mechanism: After each reminder injection, the step threshold increases according to the following formula:
[0277]
[0278] Indicates the threshold for the next stage of inference, Indicates the current inference step threshold, This represents the frequency attenuation coefficient.
[0279] The first reminder is triggered at step 10, the second at step 15 (10 x 1.5), and the third at step 22 (15 x 1.5, rounded down). This design is based on the following consideration: if the agent does not use the task management tool after receiving a reminder, it may be currently executing a subtask requiring multiple consecutive steps (such as modifying code in multiple files). Too many reminders would interfere with its reasoning process. The adaptive decrease in reminder frequency reduces interference with the agent's normal reasoning while ensuring task awareness. When the agent actively uses the task management tool, the step threshold returns to the initial value I0, and the reminder count counter is reset to zero.
[0280] Monitoring and decision-making process: In each LLM inference request event—on the first request, inject a complete task status snapshot (including task management rules, a list of incomplete tasks sorted by relevance, and dependency annotations); on subsequent requests, check if the step counter has reached the current step threshold and if the number of reminders has not reached the limit. If the conditions are met, inject a brief reminder and a snapshot of the current task list, increment the step threshold according to the formula, and reset the counter; otherwise, do not inject and continue normal inference. When the result of each round of tool call is returned, check if it contains a call record of the task management tool. If it does, reset the step counter to zero and restore the step threshold to its initial value.
[0281] In this embodiment of the invention, a three-layer progressive compression architecture and an inter-layer linkage mechanism are set up.
[0282] This paper proposes a progressive, multi-layered compression architecture that covers three types of token sources: tool return results, tool call parameters, and dialogue history messages. Layer 1.5 (multi-strategy structure-aware compression for tool call parameters) achieves efficient compression while maintaining the syntactic integrity of structured data through three complementary mechanisms: field semantic role classification, recursive deep-aware truncation, and cross-reference retention checks. Conditional triggering linkages between the three layers are achieved through token recounting.
[0283] In this embodiment of the invention, a three-stage query-aware summarization method based on relevance pre-scoring and budget allocation is established. A three-stage pipeline of "vector similarity pre-scoring, algorithmic budget allocation, and LLM-constrained summarization" is introduced into dialogue summarization. A quantifiable and reproducible relevance scoring formula (combining semantic similarity, temporal recency, and message type bonuses) replaces the LLM black-box judgment, and an algorithmic three-level token budget allocation replaces the LLM's self-determined length distribution, significantly improving the certainty, repeatability, and interpretability of the summarization results.
[0284] In this embodiment of the invention, an intelligent linkage recovery mechanism for compression and task state management is set up. Context compression is linked with the agent's task state management system. After Layer 2 compression, the task state is injected after task-query relevance sorting and task dependency topology labeling. Continuous monitoring is achieved through an adaptive control model (including a reminder mechanism with a frequency attenuation factor), ensuring the continuity of compressed tasks from both recovery and maintenance dimensions.
[0285] Figure 4 This is a schematic diagram of the structure of a multi-level dialogue context adaptive management device provided in an embodiment of the present invention. Figure 4 As shown, the device includes:
[0286] The lexical quantity acquisition module 410 is used to acquire the current lexical quantity of the dialogue context; wherein, the dialogue context includes tool return results, tool call parameters and dialogue history messages;
[0287] The tool-side compression module 420 is used to perform tool result summary compression on the tool return result when the current number of lexical units is greater than a first preset threshold, and to perform multi-strategy structure-aware compression on the tool call parameters by using field semantic role classification, recursive deep-aware truncation and cross-reference retention checks.
[0288] The lexical quantity update module 430 is used to re-obtain the current lexical quantity after performing compression processing on the tool's returned results and the tool's call parameters;
[0289] The historical message compression and reconstruction module 440 is used to perform query-aware dialogue summary compression on the dialogue history messages when the current number of lexical units is greater than a second preset threshold, to obtain a dialogue summary, and to reconstruct the dialogue context message sequence based on the dialogue summary.
[0290] The technical solution of this invention includes: obtaining the current number of tokens in the dialogue context; if the current number of tokens is greater than a first preset threshold, performing tool result summary compression on the tool return results, and performing multi-strategy structure-aware compression on the tool call parameters using field semantic role classification, recursive deep-aware truncation, and cross-reference retention checks; after compressing the tool return results and tool call parameters, re-obtaining the current number of tokens; if the current number of tokens is greater than a second preset threshold, performing query-aware dialogue summary compression on the dialogue history messages to obtain a dialogue summary, and reconstructing the dialogue context message sequence based on the dialogue summary. This technical solution uses a three-layer progressive compression to cover all token sources, solving the technical problem of existing technologies having a single compression dimension and failing to cover all token sources, leading to window overflow. Through multi-strategy structure-aware compression, it solves the technical problem of existing dialogue summary methods indiscriminately compressing all historical messages without distinguishing the relevance of information to the current task, resulting in the loss of key information during compression, thus improving the information retention accuracy during the compression process.
[0291] In some possible implementations, the tool-side compression module 420 includes a tool result summary compression submodule, which is used for:
[0292] If the number of lexical elements is greater than a first preset threshold, the tool return results of each tool corresponding to the dialogue context are traversed.
[0293] For the results returned by each of the aforementioned tools, a concise summary that retains key business semantics is generated, and the tool's returned results are replaced with the concise summary.
[0294] In some possible implementations, the tool-side compression module 420 further includes a multi-strategy structure-aware compression submodule, which includes a field classification unit, a recursive truncation unit, and a cross-reference checking unit.
[0295] The field classification unit is used to parse the tool call parameters and generate a hierarchical key-value tree corresponding to the tool call parameters;
[0296] According to the preset field naming rules, for all fields in the hierarchical key-value tree, the field semantic role classification is used to divide them into non-truncation fields and truncation fields.
[0297] The recursive truncation unit is used to perform recursive depth-aware truncation processing on the truncationable field to obtain the field to be processed.
[0298] The cross-reference checking unit is used to obtain a set of key identifiers in the dialogue history messages, and perform cross-reference retention checks on the fields to be processed based on the set of key identifiers to obtain the multi-strategy structure-aware compressed tool invocation parameters.
[0299] In some possible implementations, the field classification unit is specifically used for:
[0300] According to the preset field naming rules, the fields in the hierarchical key-value tree are divided into identifier fields, metadata fields, and content fields;
[0301] The identifier field and the metadata field are determined as the non-truncation fields, and the content field is determined as the truncation field.
[0302] In some possible implementations, the recursive truncation unit is specifically used for:
[0303] Identify the nesting level of the truncated field in the hierarchical key-value tree, and match the corresponding text retention threshold according to the nesting level, wherein the deeper the nesting level, the smaller the matched text retention threshold;
[0304] Traverse the nested objects and array structures of the truncation field, and perform point-to-point truncation on the excessively long text at each level based on the text retention threshold.
[0305] After truncation, the original structural identifier and truncation remarks of the field are retained to obtain the field to be processed.
[0306] In some possible implementations, the cross-reference checking unit is specifically used for:
[0307] Determine whether the field to be processed contains any identifier within the set of key identifiers;
[0308] If so, the associated text within the preset range before and after the corresponding identifier will be retained, while the content of the remaining fields will remain as it was after truncation.
[0309] In some possible implementations, the historical message compression and reconstruction module 440 includes a dialogue summary generation submodule, which includes a scoring calculation unit, a group division and budget allocation unit, and a summary construction unit.
[0310] The scoring calculation unit is used to separate system messages, current user queries, and pending scoring history messages from the dialogue history messages;
[0311] Based on semantic similarity, temporal proximateness, and message type bonus, calculate the comprehensive relevance score corresponding to each of the aforementioned historical messages to be scored;
[0312] The grouping and budget allocation unit is used to divide the historical messages to be scored into priority groups according to the comprehensive relevance score, and allocate corresponding summary term budgets to each priority group.
[0313] The summary construction unit is used to compress the historical message to be scored based on the priority group and the summary lexicon budget to obtain the dialogue summary.
[0314] In some possible implementations, the scoring calculation unit is specifically used for:
[0315] The current user query and each of the historical messages to be rated are processed into text vectors to generate corresponding semantic representation vectors.
[0316] Calculate the semantic similarity between the two sets of semantic representation vectors, and introduce message timing features and role type features;
[0317] A weighted calculation is performed on the semantic similarity, the temporal features, and the role type features to obtain a comprehensive relevance score for each of the historical messages to be scored.
[0318] In some possible implementations, the grouping and budget allocation unit is specifically used for:
[0319] Based on the comprehensive relevance score, the historical messages to be scored are divided into at least two priority groups;
[0320] A fixed percentage of the summary term budget is allocated to each of the aforementioned priority groups;
[0321] Wherein, if there are no valid pending messages in any of the at least two priority groups, the summary term budget quota corresponding to that priority group is allocated to the other priority groups.
[0322] In some possible implementations, the summary construction unit is specifically used for:
[0323] Based on the priority group, the summary term budget, and the historical messages to be scored, a summary generation request is constructed;
[0324] Based on the summary generation request, the system guides the generation of the dialogue summary corresponding to the historical message to be scored.
[0325] In some possible implementations, the apparatus further includes a task information processing module, which is used for:
[0326] After reconstructing the dialogue context message sequence based on the dialogue summary, the set of unfinished tasks stored in the agent task management module is retrieved;
[0327] The incomplete task set is grouped and filtered, and the completed task group is removed. The tasks are sorted based on semantic relevance and the dependency constraints between tasks are marked.
[0328] After sorting and labeling, the task status information is encapsulated into standard dialogue messages and injected into the reconstructed dialogue context message sequence.
[0329] In some possible implementations, the device further includes a reminder control module, which is used for:
[0330] Configure monitoring parameters, including inference step threshold, maximum number of reminders, step counter, and frequency attenuation coefficient;
[0331] The step counter accumulates the number of inference steps that the agent has not called the task management tool for a continuous period of time. When the number of inference steps reaches the inference step threshold and does not exceed the maximum number of reminders, task reminder information is injected into the dialogue context.
[0332] After each injection of the task reminder information is completed, the inference step threshold is adjusted according to the frequency attenuation coefficient.
[0333] Specifically, when the agent invokes the task management tool, the step counter and the inference step threshold are reset.
[0334] The multi-level dialogue context adaptive management device provided in the embodiments of the present invention can execute the multi-level dialogue context adaptive management method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the method execution.
[0335] Figure 5 This is a schematic diagram of the structure of an electronic device for implementing the multi-level dialogue context adaptive management method of this invention. The electronic device is intended to represent various forms of digital computers, such as laptops, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframes, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0336] like Figure 5As shown, the electronic device 50 includes at least one processor 51 and a memory, such as a read-only memory (ROM) 52 or a random access memory (RAM) 53, communicatively connected to the at least one processor 51. The memory stores computer programs executable by the at least one processor. The processor 51 can perform various appropriate actions and processes based on the computer program stored in the ROM 52 or loaded from storage unit 58 into the RAM 53. The RAM 53 can also store various programs and data required for the operation of the electronic device 50. The processor 51, ROM 52, and RAM 53 are interconnected via a bus 54. An input / output (I / O) interface 55 is also connected to the bus 54.
[0337] Multiple components in electronic device 50 are connected to I / O interface 55, including: input unit 56, such as keyboard, mouse, etc.; output unit 57, such as various types of monitors, speakers, etc.; storage unit 58, such as disk, optical disk, etc.; and communication unit 59, such as network card, modem, wireless transceiver, etc. Communication unit 59 allows electronic device 50 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0338] Processor 51 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 51 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, digital signal processors (DSPs), and any suitable processor, controller, microcontroller, etc. Processor 51 performs the various methods and processes described above, such as multi-level dialogue context adaptive management methods.
[0339] In some embodiments, the multi-level dialogue context adaptive management method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 58. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 50 via ROM 52 and / or communication unit 59. When the computer program is loaded into RAM 53 and executed by processor 51, one or more steps of the multi-level dialogue context adaptive management method described above may be performed. Alternatively, in other embodiments, processor 51 may be configured to perform the multi-level dialogue context adaptive management method by any other suitable means (e.g., by means of firmware).
[0340] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific integrated circuits (ASICs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0341] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0342] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, compact disc read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0343] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a cathode ray tube (CRT) or liquid crystal display (LCD) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0344] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0345] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and Virtual Private Server (VPS) services, such as high management difficulty and weak business scalability.
[0346] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0347] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A multi-level dialogue context adaptive management method, characterized in that, include: Obtain the current number of lexical units in the dialogue context; wherein, the dialogue context includes tool return results, tool call parameters, and dialogue history messages; If the number of current lexical units is greater than a first preset threshold, the tool result summary compression is performed on the tool return result, and multi-strategy structure-aware compression is performed on the tool call parameters using field semantic role classification, recursive deep-aware truncation and cross-reference retention checks. After compressing the results returned by the tool and the parameters invoked by the tool, the current number of lexical units is retrieved again; If the number of current lexical units is greater than a second preset threshold, query-aware dialogue summary compression is performed on the dialogue history messages to obtain a dialogue summary, and the dialogue context message sequence is reconstructed based on the dialogue summary; The process of performing multi-strategy structure-aware compression on the tool call parameters using field semantic role classification, recursive deep-aware truncation, and cross-reference retention checks includes: The tool call parameters are parsed to generate a hierarchical key-value tree corresponding to the tool call parameters; According to the preset field naming rules, for all fields in the hierarchical key-value tree, the field semantic role classification is used to divide them into non-truncation fields and truncation fields. Perform recursive deep-aware truncation processing on the truncation field to obtain the field to be processed; Obtain the set of key identifiers in the dialogue history messages, and perform cross-reference retention checks on the fields to be processed based on the set of key identifiers to obtain the multi-strategy structure-aware compressed tool invocation parameters; According to preset field naming rules, for all fields within the hierarchical key-value tree, a field semantic role classification is used to divide them into non-truncation fields and truncation fields, including: According to the preset field naming rules, the fields in the hierarchical key-value tree are divided into identifier fields, metadata fields, and content fields; The identifier field and the metadata field are defined as the non-truncation fields, and the content field is defined as the truncation field; The recursive depth-aware truncation process performed on the truncationable field yields the field to be processed, including: Identify the nesting level of the truncated field in the hierarchical key-value tree, and match the corresponding text retention threshold according to the nesting level, wherein the deeper the nesting level, the smaller the matched text retention threshold; Traverse the nested objects and array structures of the truncation field, and perform point-to-point truncation on the excessively long text at each level based on the text retention threshold. After truncation, the original structural identifier and truncation remarks of the field are retained to obtain the field to be processed; The cross-reference retention check performed on the field to be processed based on the set of key identifiers includes: Determine whether the field to be processed contains any identifier within the set of key identifiers; If so, the associated text within the preset range before and after the corresponding identifier will be retained, while the content of the remaining fields will remain as it was after truncation.
2. The method according to claim 1, characterized in that, When the number of current lexical units exceeds a first preset threshold, the step of performing tool result summary compression on the tool's returned results includes: If the number of lexical elements is greater than a first preset threshold, the tool return results of each tool corresponding to the dialogue context are traversed. For the results returned by each of the aforementioned tools, a concise summary that retains key business semantics is generated, and the tool's returned results are replaced with the concise summary.
3. The method according to claim 1, characterized in that, Query-aware dialogue summary compression is performed on the dialogue history messages to obtain a dialogue summary, including: Separate the system messages, current user queries, and pending rating history messages from the dialogue history messages; Based on semantic similarity, temporal proximateness, and message type bonus, calculate the comprehensive relevance score corresponding to each of the aforementioned historical messages to be scored; Based on the comprehensive relevance score, the priority groups corresponding to the historical messages to be scored are divided, and a corresponding summary term budget is allocated to each priority group. Based on the priority group and the summary lexicon budget, the historical messages to be scored are compressed to obtain the dialogue summary.
4. The method according to claim 3, characterized in that, The step of calculating a comprehensive relevance score for each of the historical messages to be scored based on semantic similarity, temporal proximateness, and message type bonuses includes: The current user query and each of the historical messages to be rated are processed into text vectors to generate corresponding semantic representation vectors. Calculate the semantic similarity between the two sets of semantic representation vectors, and introduce message timing features and role type features; A weighted calculation is performed on the semantic similarity, the temporal features, and the role type features to obtain a comprehensive relevance score for each of the historical messages to be scored.
5. The method according to claim 3, characterized in that, The step of dividing the historical messages to be scored into priority groups based on the comprehensive relevance score, and allocating corresponding summary term budgets to each priority group, includes: Based on the comprehensive relevance score, the historical messages to be scored are divided into at least two priority groups; Configure a fixed percentage of the summary term budget for each of the aforementioned priority groups; Wherein, if there are no valid pending messages in any of the priority groups, the summary term budget corresponding to that priority group is allocated to the other priority groups.
6. The method according to claim 5, characterized in that, The compression of the historical messages to be scored based on the priority group and the summary lexical budget includes: Based on the priority group, the summary term budget, and the historical messages to be scored, a summary generation request is constructed; Based on the summary generation request, the system guides the generation of the dialogue summary corresponding to the historical message to be scored.
7. The method according to claim 1, characterized in that, After reconstructing the dialogue context message sequence based on the dialogue summary, the method further includes: Retrieve the set of incomplete tasks stored in the agent's task management module; The incomplete task set is grouped and filtered, and the completed task group is removed. The tasks are sorted based on semantic relevance and the dependency constraints between tasks are marked. After sorting and labeling, the task status information is encapsulated into standard dialogue messages and injected into the reconstructed dialogue context message sequence.
8. The method according to claim 1, characterized in that, Also includes: Configure monitoring parameters, including inference step threshold, maximum number of reminders, step counter, and frequency attenuation coefficient; The step counter accumulates the number of inference steps that the agent has not called the task management tool for a continuous period of time. When the number of inference steps reaches the inference step threshold and does not exceed the maximum number of reminders, task reminder information is injected into the dialogue context. After each injection of the task reminder information is completed, the inference step threshold is adjusted according to the frequency attenuation coefficient. Specifically, when the agent invokes the task management tool, the step counter and the inference step threshold are reset.
9. A multi-level dialogue context adaptive management device, characterized in that, include: The lexical count acquisition module is used to acquire the current lexical count in the dialogue context; wherein, the dialogue context includes tool return results, tool call parameters, and dialogue history messages; The tool-side compression module is used to perform tool result summary compression on the tool return results when the number of current lexical units is greater than a first preset threshold, and to perform multi-strategy structure-aware compression on the tool call parameters by using field semantic role classification, recursive deep-aware truncation and cross-reference retention checks. The lexical count update module is used to re-obtain the current lexical count after performing compression processing on the results returned by the tool and the parameters called by the tool; The historical message compression and reconstruction module is used to perform query-aware dialogue summary compression on the dialogue history messages when the number of current lexical units is greater than a second preset threshold, to obtain a dialogue summary, and to reconstruct the dialogue context message sequence based on the dialogue summary; The tool-side compression module also includes a multi-strategy structure-aware compression submodule, which includes a field classification unit, a recursive truncation unit, and a cross-reference checking unit. The field classification unit is used to parse the tool call parameters and generate a hierarchical key-value tree corresponding to the tool call parameters; according to the preset field naming rules, for all fields in the hierarchical key-value tree, the field semantic role classification is used to divide them into non-truncation fields and truncation fields; The recursive truncation unit is used to perform recursive depth-aware truncation processing on the truncationable field to obtain the field to be processed. The cross-reference checking unit is used to obtain a set of key identifiers in the dialogue history messages, and perform cross-reference retention checks on the fields to be processed based on the set of key identifiers to obtain the multi-strategy structure-aware compressed tool call parameters. The field classification unit is specifically used for: According to the preset field naming rules, the fields in the hierarchical key-value tree are divided into identifier fields, metadata fields, and content fields; The identifier field and the metadata field are defined as the non-truncation fields, and the content field is defined as the truncation field; The recursive truncation unit is specifically used for: Identify the nesting level of the truncated field in the hierarchical key-value tree, and match the corresponding text retention threshold according to the nesting level, wherein the deeper the nesting level, the smaller the matched text retention threshold; Traverse the nested objects and array structures of the truncation field, and perform point-to-point truncation on the excessively long text at each level based on the text retention threshold. After truncation, the original structural identifier and truncation remarks of the field are retained to obtain the field to be processed; The cross-reference checking unit is specifically used for: Determine whether the field to be processed contains any identifier within the set of key identifiers; If so, the associated text within the preset range before and after the corresponding identifier will be retained, while the content of the remaining fields will remain as it was after truncation.
10. An electronic device, characterized in that, The electronic device includes: At least one processor; and a memory communicatively connected to the at least one processor; The memory stores a computer program that can be executed by the at least one processor, which is then executed by the at least one processor to enable the at least one processor to perform the multi-level dialogue context adaptive management method according to any one of claims 1-8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the multi-level dialogue context adaptive management method according to any one of claims 1-8.
Citation Information
Patent Citations
Context compression method and device based on query guidance
CN119669398A
Question and answer reasoning method and device based on key value cache compression, equipment and medium
CN120598057A