A context dynamic pruning method for multi-agent dialogue
By adopting a context-based dynamic pruning method for multi-agent dialogue, the problems of information redundancy and high resource consumption in multi-agent systems are solved, achieving efficient context management and accurate information routing, thereby improving the system's resource utilization efficiency and task execution accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU SHUYUAN TECHNOLOGY CO LTD
- Filing Date
- 2026-02-25
- Publication Date
- 2026-05-05
AI Technical Summary
Existing technologies lack effective context management methods in multi-agent systems, resulting in information redundancy, high resource consumption, and difficulty in achieving efficient reuse of key information. Furthermore, existing strategies fail to fully utilize topic information and business constraints for optimization.
We adopt a context-dynamic pruning method for multi-agent dialogue, which achieves efficient context management and resource optimization by combining input collection and standardization, context storage and pruning trigger judgment, context compression, context evaluation and dynamic pruning, and gating attention mechanism and multi-agent routing capability.
It effectively balances resource consumption and information retention requirements in long context management, improves the recall rate and routing accuracy of key context information, reduces interference from non-topic information, improves the accuracy of subsequent inference and routing, reduces the system's dependence on the underlying model, and enhances the universality and flexibility of the method.
Smart Images

Figure CN121745148B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and human-computer interaction, and in particular to a method for dynamic context trimming in multi-agent dialogue. Background Technology
[0002] In scenarios where multi-agent systems collaborate with large language models (LLMs) to complete complex tasks, efficiently managing the ever-growing multi-turn dialogue context is a key challenge. Contextual information is the core basis for user intent recognition and task distribution, and its management quality directly determines the system's response accuracy and processing efficiency.
[0003] Currently, there is a great deal of research on context management both domestically and internationally, but it mainly focuses on the interaction scenarios between users and a single LLM. For the complex interaction scenarios between users, multi-agent systems and LLMs, existing technologies lack public and detailed explanations.
[0004] Therefore, existing related technologies still have many limitations:
[0005] 1. Most existing technical solutions focus on security and strategy, lack semantic refinement, rarely involve intelligent trimming and compression of the semantic content of the context itself, and mostly only use single-dimensional trimming strategies such as time window truncation or pure similarity scoring, which cannot utilize topic information and business constraints for joint optimization, and are prone to losing key evidence or retaining redundant information.
[0006] 2. While the processing method is simple, it struggles to handle information redundancy. Some technical solutions construct context by building historical message chains, a relatively simple approach. However, this method easily accumulates a large amount of redundant information in long conversations, failing to proactively identify and remove duplicate or secondary content. Furthermore, it lacks state management of the context's lifecycle, making it difficult to achieve structured condensation and efficient reuse of key information in long conversations.
[0007] 3. Existing complex strategies are often costly to implement, difficult to maintain parameters, and do not deeply integrate with the dynamic routing capabilities of multi-agent systems. Summary of the Invention
[0008] The purpose of this invention is to solve the above-mentioned problems by proposing a dynamic context trimming method for multi-agent dialogue.
[0009] To achieve the above objectives, the following technical solution was adopted:
[0010] A dynamic context trimming method for multi-agent dialogue, specifically including the following steps:
[0011] S1: Input acquisition and context field object standardization;
[0012] Receive heterogeneous data from multi-agent dialogue scenarios and standardize the heterogeneous data into context field objects.
[0013] The heterogeneous data includes at least user input, tool call results, historical dialogue records, external knowledge base hit results, and intermediate conclusions of each sub-agent.
[0014] The context field object contains at least text content, status markers, risk markers, and vector representations. The status markers include at least incomplete, completed, compressed, and representative summary. The status markers of newly generated context field objects are all initialized to incomplete.
[0015] S2: Context storage and clipping trigger judgment;
[0016] The standardized context field object is stored in the original text cache area, and the status data of the original text cache area is monitored. When the preset triggering conditions are met, the dynamic pruning process is started.
[0017] Specifically, the status data includes at least the amount of data in the original text cache, the total number of tokens, and the last processing time.
[0018] Specifically, a first threshold is preset for the triggering condition. Second threshold and the third threshold The dynamic cropping process will be initiated when any of the following conditions are met:
[0019] The number of context field objects in the original text cache area reaches a first threshold. Or, the estimated total number of tokens for all the context field objects in the original text cache reaches the second threshold. Or the time interval since the last cropping operation reaches the third threshold. .
[0020] S3: Context compression;
[0021] Monitor the status flags of the context field objects. When the number of context field objects with the status flag "completed" meets the conditions for triggering compression, merge the context field objects that meet the conditions and generate a structured task summary. Use the task summary as a new context field object with the status flag "representative summary" and store it in the representative summary area.
[0022] Specifically, step S3 includes the following sub-steps:
[0023] S301: Compression trigger condition;
[0024] A compression threshold θ is predetermined to represent the number of context field objects to be processed. When the number of context field objects marked as completed reaches the compression threshold θ, a compression operation is performed to obtain these objects and form a compressed input context set. If the threshold is not reached, compression will not be performed, and more context field objects will be waited for until their number reaches the compression threshold θ.
[0025] S302: Merged content;
[0026] The compressed input context set The text content of all context field objects is concatenated and processed using a large language model or structured summarizer to generate a structured summary text that contains at least key points, entities, and conclusions.
[0027] S303: Vectorized representation;
[0028] The structured summary text is vectorized and created as a new context field object with its status flag updated to represent the summary. This object is then stored in the summary area, while the system timestamp is recorded.
[0029] S304: Status update;
[0030] The compressed input context set The state flags of all original context field objects are updated to compressed, and a backtracking association is established with the newly created context field objects.
[0031] S4: Contextual evaluation and dynamic clipping;
[0032] When the dynamic pruning process is started, all context field objects marked as incomplete or representing a summary are obtained from the original text cache area and the representative summary area to form a candidate context set.
[0033] Calculate the gating attention score of the context field object within the candidate context set. .
[0034] Specifically, the specific steps for calculating the gated attention score include:
[0035] S401: Mask filtering;
[0036] For the context field objects in the candidate context set, filter them by calculating their Boolean mask; filter out context field objects whose status is marked as incomplete or represents a summary and whose risk is marked as 0;
[0037] S402: Topic matching degree calculation;
[0038] The context field objects selected from the candidate context set are projected through the projection matrix W. t Projected onto the subject space, the projected matrix is obtained. Calculate the projected matrix The matching score matrix S between the target theme base matrix T and the target theme base matrix is calculated using the following formula:
[0039]
[0040] The distribution P(i,k) of each candidate topic is calculated using the softmax function, with the following formula:
[0041]
[0042] Where P(i,k) is the topic distribution, S i,k Let i be the matching score matrix, where i represents the i-th context field object selected from the candidate context set, and k represents the k-th topic.
[0043] The topic matching degree is defined based on the topic distribution P(i,k). The calculation formula is:
[0044]
[0045] S403: Basic attention weights;
[0046] For each object in the candidate context set, its basic attention weights are calculated. The calculation formula is: ;in, The semantic saliency of a context field object can be calculated using methods such as the percentage of intersection between the key entities contained in the context and the list of key entities in the domain. The time decay coefficient, and These are the current timestamp and the object timestamp, respectively.
[0047] S404: Attention Calculation;
[0048] For each context field object in the candidate context set, calculate its gated attention score. ;
[0049] Among them, the gated attention score The calculation formula is:
[0050]
[0051] in, , , These are the preset weighting coefficients;
[0052] The maximum match between this context field object and the theme prototype library;
[0053] The maximum cosine similarity between the context field object and other context field objects in the candidate context set;
[0054] The compliance risk score for this object is obtained based on risk analysis of the text content of the context field object, and... The risk analysis method includes at least one of the following: a pre-trained lightweight neural network model, a predefined risk keyword library, and the agent's historical risk records.
[0055] S405: Candidate weight calculation;
[0056] For each context field object in the candidate context set, its gating attention score is calculated. The σ value is converted into a soft-gated value using the Sigmoid function. And based on the basic attention weights Calculate the candidate weights of the context field object. The calculation formula is: .
[0057] The soft gating value The specific calculation formula is as follows:
[0058]
[0059] in, This is a soft-gating value. The gating attention score.
[0060] Based on the gated attention score The context field objects are selected from the candidate context set and combined to form the core context set. For the core context set The context field object within is subjected to weight normalization to obtain the final weight. .
[0061] Specifically, based on gating attention scores Sort the data and select K context field objects to form the core context set. If the number of context field objects is less than K, all of them are selected; where K is a preset threshold for the number of clipping objects; thus, the core context set is obtained. Then, for the core context set The context field object within is subjected to weight normalization processing, specifically through the following steps:
[0062] For the core context set The candidate weights of each of the context field objects in the dataset are normalized to obtain the final weights. The specific calculation formula is as follows:
[0063]
[0064] in, , To represent the candidate weights of objects in the core context set, i and j are the core context set. The index of the context field object, ε is a very small positive number to prevent division by zero errors.
[0065] S5: Task routing;
[0066] Based on the predetermined multi-agent capability matrix R and the core context set The final weight of the object Calculate the set Routing scores between the internal context field object and each sub-agent;
[0067] The context field object corresponding to the current user input, and the final weight. Sorted core context set The context packet is packaged and routed to one or more target sub-agents based on the routing score.
[0068] Specifically, the multi-agent capability matrix R[agent,Topic]∈[0,1] represents the capability matching degree between a certain agent and a certain topic, and the routing score is calculated using the following formula:
[0069]
[0070] in, This is the multi-agent capability matrix;
[0071] The best matching topic for context field object i;
[0072] The final weight of context field object i;
[0073] The soft risk value for context field object i, the specific value of which is based on the risk assessment. It is confirmed that this value is a continuous risk intensity value, and ≥0, the higher the value, the higher the compliance risk of the context field object, and the lower its priority in the routing process;
[0074] α, β, and λ are preset weighting coefficients that control the impact of capability matching degree, final weight of context object, and soft risk value, respectively.
[0075] S6: Sub-agent execution and result aggregation;
[0076] The target sub-agent executes the received context packet, parses and performs inference tasks, and outputs structured intermediate results;
[0077] The structured intermediate results include at least the content of the reasoning result, the list of evidence cited, the confidence level of the result, the number of tokens consumed in the reasoning process, and the reasoning delay time.
[0078] The intermediate results output by all sub-agents are aggregated and their consistency verified to generate the final output.
[0079] Specifically, the steps for aggregating and verifying the consistency of the intermediate results from all sub-agents are as follows:
[0080] S601: Weighted aggregation;
[0081] The confidence level of the intermediate result is based on the final weight of the context field object it consumes. The summation involves weighting and fusing the reasoning results of all agents to form a preliminary aggregated result.
[0082] S602: Conflict resolution;
[0083] The system detects whether there are conflicting entities or conclusions in the preliminary aggregation results; if there are conflicts, they are resolved through a voting mechanism or predefined business rules to form a consistent final output.
[0084] S603: Compliance Verification;
[0085] The final output of the consistency is verified for content security and compliance; if a compliance risk is found, the content of the reasoning result is automatically rewritten or anonymized.
[0086] Specifically, after step S6, memory updates and online learning are also supported, with the following steps:
[0087] High-value final outputs or intermediate results are precipitated as new context field objects with status tags representing summaries and stored in the representative summary area;
[0088] Based on the contributions of each agent to different topics during this task execution, the capability matching degree in the multi-agent capability matrix R is updated online. Specifically, the contribution of a sub-agent is determined by the confidence level of the inference result of its intermediate output, the task success rate, or the final weight of the context field objects it consumes. One or more of them can be used for quantification.
[0089] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0090] 1. This invention effectively balances resource consumption and information retention requirements in long context management by introducing a two-level collaborative processing architecture of "context compression" and "dynamic pruning". Compared with traditional fixed window truncation or single similarity retrieval methods, this invention can significantly improve the recall rate and routing accuracy of key context information while strictly controlling computation and token overhead.
[0091] 2. The "gated attention mechanism" employed in this invention integrates multiple dimensions such as topic matching degree, redundancy, risk degree, time decay, and semantic saliency to jointly evaluate the context. This multi-factor joint optimization strategy overcomes the shortcomings of traditional methods, such as single screening dimensions and insensitivity to redundancy and risk, and achieves a leap from "simple filtering" to "intelligent screening".
[0092] 3. By projecting the context vector onto a topic space defined by domain knowledge for computation, this invention can effectively reduce interference from non-topic information and ensure that the retained context is highly semantically consistent with the current task intent, thereby significantly improving the accuracy of subsequent reasoning and routing.
[0093] 4. This invention explicitly introduces redundancy (highest similarity within the same batch) and topic consistency into the gating score. The hedging mechanism effectively suppresses duplicate information without sacrificing important thematic evidence, resulting in better deduplication while maintaining focus on key themes, further enhancing contextual relevance and task execution accuracy.
[0094] 5. This invention utilizes theme projection W t With the base T, the topic space can be quickly constructed using a small number of domain prototype sentences and corpora, which reduces the system's dependence on the underlying dialogue model and embedded model version, reduces migration costs, and facilitates cross-domain reuse, thereby significantly improving the universality and flexibility of the method. Attached Figure Description
[0095] Figure 1 This is a flowchart illustrating the steps of a dynamic context trimming method for multi-agent dialogue according to the present invention.
[0096] Figure 2 This is a flowchart illustrating step S3 of the present invention;
[0097] Figure 3 This is a flowchart illustrating step S4 of the present invention;
[0098] Figure 4 This is a schematic diagram of the system architecture of a context dynamic pruning system for multi-agent dialogue according to the present invention. Detailed Implementation
[0099] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, the specific embodiments of this application will be described in detail below with reference to the accompanying drawings.
[0100] like Figure 4 As shown, the context-dynamic pruning system for multi-agent dialogue of the present invention mainly includes the following core modules:
[0101] Input Acquisition and Standardization Module: Used to receive and uniformly format multi-source heterogeneous data.
[0102] Session storage and indexing module: Used to store and manage the lifecycle of context field objects, including the original text cache, the representative summary area, and the vector index.
[0103] Theme space building module: provides projection matrix and theme base Responsible for using the projection matrix Map context vectors to topic space.
[0104] Context evaluation and pruning module: used to perform gating attention calculation and dynamic pruning.
[0105] Context compression module: First, it uses budget control to ensure that context processing is within resource limits. Then, it is responsible for the structured compression of historical context.
[0106] Multi-agent capability graph and distribution module: This module maintains a "capability matrix" This is used to characterize the processing capabilities of each agent on a specific topic, and based on this, intelligent routing decisions are executed.
[0107] Sub-agent execution module: Used to receive context packets and execute specific inference tasks.
[0108] The results aggregation and consistency verification module is used to merge the outputs of multiple agents and resolve conflicts.
[0109] Memory Update and Learning Module: Used to convert high-value outputs into "representative summaries" ( ), and used for subsequent Computation and context compression.
[0110] like Figure 1 As shown, a dynamic context trimming method for multi-agent dialogue specifically includes the following steps:
[0111] S1: Input acquisition and context field object standardization;
[0112] The input acquisition and standardization module receives heterogeneous data such as user input, tool call results, historical dialogue records, external knowledge base hit results, and intermediate conclusions from each sub-agent. All input data will be uniformly converted into a context field object, specifically represented by the function: ContextItem: { , , , , , , , , }
[0113] The elements and their meanings are as follows:
[0114] id: A globally unique identifier used for item retrieval, deduplication, and tracing. It is preferably a string that cannot be repeated.
[0115] text: Standardized contextual text content, including readable representations of user input, tool results, historical dialogues, retrieval hits, or intermediate conclusions of sub-agents;
[0116] : Estimating the number of tokens for text under the target model's tokenizer, used for length constraints, resource budgeting, and pruning strategy control;
[0117] ts: timestamp, records the time when the entry was generated or collected;
[0118] state: Processing status identifier, representing the stage of an entry in the pipeline;
[0119] Risk marker is a binary marker. It is set to 1 if the risk value exceeds a preset threshold, and 0 if the risk value does not exceed the threshold.
[0120] source: Source type, indicating the sub-agent task to which this record belongs (marked by Agentic Agent);
[0121] Agent labeling indicates the agent that generated or most recently consumed the entry, facilitating accountability and collaborative management;
[0122] meta: an extensible metadata container;
[0123] Furthermore, the processing status identifier of the newly created context field object. It was initialized to 0 (incomplete), as shown in Table 1.
[0124] state meaning 0 (Not completed) Incomplete context (original dialogue content retained) 1 (Completed) Context completed (awaiting LLM compression) -1 (compressed) Compressed and not included in the calculation. 2 (Representative Summary) The new summary context generated by compression participates in the attention score calculation.
[0125] Table 1. Reference Table for the Meaning of Context State Markers
[0126] S2: Context storage and clipping trigger judgment;
[0127] The session storage and indexing module stores the standardized context field objects in the original text cache and continuously monitors three metrics of the original text cache: the number of objects, the total estimated number of tokens, and the time since the last pruning. When the preset trigger conditions are met, the dynamic pruning process is started.
[0128] Specifically, a first threshold is preset within the session storage and indexing module. Second threshold and the third threshold The preset trigger condition is: the number of context field objects in the original text cache reaches a first threshold. Or, the estimated total number of tokens for all the context field objects in the original text cache reaches the second threshold. Or the time interval since the last cropping operation reaches the third threshold. .
[0129] S3: Context compression;
[0130] The context compression module operates in parallel with the pruning process, continuously monitoring the status flags of all context field objects. When the number of context field objects with a status flag of "1" (completed) meets the compression trigger condition, the context compression action is triggered, merging the context field objects that meet the condition and generating a structured task summary. The task summary is then stored as a new context field object with a status flag of "2" (representative summary) in the representative summary area.
[0131] Specifically, such as Figure 2 As shown, context compression includes the following sub-steps:
[0132] S301: Compression trigger condition;
[0133] A preset compression threshold θ is used to determine when compression should begin when the number of context entries to be processed reaches a certain number; its setting is derived from system configuration. When the number of context field objects with a status marker of "1" (completed) reaches the compression threshold θ, these objects are retrieved and a compressed input context set is formed. .
[0134] If the threshold is not reached, compression is not performed, and more context field objects with the status marked "1" (completed) are waited for until their number reaches the compression threshold θ.
[0135] S302: Merged content;
[0136] The compressed input context set The text content of all context field objects in the array is concatenated using the following expression:
[0137]
[0138] in, To merge text, the input context set is compressed. The text content of each item It is obtained by piecing together in a predetermined order.
[0139] The merged text obtained by splicing Input compression function The process generates a structured summary text that contains at least key points, entities, and conclusions. ,Right now .
[0140] S303: Vectorized representation;
[0141] The structured summary text is vectorized and created as a new context field object with the status flag updated to "2" (representing a summary). The corresponding vector representation is generated and stored in the summary representation area, while the system timestamp is recorded.
[0142] S304: Status update;
[0143] Compress the input context set The status flag of all compressed context field objects is updated to "-1" (compressed), and a backtracking association is established with the newly created context field object.
[0144] The purpose of this algorithm is to perform semantic compression and structured refinement on the historical context of "increasing volume but decreasing marginal value" without losing key information, and generate representative summary text that can participate in subsequent attention and gating calculations. This reduces token overhead and response latency, improves the signal-to-noise ratio and stability of subsequent routing, retrieval and inference, and ensures the consistency and traceability of long-term dialogue through a state machine.
[0145] S4: Contextual evaluation and dynamic clipping;
[0146] When the dynamic pruning process is initiated, all context field objects with a status marker of "0" or "2" (incomplete or representing a summary) are retrieved from the original text cache and the representative summary area to form a candidate context set. The gating attention score of the context field objects within the candidate context set is then calculated. .
[0147] Specifically, such as Figure 3 As shown, the gating attention score is calculated. Includes the following sub-steps:
[0148] S401: Mask filtering;
[0149] First, for the context field objects in the candidate context set, calculate their boolean masks. The filter selects context field objects with a status marked as "0" or "2" (incomplete or representing a summary) and a risk marker of 0. If the conditions are not met, then All risk items will be excluded. The specific expression is:
[0150]
[0151] in, For status flags, Risk markers for context field objects, This refers to each context field object. Furthermore, this step only performs boolean filtering and does not change the subsequent gating attention score. The calculation.
[0152] S402: Topic matching degree calculation;
[0153] Selected from the candidate context set The context field object is projected through the matrix W. t Projected onto the subject space, the projected matrix is obtained. Calculate the projected matrix The matching score matrix S between the target theme base matrix T and the target theme base matrix is calculated using the following formula:
[0154]
[0155] The topic distribution P(i,k) of each row of the matching score matrix S is calculated using the softmax function. The calculation formula is as follows:
[0156]
[0157] Where P(i,k) is the topic distribution, S i,k Let i be the matching score matrix, where i represents the i-th context field object selected from the candidate context set, and k represents the k-th topic.
[0158] The sample-level topic matching degree is defined based on the topic distribution P(i,k). The calculation formula is:
[0159]
[0160] S403: Basic attention weights;
[0161] For each object in the candidate context set, its basic attention weights are calculated. The calculation formula is:
[0162]
[0163] in, The semantic saliency of a context field object can be calculated by methods such as the percentage of intersection between the key entities contained in the context and the list of key entities in the domain, and is used to measure its semantic importance. The time decay coefficient, and These are the current timestamp and the object timestamp, respectively, representing time decay and giving more recent contexts a higher base weight.
[0164] S404: Attention Calculation;
[0165] For each context field object in the candidate context set, calculate its gated attention score. The specific calculation formula is as follows:
[0166]
[0167] in, , , These are the preset weighting coefficients;
[0168] The maximum match between this context field object and the theme prototype library;
[0169] Defined as the maximum cosine similarity between the context field object and other context field objects in the candidate context set, it is used to characterize the degree of information redundancy.
[0170] The risk score for this context field object is a predefined continuous risk intensity value, obtained based on risk analysis of the text content of the context field object. ;
[0171] Specifically, those skilled in the art can perform risk analysis on the text content of a context field object using any of the following methods:
[0172] The first approach employs a pre-trained lightweight neural network model. The text content is input into a lightweight model, DistilBERT, fine-tuned with compliant corpora. This model outputs a continuous risk probability value between [0,1], which is directly used as the current context field object. .
[0173] The second method employs rule-based and keyword-based quantitative calculation. A predefined thesaurus containing risky keywords and their weights is used; by scanning text content, the weights of the hit keywords are calculated, and the statistical values are mapped to the [0,1] interval using a pre-defined normalization function to obtain the result. .
[0174] The third approach combines historical behavior analysis. This is based on the source agent of the context field object (recorded in...). The historical risk records of the field are used to calculate a risk trend score by statistically analyzing the frequency or average risk value of past tasks. This score is then used as the basis for... .
[0175] S405: Candidate weight calculation;
[0176] For each context field object in the candidate context set, its gating attention score is calculated. The sigmoid function σ transforms the value into a soft gating value between 0 and 1. The specific calculation formula is as follows:
[0177]
[0178] in, This is a soft-gating value. The gating attention score.
[0179] And based on basic attention weights Calculate the candidate weights of the context field object. The calculation formula is:
[0180]
[0181] Then, based on the gating attention score Sort the data from highest to lowest, and select the top K context field objects to form the core context set for this round. If the number of context field objects is less than K, all of them are selected; where K is a preset threshold for the number of objects to be truncated. Core Context Set It contains all the filtered candidate context entries, which are considered to be the most relevant contextual information for the current task.
[0182] Obtain the core context set Then, for the core context set The context field object within is subjected to weight normalization processing, specifically through the following steps:
[0183] For the core context set The candidate weights of each of the context field objects in the dataset are normalized to obtain the final weights. The specific calculation formula is as follows:
[0184]
[0185] in, , To represent the candidate weights of objects in the core context set, where To prevent division by zero errors, ensure and Normalization gives the final weights relative importance, which facilitates subsequent resource allocation and weighted aggregation.
[0186] Furthermore, during the weight normalization process, each context field object has a fixed length of [length value missing]. If it exceeds the window size, it will be sorted by weight. Eliminate from largest to smallest. And the final weight... This is an importance score for each selected context field object, representing the object's contribution to the current task. This weight is used for:
[0187] (1) Sorting: Determines the priority of context field objects to ensure that the most relevant information is processed first.
[0188] (2) Quota allocation: Allocate system resources according to the weight of the context to ensure that important context field objects receive more computing resources.
[0189] (3) Segmentation: In the process of multi-turn dialogue and context transmission, weights may also affect the context splicing order and information integration method.
[0190] S5: Task routing;
[0191] The multi-agent capability graph and distribution module uses a predefined multi-agent capability matrix R and a core context set. The final weight of the context field object Calculate the set The routing score between the internal context field object and each sub-agent. The multi-agent capability matrix R[agent,Topic]∈[0,1] represents the capability matching degree between a certain agent and a certain topic. This capability matching degree can be statistically analyzed using an offline validation set or dynamically updated through online feedback.
[0192] Specifically, the formula for calculating the routing score is:
[0193]
[0194] in, This is the multi-agent capability matrix;
[0195] The best matching topic for context field object i;
[0196] The final weight of context field object i;
[0197] The soft risk value for context field object i, the specific value of which is based on the risk assessment. It is confirmed that this value is a continuous risk intensity value, and ≥0, the higher the value, the higher the compliance risk of the context field object, and the lower its priority in the routing process;
[0198] α, β, and λ are preset weighting coefficients that control the impact of capability matching, context weight, and risk factor, respectively.
[0199] The score takes into account the agent's topic matching ability, the importance weight of the context, and risk control factors.
[0200] Furthermore, regarding soft risk values Its relationship with risk assessment Each represents a continuous risk intensity value, which can be obtained in ways including but not limited to: quantification based on keyword matching, analysis based on semantic similarity, and acquisition using lightweight neural network models.
[0201] Specifically, the quantification based on keyword matching involves: predefining a risk keyword library, where each keyword corresponds to a basic risk score; extracting keywords from the context text and calculating the total risk score of keywords that match the risk keyword library; and using a predefined normalization function to map this total score into a continuous intensity risk value in the range [0,1].
[0202] The analysis based on semantic similarity is as follows: a risk text prototype library is preset, which contains typical illegal, sensitive or high-risk statements and their vector representations. The cosine similarity between the vector representation of the current context text and all texts in the risk text prototype library is calculated, and the maximum value is taken as the risk intensity value.
[0203] The acquisition using a lightweight neural network model specifically involves calling a pre-trained lightweight neural network capable of outputting continuous risk probabilities. In this embodiment, a text classifier based on BERT fine-tuning is used to evaluate the context text in real time, and the output probability value is used as the continuous risk intensity value.
[0204] After obtaining the routing score, then, based on the routing score... A context packet is constructed for each target sub-agent, and this context packet is routed to one or more target sub-agents. The context packet contains the context field object corresponding to the current user input, and the values according to the final weights. Sorted core context set .
[0205] Furthermore, the multi-agent capability graph and distribution module supports flexible assignment strategies to adapt to different scenarios: When using single routing, the routing scores of all contexts are aggregated and assigned to each agent, with the agent with the highest total score selected as the sole executor. This is suitable for scenarios with clear task boundaries and no need for collaboration. In multi-routing or collaborative modes, a Softmax function is applied to the routing scores of all agents to obtain a probability distribution. Then, sampling is performed based on the probability, or multiple agents with probabilities exceeding a certain threshold are selected to execute in parallel, but the total number does not exceed a preset upper limit M. This is suitable for complex tasks requiring multi-faceted analysis.
[0206] In addition, regarding quota allocation, the context of each sub-agent... Quotas are calculated by determining the final weight of the context field object under the agent. The total budget is determined by multiplying the sum of the total budgets by the global budget or the sub-budgets of the agent, thereby rationally allocating system resources. In this embodiment, the agent's quota is: Agent A's quota = (the sum of the items allocated to Agent A) / (the sum of the total budgets of Agent A's sub-budgets). (Sum of all) × Total Token Budget. This weighted replication allocation method ensures that important contexts receive more computing resources for in-depth processing.
[0207] S6: Sub-agent execution and result aggregation;
[0208] Each assigned sub-agent receives its customized context packet, parses it, and executes the inference task in parallel within its respective runtime environment. After the inference task is completed, it outputs a structured intermediate result. This structured intermediate result is a standardized data structure that includes at least: content (the content of the inference result). (Cited evidence related to the reasoning result), confidence (the degree of confidence in this reasoning), (Number of tokens used to generate inference results), latency (inference delay time). The structured output facilitates subsequent aggregation.
[0209] The intermediate results output by all sub-agents are aggregated and their consistency verified to generate the final output.
[0210] Specifically, the steps for the result aggregation and consistency verification module to aggregate and verify the intermediate results of all sub-agents are as follows:
[0211] S601: Weighted aggregation;
[0212] The final weight is determined by the confidence level of the intermediate results output by each agent and the context field objects it consumes. The summation of the inference results from all agents is weighted and fused to form a preliminary aggregation result; where the final weights are... The results contributed by higher context account for a larger proportion in aggregation.
[0213] S602: Conflict resolution;
[0214] For conflicting entities or conclusions appearing in the initial aggregation results, the conflicts are resolved through voting mechanisms or predefined business rules to achieve a consistent final output. For example, if two agents give different answers regarding the inventory of the same product, the results are determined based on confidence level and final weight. To resolve the conflict.
[0215] S603: Compliance Verification;
[0216] Finally, a low-cost content security and compliance check is performed on the final output. If potential compliance risks are found in the output content, the system will automatically trigger a rewriting or de-identification process to ensure the output results are safe and reliable.
[0217] Specifically, the rewriting or desensitization process includes at least one or more of the following methods:
[0218] Based on the preset sensitive word library and desensitization rules, the identified sensitive entities, including at least personal names, ID numbers, and mobile phone numbers, are subjected to fixed character replacement or generalization processing.
[0219] Alternatively, a trained text rewriting model can be used to semantically preserve the sensitive information in sentences containing risk.
[0220] Alternatively, a dedicated privacy information identification interface or local library can be invoked to locate and directly delete sensitive data fragments that cannot be effectively processed by rewriting;
[0221] Furthermore, after step S6, the memory update and learning module supports memory updates and online learning, specifically through the following steps:
[0222] High-value final outputs or intermediate results are created as new context field objects with a status marker of "2" (representing a summary) and stored in the summary area. This achieves the transformation from interaction results to system knowledge, completing the knowledge accumulation.
[0223] Based on the contributions of each agent to different topics during this task execution, the capability matching degree in the multi-agent capability matrix R is updated online. This allows the system's routing decision-making capability to be continuously optimized with the accumulation of practical experience.
[0224] Furthermore, regarding the contribution of the sub-agent, it is based on the confidence of the inference result of the intermediate result output by the sub-agent, the task success rate, or the final weight of the context field objects consumed by the sub-agent. One or more of them can be used for quantification.
[0225] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of this application. Those skilled in the art may find other optimizations and additional functions in this application. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A method for dynamic context trimming in multi-agent dialogue, characterized in that: Includes the following steps: S1: Input acquisition and context field object standardization; Receive heterogeneous data from multi-agent dialogue scenarios and standardize the heterogeneous data into context field objects; The heterogeneous data includes at least user input, tool call results, historical dialogue records, external knowledge base hit results, and intermediate conclusions of each sub-agent. The context field object contains at least text content, status markers, risk markers, and vector representations. The status markers include at least incomplete, completed, compressed, and representative summary. The status markers of newly generated context field objects are all initialized to incomplete. S2: Context storage and clipping trigger judgment; The standardized context field object is stored in the original text cache area, and the status data of the original text cache area is monitored. When the preset triggering conditions are met, the dynamic pruning process is started. S3: Context compression; Monitor the status flags of the context field objects. When the number of context field objects with the status flag "completed" meets the conditions for triggering compression, merge the context field objects that meet the conditions to generate a structured task summary. Use the task summary as a new context field object with the status flag "representative summary" and store it in the representative summary area. S4: Contextual Evaluation and Dynamic Clipping When the dynamic pruning process is started, all context field objects marked as incomplete or representing a summary are obtained from the original text cache area and the representative summary area to form a candidate context set; Dynamic pruning is performed on the candidate context set, and the gating attention score of each context field object in the candidate context set is calculated. ; Based on the gated attention score The context field objects are selected from the candidate context set and combined to form the core context set. For the core context set The context field object within is subjected to weight normalization to obtain the final weight. ; S5: Task routing; Based on the predetermined multi-agent capability matrix R and the core context set The final weight of the object Calculate the set Routing scores between the internal context field object and each sub-agent; The context field object corresponding to the current user input, and the final weight. Sorted core context set Pack the data into a context packet, and route the context packet to one or more target sub-agents based on the routing score; S6: Sub-agent execution and result aggregation; The target sub-agent executes the received context packet, parses and performs inference tasks, and outputs structured intermediate results; The intermediate results output by all sub-agents are aggregated and their consistency verified to generate the final output.
2. The context dynamic pruning method for multi-agent dialogue as described in claim 1, characterized in that: In step S2, the status data includes at least the amount of data in the original text cache, the total number of tokens, and the last processing time; A first threshold is preset for the triggering condition. Second threshold and the third threshold The triggering condition is any of the following: The number of context field objects in the original text cache area reaches a first threshold. Or, the estimated total number of tokens for all the context field objects in the original text cache reaches the second threshold. Or the time interval since the last cropping operation reaches the third threshold. .
3. The context dynamic pruning method for multi-agent dialogue as described in claim 1, characterized in that: In step S3, the specific steps of context compression are as follows: S301: Compression trigger condition; A compression threshold θ is predetermined to represent the number of context field objects to be processed. When the number of context field objects marked as completed reaches the compression threshold θ, a compression operation is performed to obtain these objects and form a compressed input context set. If the threshold is not reached, compression will not be performed, and more context field objects will be waited for until their number reaches the compression threshold θ. S302: Merged content; The compressed input context set The text content of all context field objects is concatenated and processed using a large language model or structured summarizer to generate a structured summary text that contains at least key points, entities, and conclusions. S303: Vectorized representation; The structured summary text is vectorized and created as a new context field object with its status flag updated to represent the summary. This object is then stored in the summary area, while the system timestamp is recorded. S304: Status update; The compressed input context set The state flags of all original context field objects are updated to compressed, and a backtracking association is established with the newly created context field objects.
4. The context-based dynamic pruning method for multi-agent dialogue as described in claim 1, characterized in that: In step S4, the specific steps for calculating the gating attention score include: S401: Mask filtering; For the context field objects in the candidate context set, filter them by calculating their Boolean mask; filter out context field objects whose status is marked as incomplete or represents a summary and whose risk is marked as 0; S402: Topic matching degree calculation; The context field objects selected from the candidate context set are projected through the projection matrix W. t Projected onto the subject space, the projected matrix is obtained. Calculate the projected matrix The matching score matrix S between the target theme base matrix T and the target theme base matrix is calculated using the following formula: ; The distribution P(i,k) of each candidate topic is calculated using the softmax function, with the following formula: Where P(i,k) is the topic distribution, S i,k The matching score matrix is defined as follows: i represents the i-th context field object selected from the candidate context set, and k represents the k-th topic. The topic matching degree is defined based on the topic distribution P(i,k). The calculation formula is: S403: Basic attention weights; For each context field object in the candidate context set, calculate its basic attention weight. The calculation formula is: ;in, The semantic saliency of a context field object can be calculated by the percentage of the intersection between the key entities contained in the context and the list of key entities in the domain. The time decay coefficient, and These are the current timestamp and the object timestamp, respectively. S404: Attention Calculation; For each context field object in the candidate context set, calculate its gated attention score. ; S405: Candidate weight calculation; For each context field object in the candidate context set, its gating attention score is calculated. Through the Sigmoid function Convert to soft-gated value And based on the basic attention weights Calculate the candidate weights of the context field object. The calculation formula is: .
5. The context dynamic pruning method for multi-agent dialogue as described in claim 4, characterized in that: In step S404, the gated attention score The calculation formula is: in, , , These are the preset weighting coefficients; The maximum match between this context field object and the theme prototype library; The maximum cosine similarity between the context field object and other context field objects in the candidate context set; The risk score for compliance of this object is based on a risk analysis of the text content of the context field object, and... ; The risk analysis method includes at least one of the following: a pre-trained lightweight neural network model, a predefined risk keyword library, and a method based on the agent's historical risk records.
6. The context dynamic pruning method for multi-agent dialogue as described in claim 4, characterized in that: In step S405, the soft gating value The specific calculation formula is as follows: in, This is a soft-gating value. The gating attention score.
7. The context dynamic pruning method for multi-agent dialogue as described in claim 4, characterized in that: In step S4, based on the gating attention score Sort the data and select K context field objects to form the core context set. If the number of context field objects is less than K, all are selected; where K is a preset threshold for the number of clipping objects; after obtaining the core context set, the core context set is... The context field object within is subjected to weight normalization processing, specifically through the following steps: For the core context set Candidate weights for each of the context field objects in Normalization is performed, and the result is the final weight. The specific calculation formula is as follows: in, , To represent the core context set Candidate weights for context field objects, where i and j are the core context set. The index of the context field object, ε is a very small positive number to prevent division by zero errors.
8. The context dynamic pruning method for multi-agent dialogue as described in claim 1, characterized in that: In step S5, the multi-agent capability matrix R[agent,Topic]∈[0,1] represents the capability matching degree between a certain agent and a certain topic, and the formula for calculating the routing score is: in, This is the multi-agent capability matrix; The best matching topic for context field object i; The final weight of context field object i; The soft risk value for context field object i, the specific value of which is based on the risk assessment. It is confirmed that this value is a continuous risk intensity value, and ≥0, the higher the value, the higher the compliance risk of the context field object, and the lower its priority in the routing process; α, β, and λ are preset weighting coefficients that control the impact of capability matching degree, final weight of context object, and soft risk value, respectively.
9. The context-based dynamic pruning method for multi-agent dialogue as described in claim 1, characterized in that: In step S6, the structured intermediate result includes at least the content of the inference result, the list of cited evidence, the confidence level of the result, the number of tokens consumed in the inference process, and the inference delay time; the specific steps for aggregating and verifying the consistency of the intermediate results of all sub-agents are as follows: S601: Weighted aggregation; Based on the confidence level of the intermediate results and the final weight of the consumed context field objects. The outputs of all agents are weighted and fused to form a preliminary aggregation result. S602: Conflict resolution; Detect whether there are conflicting entities or conclusions in the preliminary aggregation results; If conflicts exist, they are resolved through voting mechanisms or predefined business rules to achieve a consistent final output. S603: Compliance Verification; The final output of the consistency is then verified for content security and compliance. If compliance risks are identified, the output content will be automatically rewritten or anonymized.
10. The context-dynamic pruning method for multi-agent dialogue as described in claim 1, characterized in that: Following step S6, memory updates and online learning are also supported. The specific steps are as follows: High-value final outputs or intermediate results are precipitated as new context field objects with status tags representing summaries and stored in the representative summary area; Based on the contributions of each agent to different topics during this task execution, the capability matching degree in the multi-agent capability matrix R is updated online. Specifically, the contribution of a sub-agent is determined by the confidence level of the inference result of its intermediate output, the task success rate, or the final weight of the context field objects it consumes. One or more of them can be used for quantification.
Citation Information
Patent Citations
Context compression method based on multi-round dialogue intention graph construction
CN121388182A
Systems and methods for multimodal conversational agents for biological sequence analysis
US20250292868A1