Context extraction method, long-term task-oriented interaction method, device and equipment
By generating a representation of the current query and determining weights based on similarity, the context of long-term tasks is dynamically compressed, solving the problem of context management in long-term tasks and improving the accuracy and stability of inference.
Patent Information
- Application Number
- CN202610993974.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-03
- Publication Date
- 2026-11-27
AI Technical Summary
Existing technologies cannot effectively manage context in long-term tasks, leading to historical information exceeding the model's capacity or the loss of key information, thus affecting the accuracy of inference.
By generating a representation of the current query, encoding it into an embedding vector, and determining weights based on similarity to the interaction fragments, historical fragments of appropriate granularity are selected from multi-granular representations, the context is dynamically compressed, and key information is preserved.
Within a limited context window, the inference accuracy and stability of long-term tasks are improved, irrelevant and redundant content is reduced, and the integrity of key information is ensured.
Smart Images

Figure CN123180318A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence, and in particular to a context extraction method, an interaction method for long-term tasks, an apparatus, and a device. Background Technology
[0002] As the capabilities of large language models continue to improve, intelligent agents have evolved from simple question-and-answer systems into automated execution systems capable of autonomously handling complex tasks. In scenarios such as in-depth web research, batch data analysis, and complex enterprise office work, tasks cannot be completed through a single interaction. They require dozens, hundreds, or even thousands of consecutive interactions to advance step by step, forming typical long-term tasks. In such tasks, the effectiveness of the intelligent agent's management of historical context directly affects the overall reasoning accuracy and completion quality of the task.
[0003] In existing technologies, intelligent agents designed for long-range tasks typically employ methods such as fully preserving interaction history and fixed window truncation for context management. The method of fully preserving interaction history quickly exceeds the capacity of large language models as the number of interaction rounds increases, making it unsuitable for long-range task execution. The method of fixed window truncation, on the other hand, leads to the loss of early interaction records, potentially resulting in missing reasoning evidence and affecting the accuracy of long-range inference.
[0004] Therefore, how to balance historical information preservation, compression efficiency, and inference quality within a limited context window has become a pressing technical problem that needs to be solved. Summary of the Invention
[0005] This application provides a context extraction method, an interaction method, apparatus, and device for long-term tasks to solve the aforementioned technical problems. By using multi-granularity representations of historical fragments and selecting representations of corresponding granularities of historical fragments to form context based on the similarity between historical fragments and the current query, dynamic compression of historical fragments is achieved. This enables the accurate retention of key information strongly related to the current task within a limited word window, balancing context compression efficiency with the integrity of historical source information, and significantly improving the accuracy of agent reasoning in long-term tasks.
[0006] In a first aspect, embodiments of this application provide a context extraction method, including:
[0007] Based on the user's original task and multiple recent interaction segments, a current query representation is generated; these recent interaction segments are interaction segments from multiple time steps prior to the current time step; the current query representation is encoded to obtain the current query embedding vector; for each interaction segment, the weight of the interaction segment is determined based on the similarity between the current query embedding vector and the key embedding vector of the interaction segment; based on the weight of the interaction segment, the selected representation of the interaction segment is determined from the multi-granularity representation of the interaction segment; based on the selected representation of each interaction segment, the context of the current time step of the user's original task is generated and output.
[0008] In one possible embodiment, determining the selected representation of an interaction segment from its multi-granularity representation based on the segment's weight includes:
[0009] Obtain the compression pressure value at the current time step; determine multiple weight thresholds based on the compression pressure value; determine the selected representation of the interaction segment from the multi-granularity representation of the interaction segment based on the comparison result of the weight of the interaction segment and the multiple weight thresholds.
[0010] In one possible embodiment, obtaining the compression pressure value at the current time step includes:
[0011] The compression pressure value at the current time step is calculated based on the total number of context lexical units and the current time step; the total number of context lexical units is the cumulative value of the number of context lexical units generated in the historical time steps.
[0012] In one possible embodiment, the compression pressure value of the current time step is the larger of the ratio of the current time step to the preset time sequence length and the ratio of the total number of context lexical units to the preset lexical budget.
[0013] In one possible embodiment, the method further includes:
[0014] After the interactive agent performs reasoning based on the context of the current time step and obtains the reasoning result, a multi-granular representation of the interaction segment of the current time step is generated based on the reasoning result, and a key embedding vector of the current time step is generated.
[0015] In one possible embodiment, the method further includes:
[0016] In response to the review request from the interactive agent, the target review segment is determined; the original complete representation of the target review segment in the multi-granularity representation is pushed to the interactive agent; based on the original complete representation of the target review segment, the number of lexical units in the context at the current time step is updated; based on the updated number of lexical units in the context at the current time step, the total number of lexical units in the context is updated.
[0017] In one possible embodiment, the multi-granularity representation of the interaction fragment includes the original complete representation of the interaction fragment, summaries at multiple levels of detail, and placeholders; multiple weight thresholds include a first threshold and multiple second thresholds; based on the comparison results of the interaction fragment's weights with the multiple weight thresholds, a selected representation of the interaction fragment is determined from the multi-granularity representation of the interaction fragment, including:
[0018] If the weight of the interactive segment is greater than the first threshold, the selected representation of the interactive segment is determined to be the original complete representation; if the weight of the interactive segment is less than or equal to the first threshold and greater than the minimum of multiple second thresholds, the selected representation of the interactive segment is determined from multiple summaries of detail based on the comparison result of the weight of the interactive segment and multiple second thresholds; if the weight of the interactive segment is less than or equal to the minimum of multiple second thresholds, the selected representation of the interactive segment is determined to be a placeholder.
[0019] In one possible embodiment, the weight of the interaction segment is determined based on the similarity between the current query embedding vector and the key embedding vector of the interaction segment, including:
[0020] Based on the cosine similarity between the current query embedding vector and the key embedding vector of the interaction segment, the relevance score of the interaction segment is obtained; the relevance score of the interaction segment is normalized to obtain the weight of the interaction segment.
[0021] Secondly, embodiments of this application provide an interaction method for long-term tasks, including: receiving a user's original task input by the user; obtaining the context of each time step based on the method provided above; performing inference based on the context of the time step to obtain and output the inference result of the current time step.
[0022] Thirdly, embodiments of this application provide a context extraction apparatus, comprising: a query generation module, configured to generate a current query representation based on a user's original task and multiple recent interaction segments; the multiple recent interaction segments being interaction segments with multiple time steps prior to the current time step; and encoding the current query representation to obtain a current query embedding vector; a weight calculation module, configured to determine the weight of each interaction segment based on the similarity between the current query embedding vector and the key embedding vector of the interaction segment; a dynamic compression module, configured to determine the selected representation of the interaction segment from the multi-granularity representation of the interaction segment based on the weight of the interaction segment; and a context generation module, configured to generate and output the context of the current time step of the user's original task based on the selected representation of each interaction segment.
[0023] Fourthly, embodiments of this application provide an electronic device, including: a memory and a processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, causing the processor to perform the method provided above.
[0024] Fifthly, embodiments of this application provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the methods provided above.
[0025] Sixthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the method provided above.
[0026] The context extraction method, interaction method, apparatus, and device provided in this application generate a current query representation based on the user's original task and multiple recent interaction segments. This current query representation is then encoded to obtain a current query embedding vector. The weights of the interaction segments are dynamically determined by combining the similarity between the current query embedding vector and the key embedding vectors of each interaction segment. Based on these weights, a representation of suitable granularity is adaptively selected from the multi-granularity representations of each interaction segment to construct the context for the current time step. This achieves dynamic compression of historical interaction segments based on the semantic requirements of the current task, reducing irrelevant and redundant content from entering the context. Simultaneously, it avoids the loss of key traceability information, balancing the preservation of historical key information and compression efficiency within a limited context window. This significantly improves the reasoning accuracy of the agent in long-term tasks. Furthermore, it continuously provides the agent with concise and effective context matching the current reasoning needs, reducing errors in judgment, rework of steps, and even task interruptions during the task. This ensures the smooth progress of multi-round reasoning in long-term tasks and significantly improves the stability of task execution. Attached Figure Description
[0027] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0028] Figure 1 Flowchart of the context extraction method provided in this application Figure 1 ;
[0029] Figure 2 A schematic diagram of a context extraction framework provided in this application;
[0030] Figure 3 A schematic diagram of the context extraction device provided in this application;
[0031] Figure 4 A schematic diagram of the structure of the electronic device provided in this application.
[0032] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0033] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0034] It should be noted that, in the case of user information involved in the embodiments of this application, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with relevant laws, regulations and standards, and provide corresponding operation entry points for users to choose to authorize or refuse.
[0035] This application relates to the field of large language model intelligent agent technology, applicable to various long-term tasks such as multi-turn dialogue, cross-web page information retrieval, task planning, and automated office work. When performing long-term tasks, the intelligent agent needs to complete multiple rounds of reasoning based on the user's original task input, generate execution actions, and obtain feedback from tools and the environment, autonomously advancing the task until completion.
[0036] Context management for long-duration task inference mainly includes methods such as complete history preservation, fixed window truncation, progressive summarization, and folded memory. Complete history preservation minimizes information loss but leads to a near-linear increase in context length, quickly exhausting the model's context window in long tasks. Fixed window truncation, while simple and efficient, easily discards crucial evidence that might still be cited later. Progressive summarization (also known as progressive summarization) achieves historical information compression, but its uniform compression rules and lack of consideration for the specific needs of the current task result in premature compression or even loss of key information. Folded memory methods introduce more complex memory compression mechanisms, but typically rely on the model actively generating folding instructions or learning additional memory management strategies. This couples the task solving process with the memory management process, affecting generality and stability.
[0037] Therefore, when performing long-range tasks, intelligent agents face a core technical dilemma: they need to retain sufficient historical interaction content to support coherent reasoning across multiple steps, but are limited by the model's context window capacity, making it impossible to store complete original historical information indefinitely. To address this dilemma, this application proposes an adaptive context extraction scheme that dynamically performs differentiated compression of historical information based on the relevance between historical information and the semantic requirements of the current query, thereby constructing a compact and more information-dense context.
[0038] Specifically, this application provides a context extraction method that, at the current time step, generates a current query representation based on the user's original task and multiple recent interaction segments, and encodes the current query representation to obtain a current query embedding vector; then, based on the similarity between the current query embedding vector and the key embedding vectors of each interaction segment, quantifies the relevance of each interaction segment to the semantic requirements of the current query, and obtains the weight of each interaction segment; subsequently, based on the weight, adaptively matches the corresponding granularity representation from the multi-granularity representation of each interaction segment as the selection representation; finally, based on the selection representation of each interaction segment, it generates the context of the current time step, realizing the current query embedding vector extraction method. The system differentiates and compresses historical interaction information based on the semantic requirements of the current task, retaining only the effective content that is highly relevant to the current reasoning. This significantly reduces the space occupied by irrelevant and redundant text, alleviating the problem of exceeding the context window limit in long-term tasks. At the same time, high-weight key interaction fragments can retain more complete details, avoiding premature over-compression or direct discarding of information such as key tool records, web page evidence, and file data. This provides complete traceability for multi-step continuous reasoning, reduces reasoning bias caused by missing information, and balances the integrity of historical information retention with the efficiency of context compression within a limited context window, thereby improving the accuracy and execution stability of reasoning throughout ultra-long tasks.
[0039] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0040] Figure 1 Flowchart of the context extraction method provided in this application Figure 1 ,like Figure 1 As shown, the context extraction method includes:
[0041] S101: Generate the current query representation based on the user's original task and multiple recent interaction segments.
[0042] Among them, the multiple recent interaction segments are the interaction segments with multiple time steps before the current time step. The time steps corresponding to each interaction segment in the multiple recent interaction segments can be continuous or have intervals, that is, they are arranged in a non-continuous manner.
[0043] For example, interaction segments from multiple time steps prior to the current time step can be directly identified as multiple recent interaction segments. Alternatively, these interaction segments can be filtered to obtain multiple recent interaction segments. Multiple recent interaction segments can be obtained by filtering from interaction segments from multiple time steps prior to the current time step based on multi-granularity representations of the interaction segments. During filtering, invalid or duplicate interaction segments are primarily removed. Invalid interaction segments can include those with insufficient content length or lacking valid semantics.
[0044] Interaction chunks are the content generated by an agent after completing a round of inference in a single time step. They can include actions performed by the agent, such as calling tools, environmental observations, tool return results, and intermediate results.
[0045] An intelligent agent is an automated system capable of performing multi-step reasoning, tool invocation, environmental interaction, and result generation based on a user's original task. The user's original task is the text of their needs input during the interaction, such as a question entered by the user.
[0046] For example, the user's original task could be the request text input by the user who triggered the long-horizon task. A long-horizon task refers to a task that requires multiple steps of reasoning to complete, such as multi-page retrieval, in-depth research, multi-stage information synthesis, and continuous execution across tasks.
[0047] The user-input text can be natural language instructions, problem statements, descriptions of tasks to be completed, or a set of constraints.
[0048] For example, the execution entity of this method can be a context management module deployed in a server, terminal device, or edge node. This module reads the user's original task from the session storage area, reads multiple interaction fragments adjacent to the current time step from the historical interaction cache in chronological order, and constructs the current query representation based on the user's original task and the multiple interaction fragments.
[0049] In practical implementation, the user's original task can be normalized first, removing redundant whitespace, invalid control characters, and non-task-related system markers, while retaining semantic components such as task objectives, objects, constraints, and output requirements. Then, multiple recent interaction segments are fragmented, associating each segment with its corresponding time step and retaining the role identifier, action category, and result content within the segment. To ensure the current query representation simultaneously reflects the current task intent and adjacent historical information, the user's original task can be placed at the beginning of the query according to a preset template, and recent interaction segments can be concatenated at the end of the query in chronological order (from most recent to oldest or from oldest to most recent). Each interaction segment is preceded by a segment separator and a time step marker to facilitate segment boundary identification in subsequent encoding stages.
[0050] Each interaction fragment is represented using a multi-granularity representation, which includes representations of high-level interaction fragments with varying degrees of detail. The highest level of detail can be the original, complete content (Full Text) of the interaction fragment, which is the original, complete representation. When generating the current query representation, it can be based on the user's original task and the original, complete representations of the interaction fragments from the most recent steps.
[0051] The current query representation can be:
[0052]
[0053] in, This indicates a concat operation; Indicates the first The original complete representation of the interactive segments of the time step; For the current time step The current query representation; This is the user's original task.
[0054] By integrating the user's original task with multiple recent interaction segments, a current query representation for the next step of reasoning and prediction is constructed. This makes the query representation no longer solely dependent on the initial requirement text provided by the user, but incorporates the interaction chain formed by recent continuous interactions. This allows for a more complete and three-dimensional expression of the user's reasoning needs at the current time step, providing a reliable semantic basis for subsequent adaptive compression of historical segments based on similarity.
[0055] S102: Encode the current query representation to obtain the current query embedding vector.
[0056] The current query embedding vector in this step is used to transform the current query representation into a vector form with computable similarity, so that it can be compared with the key embedding vectors of each interaction segment. Encoding refers to mapping the current query representation, which contains the user's original task and recent interaction segments, into a semantic vector output with fixed or preset dimensions, transforming it into a dense semantic vector that can be directly numerically calculated by a computer.
[0057] In one possible embodiment, the current query representation can be encoded based on the query encoder, sentence vector model, Transformer encoder, or embedding network trained from the same source as the subsequent key vector generation process in the dual-tower retrieval model to obtain the current query embedding vector.
[0058] In practice, the current query representation is first input into the word segmentation unit to obtain the word sequence, and then the hidden state is output through the positional encoding and semantic encoding network. Finally, the current query embedding vector is generated through pooling operation.
[0059] To ensure consistency in subsequent similarity calculations, the current query embedding vector and the key embedding vector of the interaction fragment are expressed in the same vector space with consistent dimensions, such as 256, 512, or 768 dimensions.
[0060] After encoding, normalization can be performed on the current query embedding vector to constrain the vector magnitude to a uniform range, so as to reduce the impact of scale differences when using dot product or other similarity methods for subsequent calculation.
[0061] If the current query representation contains multiple logical segments, such as the user's original task target segment, recent observation segment, and intermediate conclusion segment, then a unique segment type label can be added to each segment before encoding to help the encoding model or encoder distinguish the semantic role of each segment; the hierarchical hidden state corresponding to each segment can be preserved during the encoding process.
[0062] The current query embedding vector essentially provides a semantic index of the query at the current time step, enabling the subsequent weight determination stage to compare the fit between the current task requirements and historical fragment content within a unified numerical vector space. This step transforms the current query representation in the form of composite text into a dense vector suitable for similarity comparison. On the one hand, this transforms the subsequent matching process from direct comparison of long texts to vector computation, reducing computational overhead. On the other hand, it ensures that the current task semantics, recent state, and inference clues are represented uniformly in the relevance judgment process, improving the accuracy of interaction fragment weight allocation.
[0063] S103: For each interaction segment, determine the weight of the interaction segment based on the similarity between the current query embedding vector and the key embedding vector of the interaction segment.
[0064] In this context, the key embedding vector serves as the retrieval key for each interaction segment, and its similarity to the current query embedding vector is calculated to determine the relevance between the interaction segment and the current query. Weights represent the contribution of each interaction segment to the construction of the current time step context and serve as the basis for subsequent selection of multi-granularity representations.
[0065] The key embedding vector for each interaction segment can be generated when the interaction segment is obtained, for example, by encoding the original complete representation of the interaction segment to obtain the key embedding vector and caching it. Alternatively, at the current time step, the original complete representation of the interaction segment from the previous time step can be encoded to obtain its key embedding vector.
[0066] In practice, each interactive segment is first processed by a uniform format, merging the action, observation, tool return and intermediate results into segment text to obtain the original full text. Then, the original full text is input into the segment encoder to obtain the key embedding vector.
[0067] If the query encoder (used to encode the current query representation) and the fragment encoder adopt a dual encoder architecture, they are aligned through the same training objective, so that the current query embedding vector and the key embedding vector can be compared in the same semantic space.
[0068] The weight of an interaction segment can be determined based on the cosine similarity, inner product similarity, and Euclidean distance between the current query embedding and the key embedding of the interaction segment.
[0069] The relevance score of an interaction segment can be determined based on the cosine similarity between the current query embedding vector and the key embedding vector of the interaction segment. This relevance score is then normalized using a low-temperature softmax function to obtain the weight of the interaction segment. The purpose of the low-temperature softmax function is to enhance the distinction between highly relevant and low-relevance interaction segments, giving higher weights to interaction segments that are truly likely to influence the next action, while assigning lower weights to a large number of irrelevant interaction segments.
[0070] S104: Determine the selected representation of the interaction segment from the multi-granularity representation of the interaction segment based on the weight of the interaction segment.
[0071] Multi-granularity representation is used to provide representations with different levels of compression for the same interaction segment, so as to select the appropriate information retention level according to the weight. The selected representation is the representation that is finally selected from the multi-granularity representation and actually enters the current time step context.
[0072] For example, a multi-granularity representation includes at least the most detailed original full text, i.e., the original full representation, and a summary of that original full text. The original full text is used to preserve the original action and observation details, that is, to preserve the complete information of the actions and environmental observations output by the interactive agent during inference at the corresponding time step.
[0073] For example, a multi-granularity representation may also include placeholders that simply indicate the existence of the interaction fragment and may also indicate the type of the interaction fragment.
[0074] Based on the weight of an interaction segment, a representation suitable for that weight can be selected from the multi-granularity representations corresponding to that interaction segment. Alternatively, based on the weight's range, the representation corresponding to that range's granularity can be selected as the chosen representation. For example, when the weight is high, the chosen representation is the original, complete content; when the weight is low, the chosen representation is a summary; and when the weight is even lower, the chosen representation is a placeholder. By ensuring that high-weight interaction segments retain more information and low-weight interaction segments retain less information, a non-uniform information distribution among segments can be achieved under limited context conditions.
[0075] By transforming the weighted results into a practically usable text preservation strategy, historical information is not directly preserved, truncated, or summarized as a whole, but is preserved in layers based on the relevance driven by the current query. This allows us to maintain the key evidence upon which subsequent inference depends while controlling the length of the input.
[0076] S105: Based on the selection representation of each interaction segment, generate and output the context of the current time step of the user's original task.
[0077] After determining the selection representation of each interaction segment based on its weight, the context of the current time step is obtained based on the selection representation of each interaction segment. The context of the current time step is then output to the interactive agent, which performs inference for the current time step based on the context of the current time step to obtain the inference result.
[0078] One or more of the following can be combined with the prompt, the user's original task, the original complete representations of multiple recent interaction segments, and the current environmental observation information, along with the selected representations of each interaction segment, to form the context of the current time step. This context is then output to the interactive agent for reasoning. The interactive agent deduces its thinking logic based on this context, obtains the next action, and then generates a multi-granular representation of the interaction segment of the current time step based on the action, environmental observation information, the return result of the action, intermediate results, etc.
[0079] The selected representations can be arranged according to the original chronological order of the interaction fragments to maintain the traceability of the event chain; alternatively, high-weight fragments can be placed earlier while satisfying the chronological order constraints. When generating context, a uniform separator can be inserted between the selected representations of adjacent interaction fragments, and a source label, such as user, agent, tool, or environment, can be added before each interaction fragment to help the model identify the role relationships between the content.
[0080] In addition to including the selection indication, the context of the user's original task at the current time step can also include the user's original task at the beginning, as well as current environmental observation information, prompts, etc., in other locations, thus forming a complete context sequence that can be directly input into a large language model.
[0081] This context construction method based on selection representation ensures that the input obtained at the current time step is no longer a mechanical patchwork of the entire history, nor a fixed retention of the most recent rounds. Instead, it extracts a set of historical information with differentiated retention levels based on the current original task and recent state. This step unifies the aforementioned query construction, vector encoding, relevance calculation, and multi-granularity selection results into the currently executable context input. This allows subsequent reasoning processes to read historical evidence that better fits the current needs within a limited window and reduces the input capacity occupied by redundant fragments that are not directly related to the current task.
[0082] The context extraction method provided in this application uses the task semantics of the current time step as the retrieval driver to perform vectorized relevance measurement on interaction fragments from multiple consecutive historical time steps. This relevance result is then mapped to a multi-granularity representation selection strategy, allowing different historical fragments to retain different levels of information upon entering the context. This preserves content more relevant to the current inference and compresses redundant history within a limited context window. Compared to complete retention, fixed window truncation, or uniform summary compression, the context generated by this application exhibits higher consistency with the subsequent inference needs of the current time step. In long-term interaction scenarios, it can stably control the input length and maintain the availability of key historical evidence.
[0083] In one possible implementation, the weight of an interaction segment is determined based on the similarity between the current query embedding vector and the key embedding vector of the interaction segment, including: obtaining a relevance score of the interaction segment based on the cosine similarity between the current query embedding vector and the key embedding vector of the interaction segment; and normalizing the relevance score of the interaction segment to obtain the weight of the interaction segment.
[0084] After obtaining the current query embedding vector, the key embedding vector of each interaction segment is read, and the cosine similarity is calculated based on the ratio of the vector dot product to the product of the vector magnitudes, resulting in the corresponding relevance score. Subsequently, the relevance scores of multiple interaction segments within the same time step can be summed and normalized to make the sum of the weights of each interaction segment equal to one; alternatively, linear normalization can be used to map the relevance scores to a preset interval, and then weight values can be formed accordingly.
[0085] When normalizing the relevance scores, a low-temperature softmax function can be used to enhance the distinction between highly relevant and low-relevance historical segments, giving higher weight to historical information that may actually influence the next action, while compressing a large number of irrelevant historical segments to lower weight.
[0086] After normalizing the relevance scores of the interaction segments, the normalized weights can be further converted into relative weights to determine the importance of each interaction segment relative to the average level (i.e., the average of the normalized weights of all interaction segments). The relative weights can be represented by the ratio of the normalized weights to the average value.
[0087] Cosine similarity is used to calculate relevance scores, taking only the semantic angle and not being affected by the length of the fragment text, resulting in a fairer relevance assessment. Normalizing the scores yields standardized weights within a uniform range, eliminating fluctuations in the original score range and facilitating horizontal comparisons of fragment importance, thus providing a reliable basis for subsequent dynamic compression.
[0088] Based on the foregoing embodiments, further, determining the selected representation of an interaction segment from the multi-granularity representation of the interaction segment based on the weight of the interaction segment includes: obtaining the compression pressure value of the current time step; determining multiple weight thresholds based on the compression pressure value; and determining the selected representation of the interaction segment from the multi-granularity representation of the interaction segment based on the comparison result between the weight of the interaction segment and the multiple weight thresholds.
[0089] The compression pressure value at the current time step is used to characterize the task execution progress and / or the usage of the context budget. When the user's original task is in the early stage, the usage of the context budget is also low, and the compression pressure value is small. When the user's original task is in the later stage, the task sequence becomes longer, and the context budget gradually approaches its upper limit, at which point the compression pressure value is high.
[0090] The lower the compression pressure value, the lower the corresponding weight threshold, which allows more historical interaction fragments to retain relatively detailed information; conversely, the higher the compression pressure value, the higher the corresponding weight threshold, which further compresses the representation of historical interaction fragments in the context, such as using placeholders to represent the selection of more interaction fragments, thereby reducing the number of tokens in the context.
[0091] The relationship between the compressive pressure value and the weighted threshold can be linear or non-linear. For example, the relationship between the compressive pressure value and the weighted threshold can be: .in, For the current time step The weight threshold, For the current time step The compression pressure value, This is the initial or baseline value for the weight threshold. This is the adjustment coefficient, a configurable parameter used to control the adaptive adjustment rate. The default value can be 0.5.
[0092] After obtaining multiple weight thresholds for the current time step, the corresponding granularity representation is matched from the multi-granularity representation of each interaction segment (or historical segment or historical interaction segment) by comparing the weight of each interaction segment with the multiple weight thresholds, and used as the selected representation of each interaction segment.
[0093] For example, taking a multi-granularity representation including an original complete representation, a detailed summary, and a concise summary with progressively decreasing levels of detail, and multiple weight thresholds including a first threshold and a second threshold, the following approach is used: If the weight of an interactive segment is greater than or equal to the first threshold, it is determined that its selected representation is the original complete representation; if the weight of an interactive segment is less than the first threshold but greater than or equal to the second threshold, it is determined that its selected representation is the detailed summary; if the weight of an interactive segment is less than the second threshold, it is determined that its selected representation is the concise summary.
[0094] By dynamically adjusting the weight threshold based on the compression pressure value at the current time step, the compression intensity of interactive segments changes dynamically with the progress of the task. When the pressure is low, complete interactive clues are fully preserved to ensure that complex reasoning has sufficient basis. When the pressure is high, irrelevant segments are simplified and redundant words are reduced to avoid the problem of excessively long sequences and improve adaptability to long-term tasks.
[0095] Based on the aforementioned embodiments, further, obtaining the compression pressure value of the current time step includes: calculating the compression pressure value of the current time step based on the total number of context words and the current time step; the total number of context words is the cumulative value of the number of context words generated in historical time steps.
[0096] At each time step, after obtaining the context of that time step, the total number of context lexical units is updated based on the number of lexical units in the context of that time step.
[0097] The compression pressure value, once generated, characterizes the intensity of compression demand at the current time step and serves as the basis for subsequently determining multiple weight thresholds. The closer the total number of words or context terms at the current time step is to the set upper limit, the higher the compression pressure value.
[0098] In the specific implementation, the context lexicon budget and the time length benchmark can be preset, and the total amount of accumulated context lexicons can be calculated to correspond with the lexicon budget. The current time step can be calculated to correspond with the time length benchmark, and the results of the two calculations can be used to determine the compression pressure value.
[0099] By adopting this method, the compression pressure value can dynamically change with the accumulation of historical context and the progress of task sequence, thereby making the subsequent retention and compression judgment of interaction fragments more in line with the current stage of the task. This enables context capacity control and reasoning clue retention to adapt synchronously with the progress of the task, avoiding the continuous expansion of context words or excessive deletion of key historical information in long-term interaction.
[0100] In one possible implementation, the compression pressure value of the current time step is the larger of the ratio of the current time step to the preset time sequence length and the ratio of the total number of context lexical units to the preset lexical budget.
[0101] The preset time sequence length is the preset maximum number of inference steps for the task. The preset lexical budget is used to represent the upper limit of lexical capacity, for example, 128K.
[0102] For example, the preset time series length can be the 95th percentile of the task length of each sample in the test set.
[0103] In the specific implementation, at each time step, the current time step number is counted and the preset time length is read. At the same time, the word count of the context generated in the historical time steps is performed to obtain the total number of context words. Then, the ratio of the current time step to the preset time length and the ratio of the total number of context words to the preset word budget are calculated respectively. The larger of the two values is then taken as the compression pressure value of the current time step.
[0104] Compression pressure value at the current time step The expression is:
[0105]
[0106] in, The preset time series length is the maximum number of inference steps expected by the user's original task. The preset lexical budget represents the upper limit of the lexical capacity, for example, 128K; This represents the total number of contextual terms. At the first time step, i.e., during the first round of reasoning. It can be the sum of the number of lexical terms in the prompt message and the user's original task.
[0107] By using the above method to calculate the compression pressure value, the compression intensity is automatically increased when the number of interaction rounds approaches the task limit or the total number of words approaches the capacity budget, effectively avoiding two types of problems: excessively long time sequence and context overflow.
[0108] In one possible implementation, the method further includes:
[0109] After the interactive agent performs reasoning based on the context of the current time step and obtains the reasoning result, a multi-granular representation of the interaction segment of the current time step is generated based on the reasoning result, and a key embedding vector of the current time step is generated.
[0110] After encoding and reasoning about the context of the current time step, the interactive agent obtains the reasoning result corresponding to the current task objective, the content returned by the tool, or the environmental observation information. The reasoning result is then output to the representation generator, which generates a multi-granular representation of the interaction segment of the current time step based on the reasoning result. In the next time step, the multi-granular representation of the interaction segment of the current time step is dynamically compressed, that is, its selected representation is determined based on the weight. This process continues until the user's original task is completed.
[0111] The reasoning result can include various outputs from the interactive agent during reasoning, such as current environmental observations, executed actions, tool call results, and intermediate results. Multi-granularity representations can consist of the original complete representation, a summary representation, and placeholders for the same interaction segment. The original complete representation retains the complete semantic information corresponding to the reasoning result, preserving the original actions and observation details. The summary representation is a summary of the original complete representation, and can include multiple summaries with varying levels of detail. The summary representation can be obtained by extracting key information and semantically simplifying the original complete representation.
[0112] Multi-granularity representations can be stored in the form of text, vectors, or a combination of both, and associated with the current time step so that they can be selected later based on compression pressure and weight thresholds.
[0113] After obtaining the original complete representation of the interaction fragment at the current time step, the original complete representation can be encoded to obtain the key embedding vector of the interaction fragment at the current time step. The key embedding vector and the multi-granularity representation of the interaction fragment are stored in key-value memory in a one-to-one correspondence, so as to serve as the retrieval key for calculating the similarity with the current query embedding vector.
[0114] For example, the first Interactive segments of time steps It can be represented as:
[0115]
[0116] in, and These represent two types of abstract representations: detailed abstract and concise abstract. For original and complete representation; This is a placeholder; This is the key embedding vector.
[0117] During the execution of the user's original task by the interactive agent, each interaction step is recorded as an interaction fragment. Each interaction fragment typically includes the action taken by the interactive agent at that step (i.e., the action executed), the tool invoked, the result returned by the tool, environmental observation information, and necessary intermediate results. In this step, a multi-granularity representation is maintained for each interaction fragment, allowing for the dynamic selection of different granularity representations based on the importance of the interaction fragment, thus achieving different levels of compression for the interaction fragment. By pre-compiling the key embedding vector of the interaction fragment, this vector can be directly reused in subsequent weight calculation steps, shortening the dynamic compression time and improving the efficiency of context extraction.
[0118] In one possible implementation, the multi-granularity representation of the interaction fragment includes the original complete representation of the interaction fragment, summaries at multiple levels of detail, and placeholders; multiple weight thresholds include a first threshold and multiple second thresholds; based on the comparison result of the interaction fragment's weight with the multiple weight thresholds, the selected representation of the interaction fragment is determined from the multi-granularity representation of the interaction fragment, including: if the weight of the interaction fragment is greater than the first threshold, then the selected representation of the interaction fragment is determined to be the original complete representation; if the weight of the interaction fragment is less than or equal to the first threshold and greater than the minimum value among the multiple second thresholds, then based on the comparison result of the interaction fragment's weight with the multiple second thresholds, the selected representation of the interaction fragment is determined from the summaries at multiple levels of detail; if the weight of the interaction fragment is less than or equal to the minimum value among the multiple second thresholds, then the selected representation of the interaction fragment is determined to be a placeholder.
[0119] Taking multiple levels of detail, including detailed and concise summaries, and multiple second thresholds as an example, the first... Interactive segments of time steps Selected means It can be represented as:
[0120]
[0121] in, for The weights; The first threshold for the current time step; and These are the two second thresholds for the current time step. for Detailed summary for A concise summary. A detailed summary is used to retain the main facts, evidence, and conclusions; a brief summary is used to retain one or two sentences of core information.
[0122] Through the aforementioned selection mechanism, highly relevant segments are preserved as complete content, moderately relevant segments are compressed into summaries of varying fineness, and lowly relevant segments are reduced to placeholders. This ensures that the context input maintains a content density more consistent with the current query within a limited token budget. Weights are used to hierarchically map the importance of historical segments, switching between complete preservation, summary preservation, and existence preservation accordingly to support priority access to key information during subsequent reasoning. This allows for the preservation of necessary evidence chains while compressing context length, reducing redundant input, and ensuring that interactive segments of varying relevance receive representations commensurate with their importance.
[0123] To mitigate the risk of information loss due to downgraded compression, an on-demand review mechanism can be further introduced. When the interactive agent discovers insufficient information in a certain interaction segment during contextual reasoning at the current time step, or needs to verify the tool call results, webpage evidence, or file content of that interaction segment, it can request a review to view the original, complete content of the compressed interaction segment. The reviewed content of the interaction segment, i.e., the original, complete content, will be included in the total contextual vocabulary. This improves efficiency based on the aforementioned dynamic compression mechanism while further enhancing the ability to recover key details and improving the quality of reasoning results through the on-demand review mechanism.
[0124] When an agent performs reasoning and deduction tasks, if a breakpoint occurs, such as a causal gap, missing parameters, or a conclusion without supporting evidence, the agent locates the corresponding interaction segment. If the selected interaction segment in the context is not the original complete representation of the interaction segment, the agent initiates a review request for that interaction segment to view its original complete representation.
[0125] Based on the foregoing embodiments, the method further includes:
[0126] In response to the review request from the interactive agent, the target review segment is determined; the original complete representation of the target review segment in the multi-granularity representation is pushed to the interactive agent; based on the original complete representation of the target review segment, the number of lexical units in the context at the current time step is updated; based on the updated number of lexical units in the context at the current time step, the total number of lexical units in the context is updated.
[0127] In the specific implementation, when the interactive agent is reasoning based on the current context, if it finds that the selected representation cannot support subsequent judgments, it sends a review request to the context management module. The context management module locates the target review segment from historical storage based on the segment identifier, time step identifier, or segment index carried in the review request, and reads its corresponding original complete representation. This original complete representation is then pushed to the interactive agent to participate in the current round of reasoning. Subsequently, the number of lexical units in the current time step context is recalculated according to the number of lexical units occupied by this original complete representation, and this number is merged with the cumulative value of historical time steps to obtain the updated total number of context lexical units.
[0128] The target playback segment is a compressed interactive segment, meaning that selection indicates it is not the original complete representation.
[0129] There can be one or more target lookback segments. In some embodiments, the upper limit of the number of lookback segments per time step can be limited, such as 3, 5, etc., to prevent unbounded growth of the context or loading too many lexical units at once.
[0130] In some embodiments, after the interactive agent locates the compressed interactive segments corresponding to the breakpoint, if the number of interactive segments exceeds the corresponding upper limit, the interactive agent can filter out the upper limit number of interactive segments according to a preset filtering rule as target replay segments and initiate a replay request. For example, the filtering can be based on one or more of the following: the time step corresponding to each located interactive segment, the selection indication, and the degree of association with the breakpoint.
[0131] In other embodiments, the playback request may request to playback each of the positioned interaction segments. After receiving the playback request, the context management module determines the number of segments to be played back. If the number exceeds the corresponding upper limit, the context management module selects the upper limit number of interaction segments according to the preset filtering rules as the target playback segments and returns the original complete representation of the target playback segment.
[0132] Figure 2 A schematic diagram of a context extraction framework provided in this application is shown below. Figure 2 As shown, the context extraction framework includes a memory storage unit, a current query construction unit, an attention relevance scorer, a compression pressure calculation unit, a dynamic compression unit, an interactive agent, and a representation generator.
[0133] The memory storage unit stores multi-granular representations and key embedding vectors Ki of interaction segments from historical time steps (time step 1 to time step t-1), such as chunk 1 to chunk t-1 granular representations. Each interaction segment's multi-granular representation includes the original complete representation, detailed summary, concise summary, and placeholders. The current query construction unit constructs the current query representation based on the user's original task Q and the interaction segments from the most recent steps, such as chunk t-1 and chunk t-2, and encodes them to obtain the current query embedding vector. The attention relevance scorer reads the key embedding vectors pre-stored in all interaction segments in the memory storage unit and calculates the cosine similarity with the current query embedding vector to obtain the original relevance score of each interaction segment. All the original relevance scores are used as features input to a lightweight prediction neural network. After the neural network completes the score fitting correction, the network output is normalized to obtain the standardized weights corresponding to each interaction segment, which are used to represent the semantic importance of each interaction segment relative to the current query task.
[0134] The compression pressure calculation unit calculates the compression pressure value based on the number of task execution steps and context budget usage, and determines the weight thresholds α, β, and γ based on the compression pressure value.
[0135] In the dynamic compression unit, the selected representation of each interaction segment is determined from its multi-granularity representation by comparing the weights of each interaction segment with three thresholds: α, β, and γ. A weight greater than γ indicates the original complete representation; a weight between γ and β indicates a detailed summary; a weight between β and α indicates a concise summary; and a weight less than or equal to α indicates a placeholder. The selected representations of each interaction segment are then concatenated and output.
[0136] The selected representations of the concatenated interaction fragments, along with system prompts and the user's original task, are used to construct a context, which serves as the observation content of the interactive agent. Based on this context, the interactive agent actively conducts logical reasoning, generates a thought process, determines the action to be executed, and invokes the environment or tools. The content output by the interactive agent during the reasoning process serves as the interaction fragment of the current time step. The representation generator produces a multi-granular representation and key embedding vector of the interaction fragment chunk t of the current time step, which is then stored back in the memory storage unit. This process is repeated to complete multiple rounds of temporal interaction processing.
[0137] Furthermore, this context-extraction framework also includes a lookback mechanism. If, during reasoning, the interactive agent determines that the information in a compressed interaction segment within the context is insufficient, it can retrieve the original, complete representation of the corresponding interaction segment from the memory storage unit to supplement detailed information and improve reasoning accuracy. These components form a closed loop, enabling the interactive agent to continuously maintain a compact and high-value context during long-term tasks.
[0138] This application also provides an interaction method for long-term tasks, including: receiving the user's original task input by the user; obtaining the context of each time step based on the method provided above at each time step; performing inference based on the context of the time step to obtain and output the inference result of the current time step.
[0139] By first receiving the user's original task, a stable task objective anchor can be established for the entire long-term interaction. At each time step, the context of that time step is obtained based on the aforementioned context construction method. This allows the current input to be organized around the information truly needed for that time step, and content more suitable for subsequent inference can be extracted from recent interaction fragments based on relevance. This avoids the omission of key information caused by the indiscriminate accumulation of historical information, fixed truncation, or uniform summaries. Furthermore, inference based on this context and outputting the inference result for the current time step allows the model to maintain continuous focus on the task's main thread and key evidence within a limited context window. This reduces the burden of redundant information on attention allocation and computational resource consumption, thus improving inference accuracy, response efficiency, and multi-step interaction stability in long-term tasks.
[0140] Figure 3 A schematic diagram of the context extraction device provided in this application is shown below. Figure 3 As shown, the context extraction device provided in this embodiment includes:
[0141] The query generation module generates a current query representation based on the user's original task and multiple recent interaction segments; these recent interaction segments are interaction segments from multiple time steps prior to the current time step; and it encodes the current query representation to obtain the current query embedding vector. The weight calculation module determines the weight of each interaction segment based on the similarity between the current query embedding vector and the key embedding vector of the interaction segment. The dynamic compression module determines the selected representation of an interaction segment from its multi-granularity representation based on its weight. The context generation module generates and outputs the context of the user's original task at the current time step based on the selected representations of each interaction segment.
[0142] In one possible embodiment, the dynamic compression module includes:
[0143] The compression pressure value acquisition unit is used to acquire the compression pressure value at the current time step; the weight threshold determination unit is used to determine multiple weight thresholds based on the compression pressure value; and the dynamic compression unit is used to determine the selected representation of the interactive segment from the multi-granularity representation of the interactive segment based on the comparison result of the weight of the interactive segment and multiple weight thresholds.
[0144] In one possible embodiment, the compression pressure value acquisition unit is specifically used for:
[0145] The compression pressure value at the current time step is calculated based on the total number of context lexical units and the current time step; the total number of context lexical units is the cumulative value of the number of context lexical units generated in the historical time steps.
[0146] In one possible embodiment, the compression pressure value of the current time step is the larger of the ratio of the current time step to the preset time sequence length and the ratio of the total number of context lexical units to the preset lexical budget.
[0147] In one possible embodiment, the device further includes a multi-granularity characterization generation module for:
[0148] After the interactive agent performs reasoning based on the context of the current time step and obtains the reasoning result, a multi-granular representation of the interaction segment of the current time step is generated based on the reasoning result, and a key embedding vector of the current time step is generated.
[0149] In one possible embodiment, the device further includes a playback module for:
[0150] In response to the review request from the interactive agent, the target review segment is determined; the original complete representation of the target review segment in the multi-granularity representation is pushed to the interactive agent; based on the original complete representation of the target review segment, the number of lexical units in the context at the current time step is updated; based on the updated number of lexical units in the context at the current time step, the total number of lexical units in the context is updated.
[0151] In one possible embodiment, the multi-granularity representation of the interaction fragment includes the original complete representation of the interaction fragment, summaries at multiple levels of detail, and placeholders; multiple weight thresholds include a first threshold and multiple second thresholds; the dynamic compression module is specifically used for:
[0152] If the weight of the interactive segment is greater than the first threshold, the selected representation of the interactive segment is determined to be the original complete representation; if the weight of the interactive segment is less than or equal to the first threshold and greater than the minimum of multiple second thresholds, the selected representation of the interactive segment is determined from multiple summaries of detail based on the comparison result of the weight of the interactive segment and multiple second thresholds; if the weight of the interactive segment is less than or equal to the minimum of multiple second thresholds, the selected representation of the interactive segment is determined to be a placeholder.
[0153] In one possible embodiment, the weight calculation module is specifically used for:
[0154] Based on the cosine similarity between the current query embedding vector and the key embedding vector of the interaction segment, the relevance score of the interaction segment is obtained; the relevance score of the interaction segment is normalized to obtain the weight of the interaction segment.
[0155] The context extraction device provided in this embodiment can execute the context extraction method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.
[0156] Figure 4 A schematic diagram of the structure of the electronic device provided in this application. Figure 4 As shown, the electronic device 40 provided in this embodiment includes at least one processor 401 and a memory 402. Optionally, the electronic device 40 further includes a communication component 403. The processor 401, memory 402, and communication component 403 are connected via a bus.
[0157] In a specific implementation, at least one processor 401 executes computer execution instructions stored in memory 402, causing at least one processor 401 to perform the above-described method.
[0158] The specific implementation process of processor 401 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0159] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0160] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.
[0161] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0162] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0163] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.
[0164] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0165] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.
[0166] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0167] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0168] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0169] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0170] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0171] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
Claims
1. A context extraction method, characterized in that, include: Generate the current query representation based on the user's original task and multiple recent interaction segments; The multiple recent interaction segments are interaction segments with multiple time steps prior to the current time step; The current query representation is encoded to obtain the current query embedding vector; For each interaction segment, the weight of the interaction segment is determined based on the similarity between the current query embedding vector and the key embedding vector of the interaction segment. Based on the weight of the interaction segment, the selected representation of the interaction segment is determined from the multi-granularity representation of the interaction segment; Based on the selection representation of each interaction segment, the context of the current time step of the user's original task is generated and output.
2. The method according to claim 1, characterized in that, The determination of the selected representation of an interaction segment from its multi-granularity representation based on the weight of the interaction segment includes: Get the compression pressure value at the current time step; Based on the compression pressure value, multiple weight thresholds are determined; Based on the comparison results between the weight of the interaction segment and the multiple weight thresholds, the selected representation of the interaction segment is determined from the multi-granularity representation of the interaction segment.
3. The method according to claim 2, characterized in that, The step of obtaining the compression pressure value at the current time step includes: The compression pressure value of the current time step is calculated based on the total number of context lexical units and the current time step; the total number of context lexical units is the cumulative value of the number of context lexical units generated in the historical time steps.
4. The method according to claim 3, characterized in that, The compression pressure value of the current time step is the larger of the ratio of the current time step to the preset time sequence length and the ratio of the total number of context lexical units to the preset lexical unit budget.
5. The method according to claim 3, characterized in that, The method further includes: After the interactive agent performs reasoning based on the context of the current time step and obtains the reasoning result, a multi-granular representation of the interaction fragment of the current time step is generated based on the reasoning result, and a key embedding vector of the current time step is generated.
6. The method according to claim 5, characterized in that, The method further includes: In response to the playback request from the interactive agent, the target playback segment is determined; The original complete representation in the multi-granularity representation of the target review segment is pushed to the interactive agent; Based on the original complete representation of the target review segment, update the number of lexical units in the context of the current time step; Update the total number of context lexical units based on the number of context lexical units updated at the current time step.
7. The method according to claim 2, characterized in that, The multi-granularity representation of the interaction fragment includes the original complete representation of the interaction fragment, summaries at multiple levels of detail, and placeholders; the multiple weight thresholds include a first threshold and multiple second thresholds; The determination of the selected representation of the interaction segment from the multi-granularity representation of the interaction segment based on the comparison result of the weight of the interaction segment and the plurality of weight thresholds includes: If the weight of the interactive segment is greater than the first threshold, then the selection of the interactive segment is determined to be the original complete representation; If the weight of the interactive segment is less than or equal to the first threshold and greater than the minimum value among the plurality of second thresholds, then based on the comparison result of the weight of the interactive segment and the plurality of second thresholds, the selection representation of the interactive segment is determined from the plurality of detailed summaries; If the weight of the interactive segment is less than or equal to the minimum value among the plurality of second thresholds, then the selection of the interactive segment is determined to be the placeholder.
8. The method according to any one of claims 1-7, characterized in that, The step of determining the weight of the interaction segment based on the similarity between the current query embedding vector and the key embedding vector of the interaction segment includes: Based on the cosine similarity between the current query embedding vector and the key embedding vector of the interaction segment, the relevance score of the interaction segment is obtained; The relevance scores of the interaction segments are normalized to obtain the weights of the interaction segments.
9. An interaction method for long-term tasks, characterized in that, include: Receive the user's original task input; At each time step, the context of the time step is obtained based on the method provided by any one of claims 1-8; Reasoning is performed based on the context of the time step to obtain and output the reasoning result of the current time step.
10. A context extraction device, characterized in that, include: The query generation module is used to generate the current query representation based on the user's original task and multiple recent interaction fragments; The multiple recent interaction segments are interaction segments with multiple time steps prior to the current time step; and the current query representation is encoded to obtain the current query embedding vector; The weight calculation module is used to determine the weight of each interaction segment based on the similarity between the current query embedding vector and the key embedding vector of the interaction segment. A dynamic compression module is used to determine the selected representation of the interaction segment from the multi-granularity representation of the interaction segment based on the weight of the interaction segment; The context generation module is used to generate and output the context of the current time step of the user's original task based on the selected representation of each interaction fragment.
11. An electronic device, characterized in that, include: Memory, processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-8.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-8.
13. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method described in any one of claims 1-8.
