Large model memory enhancement method based on time perception consistency feedback and optimization
By employing a time-aware multidimensional memory consistency evaluation method, the consistency maintenance problem of large language models in multi-agent text generation systems is solved. This method enables structured modeling and automatic optimization of agents' long-term memory, thereby improving the consistency and stability of agents in the long-term generation process.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-15
- Publication Date
- 2026-03-13
AI Technical Summary
Existing large language models lack long-term structured memory modeling with temporal representation, quantifiable consistency evaluation, and automatic optimization mechanisms in multi-agent text generation systems, resulting in insufficient consistency maintenance capabilities of agents during long-term generation.
A time-aware multidimensional memory consistency assessment method is adopted. Through data preprocessing, structured memory modeling, multidimensional consistency assessment and adaptive optimization, the method can achieve long-term memory maintenance for each agent, consistency scoring of new text results and automatic correction and optimization generation.
It has enabled the agent to maintain its long-term behavioral style and stance, and has constructed a quantifiable and interpretable multi-dimensional consistency evaluation index system. It can automatically identify the reasons for the decline in consistency and perform closed-loop optimization, thereby improving the sustainability and stability of the agent's memory.
Smart Images

Figure CN121658867A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and natural language processing. Addressing the issue that most currently deployed large language models exhibit inconsistencies in their agent-based personas and perspectives over time, leading to a decline in memory capacity, this invention proposes a multi-agent memory enhancement method based on time-aware multidimensional memory consistency assessment and adaptive optimization. This method is applicable to scenarios such as public opinion analysis, current affairs commentary generation, and virtual character operation. Background Technology
[0002] With the development of large language models, multi-agent text generation and analysis systems based on large language models have been widely used in scenarios such as public opinion monitoring, event interpretation, and virtual entity operation. However, existing technologies mainly focus on the relevance and fluency of single-output text results, but in agent scenarios facing multi-turn interactions, long-term evolution, and continuous decision-making, the following shortcomings still exist: There is a lack of long-term structured memory modeling mechanisms with temporal representation for single intelligent agents. Most existing systems rely on caching context or simple text splicing to save historical information. They not only lack the ability to extract and model historical content in a structured manner, but also lack the ability to distinguish the importance of content generated in different time periods. This makes it difficult for intelligent agents to form reliable, traceable and interpretable long-term memory representations. There is a lack of a quantifiable evaluation system for the consistency between newly generated text and historical memory. Qualitative evaluations vary greatly depending on the evaluator, lack stability, and lack evaluation indicators that can change dynamically over time. It is difficult to comprehensively measure from dimensions such as character consistency, stance consistency, logical self-consistency, and keyword reuse. Therefore, it is impossible to accurately measure the consistency of the agent in the long-term generation process. When a contradiction in stance or memory shift is detected, there is usually a lack of automatic correction and optimization paths. It can only rely on manual review and rewriting, making it difficult to form a self-circulating optimization process. Furthermore, it is difficult to combine relevant historical information of the agent and lacks an automatic optimization mechanism. The time factor has not been incorporated into consistency analysis and agent behavior evolution. In practical applications, content generated in the long term should not usually have the same influence as content generated in the recent term. However, existing technologies lack a method for modeling the importance of historical information based on time decay weights, which is not conducive to building a model that is more in line with the laws of human social memory. Limited support for multi-agent scenarios: Existing technologies typically generate and evaluate dialogues for a single agent, and cannot maintain independent memory banks and scoring histories for multiple agents, nor can they intuitively compare the consistent performance of different agents.
[0003] Therefore, it is necessary to provide a multi-agent text processing method and system that can combine structured memory modeling, multi-dimensional consistency evaluation, and automatic optimization mechanisms. Summary of the Invention
[0004] The purpose of this invention is to overcome the shortcomings of existing technologies in multi-agent text generation, such as lack of event-related structured memory modeling, lack of quantifiable memory consistency assessment, and lack of automatic optimization mechanisms. It provides a multi-agent text processing method and system based on time-aware multidimensional memory consistency assessment, which realizes long-term memory maintenance for each agent, consistency scoring and automatic correction and optimization generation of new text results, and visualization analysis of scoring trends.
[0005] This invention is achieved through the following method: a large model memory enhancement method based on time-aware consistency feedback and optimization, the steps of which are as follows: Step 1) Data preprocessing: Obtain the historical interaction text generated by each agent in the target scenario, and use the preprocessing module to clean, time-label, and identify topics in the text to generate structured memory entries containing time, topics, etc. 1.1) Input the text to be processed, such as public opinion analysis, current affairs commentary, questions, dialogue context, etc. The multi-agent large language model is invoked for the first time to obtain the response of each agent. The multi-agent large language model can be represented as:
[0006] Each agent has its own independent identity, such as a virtual character, different commentators, a virtual speaker, an AI assistant, or a moderator. It receives text input generated at the current moment from multiple agents. First, a preprocessing module cleans and identifies the topic of the input text. Then, it traverses each agent's knowledge base. If the knowledge base contains answers related to the topic, it retrieves the most relevant historical entries from the agent's memory based on the current topic to construct the generation context. This step is represented as follows:
[0007] in For the retrieval function, perform embedding-based vector retrieval on a locally deployed BERT model. For each agent's memory knowledge base, upon the first input, here... You can start with an empty space or only include a small amount of character information. This refers to the topic keyword information with timestamps extracted during the preprocessing stage. The retrieval function returns the most recent keywords most relevant to the topic. Each historical record. After retrieval, a set of historical records matching the agent's knowledge base is returned, for each historical record. It has structured attributes This includes Persona, Stance, Evidence, and Logic.
[0008] 1.2) Time-weighted approach for retrieved historical information. Historical entries are weighted according to their time elapsed to the present. To reflect that "recent information has a greater impact on current input questions, while older information is gradually forgotten," the weights of historical entries are adjusted accordingly. Each historical entry is assigned a time weight for subsequent vector aggregation and keyword weighted statistics. For any historical entry j, the time weight is calculated as follows:
[0009] in This indicates the agent retrieved in the previous step. The timestamp of the memory recorded in the historical set matched by the knowledge base. This is the time-scale decay constant, which can be tuned according to the specific task, such as short-term topics. Smaller values are acceptable, but long-term personas are possible. Larger values can be taken if "half-life" is used. If '' indicates that the expression is:
[0010] This formula can be used to calculate the historical set with time weights. From the historically related topics retrieved in the previous step, the top-K topics with the highest weights are selected to proceed to the next step of context construction.
[0011] 1.3) Constructing an LLM context based on retrieval history. Time-weighted historical fragments retrieved from the historical knowledge base are organized into context strings suitable for LLM input, so that they can be used in the next step for higher-quality text. This step can be represented as:
[0012] The `format()` function formats structured attributes and specific timestamps into natural language segments (e.g., "[2025-06-01] Persona: Middle-class white-collar worker, Stance: Strongly support, Core argument: Economic reform, Logic: Illustrated with examples"). This step selects the top-K information by time weight and concatenates them into a context segment. Finally, a large language model context is generated:
[0013] in This represents the basic prompt template, such as "You are a..., please answer...". This context construction method will also be used to construct corrective prompts during adaptive optimization.
[0014] 1.4) Invoke LLM generation. Perform final cleaning (denoising, deduplication, and normalization) on the context and input, and invoke the locally deployed LLM to generate the final candidate text. As shown in the following formula:
[0015] The text cleaning operations include removing redundancy, standardizing entities, and truncating excessively long paragraphs. Here, generation strategies (temperature, Top-k, duplication penalty) can be set to control style consistency.
[0016] Step 2) After generating content, attribute mining is performed. Using a locally deployed large language model, the agent's persona, stance, core arguments, and logical attributes are extracted from the comments for each generated content based on preset prompt word templates. 2.1) Based on predefined prompt word templates, the locally deployed large language model is used to perform structured parsing of the text, generating each piece of text. The data is converted into quantifiable, comparable, and computable structured attributes and written into the agent's memory knowledge base for subsequent semantic vector calculation and keyword statistics. The system extracts four long-term evolutionary attributes from the text:
[0017] in This refers to a persona, including their identity, character style, etc. It indicates a stance or orientation, including one's attitude towards an issue (support / opposition / neutrality and the degree thereof). Evidence, or arguments, includes supporting evidence, sources of fact, and cited information. It represents logical characteristics, including the argument structure, reasoning method, and whether there is causal consistency.
[0018] Step 3) Multidimensional consistency assessment: This involves quantitatively comparing the currently generated text with historical memory at the semantic vector space and keyword level, using a historical time decay coefficient, to obtain a comprehensive consistency score that determines whether the text is qualified. ; 3.1) Constructing a semantic vector space based on BERT encoding. To ensure that texts can still be compared under different styles, tones, and expressions, this invention employs a locally deployed BERT model, using the Sentence-Transformers encoding function:
[0019] The three types of attributes of the current text stored in the historical knowledge base are encoded as vectors:
[0020] 3.2) Semantic vector calculation. For historical attributes, time-weighted vector aggregation is performed:
[0021] Obtain the historical time-weighted average vector of each attribute , , This is used for subsequent semantic similarity calculation.
[0022] 3.3) Overall Consistency Score Calculation. The consistency score for each attribute of the currently generated answer is calculated by calculating the cosine similarity between the corresponding attribute keyword vector extracted from the current generated answer and the historical time-weighted average vector of each attribute, and mapping this similarity to the interval [0,1]. The calculation formula is as follows:
[0023] in This indicates that the agent is generating a profile feature vector for the current response. This represents the time-weighted average vector of the current agent's persona attributes in the historical knowledge base, and finally calculates the persona consistency score. A higher score indicates that the current answer is more consistent with the agent's long-term persona, while a lower score indicates a significant change in persona between the current answer and past answers. Similarly, a score for stance consistency can be derived:
[0024] This score can sensitively capture the long-term consistency of an agent's stance; similarly, a score for logical consistency can be obtained.
[0025] Since each agent is initially assigned a specific persona, which includes the logic for answering questions, this score can reveal in practice whether the agent's logic has undergone significant changes. For example, if the agent's initial persona is based on evidence-based argumentation, and it displays a large degree of emotional expression in its latest answers, the score will drop significantly. Logical self-consistency scoring is applicable to "judging logical stability" in fields such as official documents, news interpretation, law, and financial analysis.
[0026] 3.4) Time-weighted keyword F1 score calculation. In this invention, to evaluate whether the newly generated text of the agent maintains consistency with its historical memory at the argument level, a time-weighted keyword F1 score is proposed. The Evidence field E of each record in the historical memory bank is used as the keyword source. First, each keyword in the history... k By applying an exponential decay weight based on the time elapsed since then to reflect the pattern that "recent memories are more important and distant memories gradually fade," we obtain the historical word weight:
[0027] Then, the current text's evidence keyword set is matched against the time-weighted historical keyword pool. Weighted precision and weighted recall are calculated based on weighted true positives (TP). The weighted true positive is defined as the sum of the historical weights of each current keyword hit, as shown in the following formula:
[0028] If the currently used keywords have appeared frequently in history and are mostly recent (with higher weight), then The larger the value, the higher the weighted precision and weighted recall. Based on this, we define weighted precision and weighted recall, with the following formulas:
[0029] The weighted accuracy rate indicates how much of the keywords used in the current text are contributed by historical evidence keywords. The number of keywords in the current evidence; weighted recall indicates how many keywords from historical evidence are reused in the current evidence. This is the time-weighted sum of all keywords in the historical evidence. Finally, the time-weighted keyword F1 score is calculated using the following formula:
[0030] The F1 score reflects the degree to which the current text continues historical evidence at the level of arguments. It has good interpretability and time perception. The larger the value, the higher the consistency between the current evidence and historical memory at the level of arguments; the smaller the value, the more obvious the updates or replacements of the arguments.
[0031] 3.5) Calculate the overall score. Based on the obtained multi-dimensional persona consistency score, stance coherence score, logical self-consistency score, and time-weighted keyword F1 score, the overall score is calculated by combining them according to their importance and weight. When stance contradiction is detected (stance coherence score is close to -1), a penalty is imposed to prevent the generation of an inconsistent answer due to other high scores. Finally, a single value reflecting the consistency between the current generated text and the agent's history is obtained.
[0032] First, calculate the basic overall score. The specific formula is as follows:
[0033] in All values are greater than 0. If a positional conflict is detected, i.e., the positional consistency score is close to -1, a positional reversal metric is set. And apply penalties:
[0034] in It refers to the intensity of punishment, when there is no conflict. When the score is 0, the score remains unchanged; if the score is completely reversed... As the score approaches 1, it will decrease by approximately Proportion.
[0035] Step 4) Adaptive optimization. The generated text is judged to be qualified based on the comprehensive score. If the final comprehensive score is less than the preset minimum threshold, "regeneration + correction" is automatically activated. Repair prompts are automatically constructed and LLM is allowed to regenerate the text until the score is qualified or the maximum number of iterations is reached.
[0036] 4.1) If the overall score is detected to be less than the threshold, a new optimization suggestion template is constructed using the original input, specific low-scoring items, and the center of historical search segments. This step is represented as follows:
[0037] in This is the original LLM prompt template. Memories retrieved from history (such as character settings, stances, and arguments). Which item scored too low? This is the original generated content. After optimizing the prompt words, the large language model is called again to generate rewritten text to ensure consistency with the historical content. This step can be represented as follows:
[0038] The process is then iterated again until the score is met or the maximum number of iterations is reached.
[0039] Step 5) The final result is written into the memory knowledge base of each agent and output. The generated structured memory content, along with the current timestamp, is stored in the independent memory base of each agent to build a long-term traceable record.
[0040] 5.1) Store the generated structured memory content, along with the current timestamp and the final score, into the independent memory bank of each agent. To build a long-term traceable record, the following steps are taken:
[0041] It also records information such as the source of metadata, confidence level, and whether it is a repair result, and saves it in a uniform time format.
[0042] The beneficial effects of this invention are as follows: This invention achieves the continuous maintenance and stable evolution of agents' long-term behavioral styles, stances, and logic by structurally modeling the historical interaction content of a multi-agent large language model and introducing a time decay mechanism and a multi-dimensional consistency quantification evaluation system. Compared with existing technologies, this invention has the following advantages: it achieves long-term, interpretable memory modeling; it introduces time decay weights, which better conform to memory laws; it constructs a quantifiable and interpretable multi-dimensional consistency evaluation index system; it can automatically identify the causes of consistency decline and perform closed-loop optimization; and it enables agents' memory to be continuously enhanced and evolve stably in the long term. Attached Figure Description
[0043] Figure 1 This is a flowchart of the method of the present invention; Figure 2 This is a result evaluation diagram of Embodiment 1 of the present invention. Detailed Implementation
[0044] like Figure 1 As shown, the steps of the large model memory enhancement method based on time-aware consistency feedback and optimization are as follows: Step 1) Data preprocessing: Obtain the historical interaction text generated by each agent in the target scenario, and use the preprocessing module to clean, time-label, and identify topics in the text to generate structured memory entries containing time, topics, etc. 1.1) Input the text to be processed, such as public opinion analysis, current affairs commentary, questions, dialogue context, etc. The multi-agent large language model is invoked for the first time to obtain the response of each agent. The multi-agent large language model can be represented as:
[0045] Each agent has its own independent identity, such as a virtual character, different commentators, a virtual speaker, an AI assistant, or a moderator. It receives text input generated at the current moment from multiple agents. First, a preprocessing module cleans and identifies the topic of the input text. Then, it traverses each agent's knowledge base. If the knowledge base contains answers related to the topic, it retrieves the most relevant historical entries from the agent's memory based on the current topic to construct the generation context. This step is represented as follows:
[0046] in For the retrieval function, perform embedding-based vector retrieval on a locally deployed BERT model. For each agent's memory knowledge base, upon the first input, here... You can start with an empty space or only include a small amount of character information. This refers to the topic keyword information with timestamps extracted during the preprocessing stage. The retrieval function returns the most recent keywords most relevant to the topic. Each historical record. After retrieval, a set of historical records matching the agent's knowledge base is returned, for each historical record. It has structured attributes This includes Persona, Stance, Evidence, and Logic.
[0047] 1.2) Time-weighted approach for retrieved historical information. Historical entries are weighted according to their time elapsed to the present. To reflect that "recent information has a greater impact on current input questions, while older information is gradually forgotten," the weights of historical entries are adjusted accordingly. Each historical entry is assigned a time weight for subsequent vector aggregation and keyword weighted statistics. For any historical entry j, the time weight is calculated as follows:
[0048] in This indicates the agent retrieved in the previous step. The timestamp of the memory recorded in the historical set matched by the knowledge base. This is the time-scale decay constant, which can be tuned according to the specific task, such as short-term topics. Smaller values are acceptable, but long-term personas are possible. Larger values can be taken if "half-life" is used. If '' indicates that the expression is:
[0049] This formula can be used to calculate the historical set with time weights. From the historically related topics retrieved in the previous step, the top-K topics with the highest weights are selected to proceed to the next step of context construction.
[0050] 1.3) Constructing an LLM context based on retrieval history. Time-weighted historical fragments retrieved from the historical knowledge base are organized into context strings suitable for LLM input, so that they can be used in the next step for higher-quality text. This step can be represented as:
[0051] The `format()` function formats structured attributes and specific timestamps into natural language segments (e.g., "[2025-06-01] Persona: Middle-class white-collar worker, Stance: Strongly support, Core argument: Economic reform, Logic: Illustrated with examples"). This step selects the top-K information by time weight and concatenates them into a context segment. Finally, a large language model context is generated:
[0052] in This represents the basic prompt template, such as "You are a..., please answer...". This context construction method will also be used to construct corrective prompts during adaptive optimization.
[0053] 1.4) Invoke LLM generation. Perform final cleaning (denoising, deduplication, and normalization) on the context and input, and invoke the locally deployed LLM to generate the final candidate text. As shown in the following formula:
[0054] The text cleaning operations include removing redundancy, standardizing entities, and truncating excessively long paragraphs. Here, generation strategies (temperature, Top-k, duplication penalty) can be set to control style consistency.
[0055] Step 2) After generating content, attribute mining is performed. Using a locally deployed large language model, the agent's persona, stance, core arguments, and logical attributes are extracted from the comments for each generated content based on preset prompt word templates. 2.1) Based on predefined prompt word templates, the locally deployed large language model is used to perform structured parsing of the text, generating each piece of text. The data is converted into quantifiable, comparable, and computable structured attributes and written into the agent's memory knowledge base for subsequent semantic vector calculation and keyword statistics. The system extracts four long-term evolutionary attributes from the text:
[0056] in This refers to a persona, including their identity, character style, etc. It indicates a stance or orientation, including one's attitude towards an issue (support / opposition / neutrality and the degree thereof). Evidence, or arguments, includes supporting evidence, sources of fact, and cited information. It represents logical characteristics, including the argument structure, reasoning method, and whether there is causal consistency.
[0057] Step 3) Multidimensional consistency assessment: This involves quantitatively comparing the currently generated text with historical memory at the semantic vector space and keyword level, using a historical time decay coefficient, to obtain a comprehensive consistency score that determines whether the text is qualified. ; 3.1) Constructing a semantic vector space based on BERT encoding. To ensure that texts can still be compared under different styles, tones, and expressions, this invention employs a locally deployed BERT model, using the Sentence-Transformers encoding function:
[0058] The three types of attributes of the current text stored in the historical knowledge base are encoded as vectors:
[0059] 3.2) Semantic vector calculation. For historical attributes, time-weighted vector aggregation is performed:
[0060] Obtain the historical time-weighted average vector of each attribute , , This is used for subsequent semantic similarity calculation.
[0061] 3.3) Overall Consistency Score Calculation. The consistency score for each attribute of the currently generated answer is calculated by calculating the cosine similarity between the corresponding attribute keyword vector extracted from the current generated answer and the historical time-weighted average vector of each attribute, and mapping this similarity to the interval [0,1]. The calculation formula is as follows:
[0062] in This indicates that the agent is generating a profile feature vector for the current response. This represents the time-weighted average vector of the current agent's persona attributes in the historical knowledge base, and finally calculates the persona consistency score. A higher score indicates that the current answer is more consistent with the agent's long-term persona, while a lower score indicates a significant change in persona between the current answer and past answers. Similarly, a score for stance consistency can be derived:
[0063] This score can sensitively capture the long-term consistency of an agent's stance; similarly, a score for logical consistency can be obtained.
[0064] Since each agent is initially assigned a specific persona, which includes the logic for answering questions, this score can reveal in practice whether the agent's logic has undergone significant changes. For example, if the agent's initial persona is based on evidence-based argumentation, and it displays a large degree of emotional expression in its latest answers, the score will drop significantly. Logical self-consistency scoring is applicable to "judging logical stability" in fields such as official documents, news interpretation, law, and financial analysis.
[0065] 3.4) Time-weighted keyword F1 score calculation. In this invention, to evaluate whether the newly generated text of the agent maintains consistency with its historical memory at the argument level, a time-weighted keyword F1 score is proposed. The Evidence field E of each record in the historical memory bank is used as the keyword source. First, each keyword in the history... k By applying an exponential decay weight based on the time elapsed since then to reflect the pattern that "recent memories are more important and distant memories gradually fade," we obtain the historical word weight:
[0066] Then, the current text's evidence keyword set is matched against the time-weighted historical keyword pool. Weighted precision and weighted recall are calculated based on weighted true positives (TP). The weighted true positive is defined as the sum of the historical weights of each current keyword hit, as shown in the following formula:
[0067] If the currently used keywords have appeared frequently in history and are mostly recent (with higher weight), then The larger the value, the higher the weighted precision and weighted recall. Based on this, we define weighted precision and weighted recall, with the following formulas:
[0068] The weighted accuracy rate indicates how much of the keywords used in the current text are contributed by historical evidence keywords. The number of keywords in the current evidence; weighted recall indicates how many keywords from historical evidence are reused in the current evidence. This is the time-weighted sum of all keywords in the historical evidence. Finally, the time-weighted keyword F1 score is calculated using the following formula:
[0069] The F1 score reflects the degree to which the current text continues historical evidence at the level of arguments. It has good interpretability and time perception. The larger the value, the higher the consistency between the current evidence and historical memory at the level of arguments; the smaller the value, the more obvious the updates or replacements of the arguments.
[0070] 3.5) Calculate the overall score. Based on the obtained multi-dimensional persona consistency score, stance coherence score, logical self-consistency score, and time-weighted keyword F1 score, the overall score is calculated by combining them according to their importance and weight. When stance contradiction is detected (stance coherence score is close to -1), a penalty is imposed to prevent the generation of an inconsistent answer due to other high scores. Finally, a single value reflecting the consistency between the current generated text and the agent's history is obtained.
[0071] First, calculate the basic overall score. The specific formula is as follows:
[0072] in All values are greater than 0. If a positional conflict is detected, i.e., the positional consistency score is close to -1, a positional reversal metric is set. And apply penalties:
[0073] in It refers to the intensity of punishment, when there is no conflict. When the score is 0, the score remains unchanged; if the score is completely reversed... As the score approaches 1, it will decrease by approximately Proportion.
[0074] Step 4) Adaptive optimization. The generated text is judged to be qualified based on the comprehensive score. If the final comprehensive score is less than the preset minimum threshold, "regeneration + correction" is automatically activated. Repair prompts are automatically constructed and LLM is allowed to regenerate the text until the score is qualified or the maximum number of iterations is reached.
[0075] 4.1) If the overall score is detected to be less than the threshold, a new optimization suggestion template is constructed using the original input, specific low-scoring items, and the center of historical search segments. This step is represented as follows:
[0076] in This is the original LLM prompt template. Memories retrieved from history (such as character settings, stances, and arguments). Which item scored too low? This is the original generated content. After optimizing the prompt words, the large language model is called again to generate rewritten text to ensure consistency with the historical content. This step can be represented as follows:
[0077] The process is then iterated again until the score is met or the maximum number of iterations is reached.
[0078] Step 5) The final result is written into the memory knowledge base of each agent and output. The generated structured memory content, along with the current timestamp, is stored in the independent memory base of each agent to build a long-term traceable record.
[0079] 5.1) Store the generated structured memory content, along with the current timestamp and the final score, into the independent memory bank of each agent. To build a long-term traceable record, the following steps are taken:
[0080] It also records information such as the source of metadata, confidence level, and whether it is a repair result, and saves it in a uniform time format.
[0081] Example 1
[0082] Example: Input a news report, and have a multi-agent language model act as a real person with different social backgrounds, outputting their own comments and opinions on the news report. In this example, one agent is selected to evaluate, optimize, and record its historical consistency and memory capabilities.
[0083] Step 1: The user inputs a command and initiates multi-agent generation; the system automatically generates a command with a timestamp.
[0084] Step 2: Call the attribute mining module to extract key information from the instruction text for subsequent retrieval.
[0085] Step 3: Traverse and query the agent's memory database to find the most semantically relevant historical memories, calculate the time decay weight, and find the top-K most relevant prompt words to be added to the large language model to generate answers.
[0086] Step 4: Combining the prompts from Step 3, the large language model is invoked to generate the agent's initial statement. The attribute mining module is then invoked to extract personality traits, stances, logic, and core argument keywords from the instruction text based on the preset prompts, forming structured entries.
[0087] Step 5: After vectorizing the extracted keywords, iterate through the agent's memory database, calculate the consistency score of each dimension combined with time decay and the keyword F1 score, and calculate the final score based on the formula.
[0088] Step Six: Determine whether the score has reached the preset threshold and the maximum number of iterations. If not, the system automatically determines the main reason for the score reduction, generates new enhancement prompts based on the content in the memory bank and the reasons, and generates the answer again.
[0089] Step 7: Add the keywords of the final generated answer and the scoring record to the agent's knowledge base.
[0090] like Figure 2 As shown, the experiment was conducted in ten rounds. The overall average score of the agent using the memory enhancement method of this invention was significantly higher than the score of the agent that directly called the large language model to generate the answer.
Claims
1. A large model memory enhancement method based on time-aware consistency feedback and optimization, characterized in that, The steps are as follows: Step 1) Data preprocessing: Obtain the historical interaction text generated by each agent in the target scenario, and use the preprocessing module to clean, time-label, and identify topics to generate structured memory entries. Step 2) After generating content, attribute mining is performed. Using a locally deployed large language model, the agent's persona, stance, core arguments, and logical attributes are extracted from the comments for each generated content based on preset prompt word templates. Step 3) Multidimensional consistency assessment: Combine the historical time decay coefficient with the semantic vector space and keyword level to quantitatively compare the current generated text with historical memory, and obtain a comprehensive score that can determine whether it is qualified. Step 4) Adaptive optimization: Based on the comprehensive score obtained in Step 3), determine whether the generated text is qualified. If the final comprehensive score is less than the preset minimum threshold, then automatically start "regeneration + correction", automatically construct repair prompt words and let LLM regenerate the text until the score is qualified or the maximum number of iterations is reached. Step 5) The final result is written into the memory knowledge base of each agent and output. The generated structured memory content, together with the current timestamp, is stored in the independent memory base of each agent to build a long-term traceable record.
2. The large model memory enhancement method based on time-aware consistency feedback and optimization according to claim 1, characterized in that, In step 1), the specific method is as follows: 1.1) Input the text to be processed, and call the multi-agent large language model for the first time to obtain the response of each agent. The multi-agent large language model is represented as follows: Each agent has its own independent identity and receives text input generated at the current moment from multiple agents. First, a preprocessing module cleans and identifies the topic of the input text. Then, it iterates through each agent's knowledge base. If the knowledge base contains answers related to the topic, it retrieves the most relevant historical entries from the agent's memory based on the current topic to construct the generation context, represented as follows: in For the retrieval function, perform embedding-based vector retrieval on a locally deployed BERT model. For each agent, a knowledge base is created upon the first input. Initially, it should be empty or contain only a small amount of character information. This refers to the topic keyword information with timestamps extracted during the preprocessing stage. The retrieval function returns the most recent keywords most relevant to the topic. Each historical record; after retrieval, the system returns a set of historical records matched by the agent's knowledge base, and for each historical record... It has structured attributes This includes Persona, Stance, Evidence, and Logic; 1.2) Time-weighted approach for retrieved historical information: Assign weights to historical entries based on their time elapsed since then, and then apply these weights to the historical entries. Each historical entry is assigned a time weight for subsequent vector aggregation and keyword weighted statistics. The time weight for any historical entry j is calculated as follows: in This indicates the agent retrieved in the previous step. The timestamp of the memory recorded in the historical set matched by the knowledge base. The decay constant is set on a time scale and adjusted according to the specific task; short-term topics. Take the smaller value, long-term persona Take the larger value and use the "half-life" If '' indicates that the expression is: Using this formula, the historical set with time weight is calculated. From the historical related topics retrieved in the knowledge base in the previous step, the top-K topics with the highest weights are selected to enter the next step of context construction. 1.3) Constructing an LLM context based on retrieval history: The time-weighted historical fragments retrieved from the historical knowledge base are organized into a context string suitable for LLM input. This step is represented as: The `format()` function formats structured attributes and specific timestamps into natural language segments; this step selects the top-K information based on time weight and concatenates them into a context segment. Finally, a large language model context is generated: in This represents the basic suggestion template, and the context construction method also constructs and modifies suggestion words during adaptive optimization. 1.4) Call LLM to generate; Perform final cleaning on the context and input, and call the locally deployed LLM to generate the final candidate text. As shown in the following formula: The text cleaning operations include removing redundancy, standardizing entities, and truncating excessively long paragraphs, while controlling style consistency by setting generation strategies.
3. The large model memory enhancement method based on time-aware consistency feedback and optimization according to claim 1, characterized in that, In step 2), the specific method is as follows: 2.1) Based on predefined prompt word templates, the locally deployed large language model is used to perform structured parsing of the text, generating each piece of text. The data is converted into structured attributes and written into the agent's memory knowledge base for subsequent semantic vector calculation and keyword statistics. The system extracts four long-term evolutionary attributes from the text: in Persona, representing a persona or character trait. Stance indicates his stance and orientation. Indicates evidence. Represents the logical characteristic.
4. The large model memory enhancement method based on time-aware consistency feedback and optimization according to claim 1, characterized in that, In step 3), the specific method is as follows: 3.1) Based on BERT encoding, a semantic vector space is constructed, and a locally deployed BERT model is used. The Sentence-Transformers encoding function is as follows: The three types of attributes of the current text stored in the historical knowledge base are encoded as vectors: 3.2) Semantic vector calculation: For historical attributes, perform vector weighted aggregation using time weights: Obtain the historical time-weighted average vector of each attribute , , This is used for subsequent semantic similarity calculation; 3.3) Overall Consistency Score Calculation: The consistency score of each attribute in the current generated answer is calculated by calculating the cosine similarity between the corresponding attribute keyword vector extracted from the current generated answer and the historical time-weighted average vector of each attribute, and mapping it to the interval [0,1]. The calculation formula is as follows: in This indicates that the agent is generating a profile feature vector for the current response. This represents the time-weighted average vector of the current agent's persona attributes in the historical knowledge base, and finally calculates the persona consistency score. The higher the score, the more consistent the current answer is with the agent's long-term persona; the lower the score, the more significant the change in persona between the current answer and past answers. This score determines the consistency of stance. This score captures the long-term consistency of the agent's stance, a logical self-consistency score: Since each agent is assigned a specific persona at the beginning, which includes the logic for answering questions, this score can be used in practice to recognize whether the agent's logic has changed significantly. 3.4) Time-Weighted Keyword F1 Score Calculation: To evaluate whether the newly generated text by the agent maintains consistency with historical memory at the argument level, a time-weighted keyword F1 score is proposed. The Evidence field E of each record in the historical memory bank is used as the keyword source. First, each keyword in the history... k By applying an exponential decay weight based on the time elapsed since then to reflect the pattern that "recent memories are more important and distant memories gradually fade," we obtain the historical word weight: Then, the current text's evidence keyword set is matched against the time-weighted historical keyword pool. Weighted precision and weighted recall are calculated based on weighted true positives (TP). The weighted true positive is defined as the sum of the historical hit weights for each current keyword, as shown in the following formula: If the currently used keyword has appeared frequently in history and mostly recently, then The larger the value, the higher the weighted precision and weighted recall are defined, with the following formulas: The weighted accuracy rate indicates how much of the keywords used in the current text are contributed by historical evidence keywords. This represents the number of keywords in the current Evidence; Weighted recall rate indicates how many keywords from historical evidence are reused currently. The time-weighted sum of all keywords in the historical evidence is used to calculate the time-weighted keyword F1 score. The specific formula is as follows: The F1 score reflects the degree to which the current text continues the historical evidence at the level of argumentation. The higher the value, the higher the consistency between the current evidence and historical memory at the level of argumentation. The smaller the value, the more significant the update or replacement of the argument; 3.5) Calculate the comprehensive score: Based on the obtained multi-dimensional persona setting consistency score, stance coherence score, logical self-consistency score and time-weighted keyword F1 score, the comprehensive score is calculated by combining them according to their importance and weight. When stance contradiction is detected, a penalty is imposed to prevent the generation of an inconsistent answer due to other high scores. Finally, a single value reflecting the consistency between the current generated text and the agent's history is obtained. First, calculate the basic overall score. The specific formula is as follows: in All values are greater than 0. If a positional conflict is detected, i.e., the positional consistency score is close to -1, a positional reversal metric is set. And apply penalties: in It refers to the intensity of punishment, when there is no conflict. When the score is 0, the score remains unchanged; if the score is completely reversed... As the score approaches 1, it will decrease by approximately Proportion.
5. The large model memory enhancement method based on time-aware consistency feedback and optimization according to claim 1, characterized in that, In step 4), the specific method is as follows: 4.1) If the overall score is detected to be less than the threshold, a new optimization suggestion template is constructed using the original input, specific low-scoring items, and the center of historical search segments, as follows: in This is the original LLM prompt template. Memories retrieved from history Which item scored too low? The original generated content is used as the basis for optimizing the prompts. The rewritten text is then generated again using a large language model to ensure consistency with the historical version. This is represented as follows: The process is then iterated again until the score is met or the maximum number of iterations is reached.
6. The large model memory enhancement method based on time-aware consistency feedback and optimization according to claim 1, characterized in that, In step 5), the specific method is as follows: 5.1) Store the generated structured memory content, along with the current timestamp and the final score, into the independent memory bank of each agent. To build a long-term traceable record, the following steps are taken: It also records information such as the source of metadata, confidence level, and whether it is a repair result, and saves it in a uniform time format.
Citation Information
Cited By
Play generation method and related device
CN121901382A
A multi-layer context-based incremental personality memory modeling and application method
CN122222034A