An agent hierarchical memory extraction and context compression method, device and medium

CN123014000APending Publication Date: 2026-10-30LOVE AVATAR TECH (BEIJING) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611221509.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-12
Publication Date
2026-10-30

AI Technical Summary

Technical Problem

[0004]本发明的目的在于提供一种智能体分层记忆提取与上下文压缩方法、设备及介质,通过分层判定评分、压缩质量指标约束和多维索引召回的组合机制,解决长周期智能体任务中历史上下文持续增长、重要事实易丢失和召回内容不稳定的问题

Benefits of technology

(1)通过工作记忆、任务记忆和归档记忆的三层分级管理,并根据时效性、任务依赖、事实稳定性、访问频率、证据完整性和敏感等级六维评分自动判定记忆层级,使长周期任务中的历史信息按照生命周期和任务依赖关系进行组织。不同层级的记忆分别服务于不同的时间窗口和任务阶段,工作记忆保证即时执行的上下文连续性,任务记忆保证阶段性任务的连续推进,归档记忆保证长期知识的复用,从而避免了所有历史内容混合存储导致的召回噪声和上下文膨胀问题;

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123014000A_ABST
    Figure CN123014000A_ABST
Patent Text Reader

Abstract

The application discloses an agent layered memory extraction and context compression method and system, the method comprising: collecting original memory fragments generated by an agent in a long-period task and obtaining structured information such as entities, events, action items and time anchors through semantic analysis; calculating layered scores according to time effectiveness, task dependency, fact stability, access frequency, evidence integrity and sensitivity level, dividing the memory fragments into three levels of working memory, task memory and archival memory; generating compressed memory according to the compression rules corresponding to each level and calculating compression rate, fact retention rate and action item coverage rate and other indicators; establishing a five-dimensional index of semantics, entities, task stages, time and action items; when a new task is executed, layered recall and assembly of input context are performed according to the current intention and context budget. Through the mechanism of layered score determination, compression quality index constraint and multi-dimensional index recall, the application improves the context continuity and recall accuracy of long-period agent tasks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence and intelligent agent task execution technology, specifically to a method, device and medium for hierarchical memory extraction and context compression of intelligent agents. Background Technology

[0002] As large language model-driven agents are increasingly used in enterprise operations, these agents are no longer limited to single-turn question-and-answer processing. Instead, they need to continuously execute long-cycle tasks spanning days, weeks, and even months, involving customers, projects, work orders, contracts, and approvals. Existing agent context processing methods mainly include directly retaining conversation history, compressing historical text based on summaries, recalling historical fragments based on vector retrieval, and maintaining task status based on database records. These methods generally meet the requirements for short-cycle tasks, but they have the following drawbacks for long-cycle tasks: They lack memory hierarchical rules for long-cycle tasks; many solutions store all historical dialogues uniformly as text or vectors without distinguishing between immediate working memory, phased task memory, and long-term archived memory, resulting in the inability to differentiate retrieval based on task phase and timeliness; they lack quantifiable compression metrics; traditional summarization methods do not specify evaluation metrics such as compression rate, fact retention rate, and action item coverage, making it difficult to verify compressed content; they lack an index structure bound to task state; simple semantic vector retrieval easily recalls semantically similar content that does not match the task phase; and they lack a context budget control mechanism; the model's context space is limited, and disordered splicing of historical content increases token cost and reduces the hit rate of key facts.

[0003] Therefore, designing a method for hierarchical management, index-based compression, and precise recall of historical information for long-cycle tasks is an urgent technical problem to be solved. Summary of the Invention

[0004] The purpose of this invention is to provide a method, device, and medium for hierarchical memory extraction and context compression for intelligent agents. By combining hierarchical judgment scoring, compression quality index constraints, and multidimensional index recall, it solves the problems of continuous growth of historical context, easy loss of important facts, and unstable recalled content in long-cycle intelligent agent tasks.

[0005] In a first aspect, embodiments of this application provide a method for hierarchical memory retrieval and context compression of an intelligent agent, executed by a processor, comprising the following steps: Collect raw memory fragments generated by the intelligent agent during the execution of long-cycle tasks. The raw memory fragments include session messages, tool call results, external system write-back results, and task state change records. Semantic parsing is performed on the original memory fragments to obtain entities, events, action items, constraints, time anchors, sources of evidence, and confidence levels. Based on the timeliness, task dependence, factual stability, access frequency, evidence integrity, and sensitivity level of the original memory fragment, a stratification score is calculated, and the original memory fragment is divided into multiple memory levels according to the stratification score. The memory levels include working memory, task memory, and archived memory. Compressed memories are generated according to the compression rules corresponding to the memory level, and the compression quality index of the compressed memories is calculated; the compression quality index includes compression ratio, fact retention rate, and action item coverage rate; Establish semantic indexes, entity indexes, task stage indexes, time indexes, and action item indexes for the compressed memory; When the agent executes a new task step, it recalls candidate compressed memories from different memory levels based on the semantic index, the entity index and the task stage index according to the current task intent, the current task stage and the preset context budget, and then assembles them into the input context after sorting and pruning according to the context budget.

[0006] Preferably, the stratified score is calculated using the following formula: (1); in, For timeliness scoring, Rate task dependency. Score for fact stability. Rate the frequency of visits. Scoring based on the completeness of evidence. This is a sensitive penalty item; , , , , and These are the weighting coefficients for timeliness score, task dependency score, fact stability score, access frequency score, evidence completeness score, and sensitive penalty item, respectively.

[0007] Preferably, the compression rules include: The working memory is lightly compressed, preserving the most recent context, unfinished steps, and temporary variables; The task memory is compressed in a structured manner to generate a five-element summary containing the goal, facts, actions, risks, and evidence; The archived memories are compressed using stable facts to generate structured records containing entities, conclusions, sources, scope of application, and update times.

[0008] Preferably, when the fact retention rate or the action item coverage rate is lower than a preset threshold, a repair operation is performed on the compressed memory to re-insert the missing key facts or action items into the compressed memory.

[0009] Preferably, the recall of candidate compressed memories includes: calculating a recall score for candidate compressed memories based on semantic similarity, entity matching degree, task stage matching degree, action item relevance and time decay coefficient, and selecting candidate compressed memories that do not exceed the context budget in descending order of the recall score.

[0010] Preferably, the assembly into an input context further includes: performing consistency checks and sensitive information filtering on the selected candidate compressed memories, and assembling them in the order of working memory priority, task memory supplementation, and archived memory.

[0011] Preferably, the method further includes: Based on the execution results after the agent executes the input context, human feedback, and tool return results, the memory level corresponding to each original memory fragment is updated, and the association strength between each index item in the semantic index, entity index, task stage index, time index, and action item index and the corresponding compressed memory is updated.

[0012] In a second aspect, embodiments of this application provide an electronic device, including a processor and a memory, wherein the memory stores a computer program, and the processor executes the computer program to implement the method described in the first aspect.

[0013] Thirdly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, characterized in that the computer program, when executed by a processor, implements the method described in the first aspect.

[0014] Fourthly, embodiments of this application provide a computer program product, characterized in that it includes a computer program, which, when executed by a processor, implements the method described in the first aspect.

[0015] Compared with the solutions of the prior art, the present invention has at least the following beneficial technical effects: (1) Through a three-tiered hierarchical management system of working memory, task memory, and archived memory, and by automatically determining the memory level based on a six-dimensional score of timeliness, task dependence, factual stability, access frequency, evidence integrity, and sensitivity level, historical information in long-term tasks is organized according to its life cycle and task dependence. Different levels of memory serve different time windows and task stages. Working memory ensures the continuity of context for immediate execution, task memory ensures the continuous progress of phased tasks, and archived memory ensures the reuse of long-term knowledge, thereby avoiding recall noise and context bloat caused by the mixed storage of all historical content. (2) The compression results are constrained by quantifiable indicators such as compression ratio, fact retention rate, and action item coverage rate. When the fact retention rate or action item coverage rate is lower than a preset threshold, a repair operation is automatically triggered to fill in the missing key information, thus upgrading the compression process from unverifiable ordinary summary generation to an evaluable and repairable context compression mechanism. Furthermore, the compression quality can be evaluated in multiple dimensions through auxiliary indicators such as entity consistency, timeline integrity, and redundancy. (3) Through the five-dimensional index structure of semantic index, entity index, task stage index, time index and action item index, the agent can simultaneously recall candidates from multiple dimensions when executing new task steps. The semantic dimension ensures content relevance, the entity dimension ensures object accuracy, the task stage dimension ensures temporal matching, the time dimension ensures timeliness, and the action item dimension ensures task continuity. This fundamentally solves the problem that single vector retrieval is prone to recalling semantically similar but stage-mismatched content. (4) By using context budget control and recall scoring and ranking pruning mechanisms, the system maintains high-value information density in the model input within a limited context window. The system assembles the context in the order of working memory priority, task memory supplementation, and archive memory, ensuring that the most urgent information enters the window first, effectively reducing token costs and minimizing interference from low-value historical content. At the same time, the system continuously updates the memory hierarchy and index association strength through execution feedback, forming a continuous optimization loop for memory management, which is suitable for enterprise scenarios that require long-term state maintenance, such as sales follow-up, project management, and long-term customer service. Attached Figure Description

[0016] Exemplary embodiments of the present invention can be more fully understood by referring to the accompanying drawings. The drawings are provided to further illustrate the embodiments of this application and form part of the specification. They are used together with the embodiments of this application to explain the present invention and do not constitute a limitation thereof. In the drawings, the same reference numerals generally represent the same components or steps.

[0017] Figure 1 A flowchart illustrating a method for hierarchical memory retrieval and context compression for an agent, provided in an embodiment of this application; Figure 2 A schematic diagram of the structure of an agent hierarchical memory retrieval and context compression system provided for an exemplary embodiment of this application; Figure 3 A schematic diagram of the structure of an agent hierarchical memory retrieval and context compression system provided as another exemplary embodiment of this application; Figure 4 A schematic diagram of an electronic device provided for an exemplary embodiment of this application; Figure 5This is a schematic diagram of a computer-readable medium provided for an exemplary embodiment of this application. Detailed Implementation

[0018] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.

[0019] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0020] Furthermore, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other. It should be noted that the specific data objects, field names, and business relationships involved in the following embodiments are all represented by anonymized abstractions, which are intended to demonstrate the feasibility of the technical solution and do not constitute a limitation on real enterprise data.

[0021] Please refer to Figure 1 , Figure 1 This is a flowchart of a method for hierarchical memory retrieval and context compression of an intelligent agent, as described in some embodiments of this application. The method in this embodiment is executed by a processor and includes the following steps: S110, Collect the original memory fragments generated by the intelligent agent during the execution of long-cycle tasks. The original memory fragments include session messages, tool call results, external system write-back results, and task state change records. Specifically, the processor continuously collects raw data from various sources generated by the agent during the execution of long-cycle tasks, including: conversational messages between the agent and the user (such as user questions, agent responses, and confirmation commands), execution results of external tools called by the agent (such as database query results, API return data, and RPA script execution logs), write-back results from external systems (such as customer status updates from the CRM system, work order progress updates from the work order system, and approval results from the approval system), and records of changes in task status (such as task phase progress, milestone achievement, and change of responsible person). All collected raw data is stored as raw memory fragments in a unified data structure. Each fragment contains a content field, source identifier, timestamp, associated task ID, and associated entity set. Bar memory fragments can come from user input, agent responses, tool calls, system write-backs, meeting minutes, email records, CRM records, work order records, or project management systems.

[0022] S120, perform semantic parsing on the original memory fragment to obtain entities, events, action items, constraints, time anchors, sources of evidence, and confidence levels; Specifically, the processor performs semantic parsing on each original memory segment, extracting structured information in the following dimensions: Entities: Business objects identified from text, such as customer name, project number, contract number, work order ID, responsible person, etc. Events: The types of business events described in the text, such as price updates, contract signings, risk reporting, and meetings. Action items: Items to be done or next steps that are clearly stated in the text, such as "Quotes need to be confirmed by Friday" or "Schedule a review for next Monday"; Constraints: Restrictions on time, amount, scope, etc., as specified in the text; Time anchor: The specific point in time when an event occurs or an action ends; Source of evidence: The source of the information, such as "from the CRM system" or "from the meeting minutes of March 15th"; Confidence level: The score for the credibility of this information. Information confirmed by humans has a high confidence level, while information inferred by the agent has a low confidence level.

[0023] In a preferred embodiment, semantic parsing can be achieved by named entity recognition and relation extraction based on a large language model, or by fine-tuning a pre-trained model such as BERT. In specific business domains (such as sales and customer service), higher entity recognition accuracy can be obtained.

[0024] S130, calculate a stratification score based on the timeliness, task dependence, factual stability, access frequency, evidence integrity and sensitivity level of the original memory fragment, and divide the original memory fragment into multiple memory levels based on the stratification score, the memory levels including working memory, task memory and archived memory; Specifically, a stratified score is calculated for each original memory fragment, using the following formula: (1); in, For timeliness scoring, the time difference between the time anchor point of the memory segment and the current time is calculated, using an exponential decay rule: the closer to the current time, the higher the score; the farther away, the score decreases exponentially with the time difference. The specific calculation method is as follows: a baseline effective time window is set (e.g., 7 days). The timeliness score for the time anchor point within the baseline window is initially 1; after exceeding the baseline window, the score decreases day by day according to a preset decay coefficient; finally, the calculation result is normalized to the range of 0 to 1. in, Task dependency scoring is calculated based on the number of times the memory is referenced by the currently active task steps and its importance coefficient. In this embodiment, the task node importance coefficient is pre-configured according to the decomposition rules of long-cycle tasks. Specifically, nodes corresponding to core milestones, key decision points, hard constraints, and core actions have higher importance coefficients, while nodes corresponding to daily communication, process discussions, and temporary intermediate states have lower importance coefficients. In a preferred embodiment, the task dependency score is calculated as follows: for all task nodes associated with the memory fragment, calculate (the cumulative value of the reference count × the corresponding node importance coefficient), and finally normalize it to the range of 0 to 1. in, To determine the fact stability score, for verifiable objective fact items (such as customer budget figures, project delivery times, product configuration parameters, contract terms, etc.) obtained from semantic parsing of original memory fragments, the number of times each fact item is confirmed and modified / repudiated in subsequent memory fragments from different sources is counted. A stability ratio is calculated based on (confirmation frequency / (confirmation frequency + modification frequency)). If the same fact is confirmed by multiple independent sources (CRM systems, formal meeting minutes, approval records, etc.), an additional credibility weight is added. The more confirmations, the fewer modifications, and the more authoritative the source, the higher the fact stability score, with values ​​normalized to the range of 0-1. in, The access frequency score is calculated based on the historical recall frequency of the memory fragment within a preset statistical period, combined with the time decay weight of the most recent recall. Specifically, the calculation method is as follows: The total number of times the memory fragment was retrieved in the last N task executions is counted; higher time weights are assigned to recall records closer to the current time, and lower weights are assigned to older recall records. The weighted sum is then normalized to the range of 0-1. The more frequently the memory fragment is recalled and the more recent the recall time, the higher the access frequency score. in, The completeness score for evidence is calculated based on the number of evidence sources supporting the memory fragment and the credibility level of each source. The specific rules are as follows: evidence sources are pre-classified into multiple levels of credibility, with automatically synchronized business data (such as CRM, work orders, and approval records) having the highest credibility, followed by manually entered records, and content generated autonomously by the intelligent agent having the lowest credibility. Each evidence source is assigned a corresponding credibility weight, and the cumulative value of all weights is calculated and normalized to the range of 0-1. The more evidence sources and the higher their credibility, the higher the completeness score. in, This is a sensitive penalty item. The deduction value is determined based on the sensitivity level of the remembered content. It belongs to the deduction item in the tiered scoring and is used to reduce the recall priority of highly sensitive information. Specifically, the sensitivity level is pre-classified into four levels according to the enterprise's data security specifications: ordinary, internal, sensitive, and highly sensitive. Public communication content and general business information are classified as ordinary; internal work records and non-core business data are classified as internal; customer contact information, non-public contract amounts, and business sensitive data are classified as sensitive; and customer privacy information, core technical parameters, and confidential business information are classified as highly sensitive. The system automatically matches sensitive content in the remembered fragments through a preset sensitive entity thesaurus and data classification tags to determine the corresponding sensitivity level. The higher the level, the greater the penalty deduction value. For example, the value range of this item is 0~0.3. The higher the sensitivity level, the greater the value. Finally, the corresponding penalty value is deducted from the total score.

[0025] in, , , , , and These are the weighting coefficients for timeliness score, task dependency score, factual stability score, access frequency score, evidence completeness score, and sensitivity penalty item. Specifically, each weighting coefficient is determined by the task type and business domain configuration. For example, for sales follow-up tasks, timeliness and task dependency have higher weights, and in this case, they can be set... =0.1, For project debriefing tasks, the stability of facts and the completeness of evidence have higher weights; in this case, you can set... , Specifically, the sum of the six weight coefficients is 1, and the values ​​range from 0 to 1. The specific values ​​are configured according to the business scenario.

[0026] In this embodiment, memory fragments are divided into three levels based on hierarchical scoring: when a memory fragment has a high timeliness score and low factual stability, it is classified as working memory, which is used to store reasoning execution information within the current round or a short time window (such as the most recent hour), emphasizing immediacy; incomplete steps and temporary variables are also stored here. When the factual stability score and evidence completeness score of a memory fragment both reach preset thresholds, and the reuse value score is high, it is classified as archived memory. The reuse value score is calculated based on the number of times the memory fragment is recalled across tasks, the coverage of applicable business scenarios, and the universality of the facts: it counts the number of times the memory has been successfully recalled and produced positive execution effects in different historical tasks and business scenarios. The wider the coverage, the more times it is reused across tasks, and the stronger the universality of the factual conclusions, the higher the reuse value score, with values ​​normalized to the range of 0-1. Archived memory is used to store stable facts, final conclusions, and complete chains of evidence that have been verified multiple times, retaining only content with long-term retention and cross-task reuse value, avoiding the occupation of archived storage resources by one-time process information. In this embodiment, the reuse value score is an independent admission criterion for archived memories and is not included in the calculation of the tiered total score; only when the tiered total score reaches the archiving threshold and the reuse value score is ≥ the preset value, it is included in the archived memory.

[0027] In this embodiment, there is a dynamic flow relationship between the three memory levels. Working memory and task memory are not fixed. When a fact in working memory is confirmed multiple times by subsequent executions, its fact stability score increases, and it may be reclassified as task memory (i.e., "sinking") in the next round of stratified scoring. When a phased task in task memory is completed and the conclusion is stable, it may be reclassified as archived memory (i.e., "sinking"). When the agent executes the relevant task again, stable facts in archived memory can still be retrieved and utilized through the recall mechanism. When the total stratified score is between the working memory threshold and the archived memory threshold, and the task dependency score reaches a preset value, it is classified as task memory.

[0028] S140, Generate compressed memory according to the compression rules corresponding to the memory level, and calculate the compression quality index of the compressed memory; the compression quality index includes compression ratio, fact retention rate and action item coverage rate; Specifically, in step S130, the original memory fragments have been divided into one of three levels: working memory, task memory, or archived memory. In this step, three compression rules are designed for the three memory levels. That is, the processor automatically selects the compression rule corresponding to the memory level to which each original memory fragment is assigned and performs the compression operation. There is no "OR" selection relationship between the levels.

[0029] Specifically, the three compression rules are as follows: (1) When the original memory fragments are classified as working memory, a lightweight compression rule is adopted: only the complete context of the most recent N rounds of dialogue is deduplicated and formatted, the list of action steps that have not yet been completed and temporary calculation variables are explicitly extracted and retained, and the rest of the historical content is not compressed for the time being. The compression rate is usually controlled at 70% to 85%. (2) When the original memory fragments are divided into task memories, a structured compression rule is adopted: the processor reorganizes the memory content into a five-element summary structure according to a preset template, which includes the goal (the core goal of the current task stage), facts (confirmed key business facts), actions (actions that have not yet been completed and their responsible persons and deadlines), risks (identified risk items and their impact levels) and evidence (source citation paths that support the information in the above fields). The compression rate is usually 60% to 80%. (3) When the original memory fragment is classified as archived memory, the stable fact compression rule is adopted: extract and retain only the entity name, the final conclusion that has been confirmed multiple times, the permanent reference path of the original evidence in the system, the scope of the business scenario to which the conclusion applies, and the last update timestamp, and discard procedural discussions and intermediate state information.

[0030] The above correspondence is a fixed mapping: working memory uses lightweight compression, task memory uses structured compression, and archived memory uses stable fact compression.

[0031] After the compression is completed, three compression quality indicators are calculated: Compression ratio = Length of compressed text / Length of uncompressed text; Fact retention rate = Number of facts retained after compression / Number of facts in the original memory fragment; Action coverage rate = Number of actions retained after compression / Number of actions in the original memory fragment. When the fact retention rate is lower than a preset threshold (e.g., 80%) or the action coverage rate is lower than a preset threshold (e.g., 90%), the processor performs a repair operation on the compressed memory—re-extracting the missing key facts or actions from the original memory fragment and adding them to the compressed memory. As an alternative implementation, entity consistency (entities with the same name before and after compression pointing to the same business object) and redundancy (the proportion of duplicate content in the compressed information) can also be added as auxiliary quality indicators.

[0032] It should be noted that the introduction of the aforementioned compression quality metrics transforms the compression process from traditional black-box summary generation to evaluable and verifiable metric-based compression. By setting different thresholds, the system can flexibly control compression quality for different business scenarios (such as sales follow-up requiring action item coverage ≥95%, and project review requiring fact retention ≥90%), which is something traditional summarization methods cannot achieve.

[0033] S150, establish semantic index, entity index, task stage index, time index and action item index for the compressed memory; Specifically, the following five types of indexes are created for each compressed memory: Semantic indexing: The compressed text content is converted into high-dimensional semantic vectors through a pre-trained text embedding model (such as text-embedding-ada-002 or bge-large-zh) and stored in a vector database (such as Faiss or Milvus); Entity Index: Extract all entity names involved in the compressed memory and build an inverted index table with entity names as keys and the compressed memory ID list as values; Task Stage Index: Records the task stage identifiers associated with the compressed memory (such as "requirements confirmation stage", "quotation stage", "contract signing stage"), and establishes a mapping from stage to compressed memory ID; Time Index: A B-tree index is built by sorting the timestamps of the time anchor points, supporting fast retrieval by time range; Action Item Index: Retrieves all pending action items contained in the compressed memory and builds an inverted index with the action status (incomplete / complete / blocked) as the key, which is used to quickly recall memories related to the next action.

[0034] It's important to note that the five-dimensional index design described above addresses the issue of single semantic vector retrieval easily retrieving semantically similar content that doesn't match the task stage. For example, in a sales follow-up scenario, "Customer A's budget issue" might have been discussed in both the requirements confirmation and contract signing stages, but the focus and conclusions of the discussions in these two stages are completely different. Relying solely on semantic vector retrieval might simultaneously recall content from both stages, leading to contextual confusion; however, through the joint retrieval of the task stage index and the entity index, the system can accurately recall the memory content corresponding to the current stage.

[0035] S160, when the agent executes a new task step, based on the current task intent, the current task stage and the preset context budget, candidate compressed memories are recalled from different memory levels based on the semantic index, the entity index and the task stage index, and then assembled into an input context after being sorted, pruned and arranged according to the context budget.

[0036] Specifically, when an agent enters a new task step, the processor first parses the current task request, extracting the current task intent (such as customer follow-up, risk assessment, contract review), associated entities, and the current task stage. Then, it performs candidate recall from the established index based on the following dimensions: retrieving compressed memories with a semantic similarity to the current intent higher than a threshold (e.g., 0.7) through the semantic index; retrieving compressed memories involving the same entities through the entity index; and retrieving compressed memories of stages that match or are adjacent to the current stage through the task stage index.

[0037] The recall score is calculated using the compressed memory of the recalled candidates, and the calculation formula is as follows: (2); in, For recall scoring, Cosine similarity of semantic vectors The degree of entity matching (1 for a complete match, 0.5 for a partial match, and 0 for no match). The matching degree for each stage (1 for the current stage, 0.5 for adjacent stages, and 0 for irrelevant stages). To determine the relevance to the current action, The time freshness is based on the time decay coefficient (the newer the better). After sorting the recall scores from high to low, candidate compressed memories are selected in order from high to low scores according to the preset context budget (e.g., 8000 tokens). , , , and These are the weighting coefficients.

[0038] When assembling the input context, the processor performs consistency checks (checking whether there are contradictory facts in compressed memories from different sources, and if there are contradictions, prioritizing the source with higher confidence) and sensitive information filtering (removing information that exceeds the current user's permissions) on the selected candidate compressed memories. Then, it assembles the context in the order of working memory, task memory, and archive memory. That is, it prioritizes putting the contents of working memory into the context window, supplements it with task memory when working memory is insufficient, and supplements it with archive memory when it is still insufficient, until the context budget limit is reached.

[0039] In a preferred embodiment, the above method further includes the following steps: S170: Based on the execution result after the agent executes the input context, the human feedback and the tool return result, update the memory level corresponding to each original memory fragment, and update the association strength between each index item in the semantic index, the entity index, the task stage index, the time index and the action item index and the corresponding compressed memory.

[0040] Specifically, after the agent executes the task based on the input context assembled in step S160, it collects the task execution results, user feedback (such as likes, content corrections, and result rejections), and tool call return results as feedback data to iteratively update the memory system. The update consists of two parts: dynamic adjustment of the memory hierarchy and iterative optimization of the index association strength. (1) Dynamic update of memory hierarchy For memory fragments at different levels, the values ​​of their stratification scoring dimensions are adjusted based on the feedback from this execution, and the stratification transition is automatically completed in the next round of S130 stratification determination: ① For working memory: If the memory fragment is referenced by the model in this execution, and the corresponding content is confirmed to be accurate by the user or the results returned by the tool are consistent, then its fact stability score will be improved. Each positive confirmation will add a correction amount of 0.1, with a maximum of 1.0. When the fact stability score is raised to the task memory admission threshold, it will automatically be downgraded to task memory in the next round of stratified scoring. ② For task memory: If the to-do action item corresponding to the memory has been completed and confirmed by the system / manual during this execution, the action item is marked as completed, and its factual stability score and reuse value score are improved simultaneously; when both scores reach the archival memory admission threshold, it will automatically be downgraded to archival memory in the next round of tiered scoring. ③ For archived memories: If the conclusion of the memory is proven to be outdated or in conflict with the latest facts by the results of this execution, its reuse value score will be reduced by 0.2 for each negative verification; when the reuse value score is lower than 0.3, it will be marked as pending update and its ranking priority will be reduced during subsequent recall, and it will no longer be used as a priority archived conclusion.

[0041] (2) Iterative optimization of index association strength Specifically, the association strength is used to characterize the degree of matching and relevance between the corresponding index item and the compressed memory, and directly participates in the recall score calculation in step S160. The higher the association strength, the higher the sorting priority of the compressed memory being recalled through the corresponding index.

[0042] If a compressed memory is successfully recalled during this execution and produces a positive execution effect (such as the task execution result meeting expectations, user approval, or tool call success rate meeting the target), the association strength of the corresponding index item in the semantic index, entity index, task stage index, time index, and action item index of the compressed memory will be increased simultaneously. If a compressed memory is recalled but is not related to the current task (such as not being referenced by the model, being corrected by the user, or not matching the current task stage), the association strength of each index item will be decreased simultaneously.

[0043] In a preferred embodiment, the association strength adopts a multiplicative update rule: the association strength is multiplied by 1.05 for positive feedback and by 0.9 for negative feedback; the association strength values ​​of all indices are constrained to the range of 0.1 to 1.0, and are clamped by boundary values ​​when they exceed the range.

[0044] It should be noted that the feedback update mechanism of S170 enables the method in this embodiment to form a complete memory management closed loop. It not only completes memory stratification and compression based on the initial scoring rules, but also continuously iterates the correction values ​​of each stratified scoring dimension and the correlation strength of the multi-dimensional index based on the actual task execution results. After multiple rounds of long-cycle task execution optimization, the system's value judgment of different types of memory at the corresponding task stages will become increasingly accurate, and the hit rate of memory retrieval and the overall success rate of task execution will continue to improve.

[0045] To further illustrate the above method, this embodiment will be explained in conjunction with three specific application scenarios, as follows: In the sales follow-up agent scenario, the system continuously collects meeting minutes, chat logs, CRM updates, quotation changes, and next follow-up actions between sales personnel and customers. Customer-related issues from the most recent communication and the current quotation version are entered into working memory; customer budget, procurement cycle, key decision-makers, competitor comparisons, and unfinished actions are entered into task memory; signed contracts, historical transaction records, and long-term customer preferences are entered into archive memory. When a salesperson asks, "What should I focus on in tomorrow's meeting with this customer?", the system uses the S160 recall mechanism and sorting assembly to prioritize recalling unfinished actions and current stage constraints from task memory, supplementing long-term preferences from archive memory, and compressing this into a meeting preparation context.

[0046] In the project management agent scenario, the system collects project meeting minutes, milestone plans, risk registration forms, work order statuses, and responsible person feedback. Points of contention and ad-hoc tasks from the current meeting are entered into working memory; project goals, phase schedules, bottlenecks, and responsible persons are entered into task memory; acceptance conclusions, debriefing experiences, and standard delivery templates are entered into archive memory. When the project manager asks, "What is the biggest risk to the project this week?", the system retrieves relevant task memories by task phase and risk entity index and generates a compressed context based on historical archive experience.

[0047] In long-term customer service agent scenarios, the system uses the user's recent issues and current ticket status as working memory; the user's historical requests, processing paths, and pending confirmations as task memory; and the final solution and recurrence patterns as archived memory. When a user inquires about a similar issue again, the system quickly recalls the root cause and solution from the archived memory, while also considering the current ticket status to avoid repeated inquiries.

[0048] It should be noted that the three application scenarios described above all demonstrate the core advantage of this method: through hierarchical memory management, it prioritizes the retention of information most relevant to the current task within a limited context window, avoiding token waste and omission of key information caused by the disordered filling of all historical data. Furthermore, the criteria for determining the memory hierarchy and the weight configuration in the three scenarios can be adjusted according to the specific business characteristics of each scenario.

[0049] Please refer to Figure 2 , Figure 2 This is a schematic diagram of the architecture of an agent-level hierarchical memory retrieval and context compression system 20 according to some embodiments of this application. System 20 includes seven modules, which correspond one-to-one with the aforementioned steps S110 to S170: Memory acquisition module 210 is used to acquire original memory fragments from multiple sources; Memory parsing module 220 is used for semantic parsing to extract structured information; The stratification determination module 230 is used to calculate the stratification score and divide the memory strata. Compression generation module 240 is used to perform compression according to hierarchical rules and calculate quality indicators; Index management module 250 is used to create a five-dimensional index; The recall orchestration module 260 is used for recall score sorting and context assembly.

[0050] In a preferred embodiment, see Figure 3 This illustration shows a schematic diagram of the architecture of an intelligent agent hierarchical memory retrieval and context compression system 20 provided by some embodiments of this application. Specifically, 20 also includes an effect verification module 270, which corresponds to step S170 of the method in the above embodiment, and is used to update the memory hierarchy and index association strength based on execution feedback. The modules are interconnected via an internal bus and are uniformly scheduled by the processor.

[0051] It should be noted that the above system module division is only a logical functional division. In actual implementation, the functions of multiple modules can be integrated into the same processing unit, or the functions of one module can be split into multiple sub-modules.

[0052] Please refer to Figure 4 This illustrates a schematic diagram of an electronic device provided by some embodiments of this application. For example... Figure 4 As shown, the electronic device 40 includes: a processor 400, a memory 401, a bus 402, and a communication interface 403. The processor 400, the communication interface 403, and the memory 401 are connected via the bus 402. The memory 401 stores a computer program that can run on the processor 400. When the processor 400 runs the computer program, it executes the method described above in this application.

[0053] The memory 401 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 403 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network.

[0054] Bus 402 can be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. The memory 401 is used to store programs. After receiving an execution instruction, the processor 400 executes the program. The methods disclosed in any of the foregoing embodiments of this application can be applied to the processor 400, or implemented by the processor 400.

[0055] The processor 400 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of the processor 400 or by instructions in software form. The processor 400 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules may reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in memory 401. The processor 400 reads the information in memory 401 and, in conjunction with its hardware, completes the steps of the above method.

[0056] The electronic device and the method provided in this application are based on the same inventive concept and have the same beneficial effects as the methods used, operated, or implemented therein. The electronic device may be a server, a data operation platform host, or a network device with computing capabilities.

[0057] This application also provides a computer-readable medium corresponding to the method provided in the foregoing embodiments. Please refer to... Figure 5 The computer-readable storage medium shown is an optical disc 50 on which a computer program (i.e., a program product) is stored, which, when run by a processor, performs the aforementioned method.

[0058] The computer-readable storage medium may include, but is not limited to, various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks. In a specific application scenario, the computer-readable storage medium may be built into a server or data operation platform host as part of the firmware; or it may be a standalone software product.

[0059] The computer-readable storage medium provided in the above embodiments of this application and the method provided in the embodiments of this application are based on the same inventive concept and have the same beneficial effects as the methods adopted, run or implemented by the applications stored therein.

[0060] This embodiment also provides a computer program product, which includes a computer program. When executed by a processor, the computer program implements the methods described in any of the above embodiments.

[0061] The computer program product may include any combination of one or more program modules.

[0062] It should be noted that the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

[0063] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0064] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and there may be other division methods in actual implementation. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the coupling or direct coupling or communication connection shown or discussed may be through some communication interface; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0065] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0066] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0067] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application, and they should all be covered within the scope of the claims and specification of this application.

Claims

1. A method for hierarchical memory retrieval and context compression for intelligent agents, executed by a processor, characterized in that, Includes the following steps: Collect raw memory fragments generated by the intelligent agent during the execution of long-cycle tasks. The raw memory fragments include session messages, tool call results, external system write-back results, and task state change records. Semantic parsing is performed on the original memory fragments to obtain entities, events, action items, constraints, time anchors, sources of evidence, and confidence levels. Based on the timeliness, task dependence, factual stability, access frequency, evidence integrity, and sensitivity level of the original memory fragment, a stratification score is calculated, and the original memory fragment is divided into multiple memory levels according to the stratification score. The memory levels include working memory, task memory, and archived memory. Compressed memories are generated according to the compression rules corresponding to the memory level, and the compression quality index of the compressed memories is calculated; the compression quality index includes compression ratio, fact retention rate, and action item coverage rate; Establish semantic indexes, entity indexes, task stage indexes, time indexes, and action item indexes for the compressed memory; When the agent executes a new task step, it recalls candidate compressed memories from different memory levels based on the semantic index, the entity index and the task stage index according to the current task intent, the current task stage and the preset context budget, and then assembles them into the input context after sorting and pruning according to the context budget.

2. The method according to claim 1, characterized in that, The stratified score is calculated using the following formula: (1); in, For timeliness scoring, Rate task dependency. Score for fact stability. Rate the frequency of visits. Scoring based on the completeness of evidence. This is a sensitive penalty item; , , , , and These are the weighting coefficients for timeliness score, task dependency score, fact stability score, access frequency score, evidence completeness score, and sensitive penalty item, respectively.

3. The method according to claim 1, characterized in that, The compression rules include: The working memory is lightly compressed, preserving the most recent context, unfinished steps, and temporary variables; The task memory is compressed in a structured manner to generate a five-element summary containing the goal, facts, actions, risks, and evidence; The archived memories are compressed using stable facts to generate structured records containing entities, conclusions, sources, scope of application, and update times.

4. The method according to claim 1, characterized in that, When the fact retention rate or the action item coverage rate is lower than a preset threshold, a repair operation is performed on the compressed memory to re-insert the missing key facts or action items into the compressed memory.

5. The method according to claim 1, characterized in that, The recall of candidate compressed memories includes: calculating a recall score for candidate compressed memories based on semantic similarity, entity matching degree, task stage matching degree, action item relevance, and time decay coefficient, and selecting candidate compressed memories that do not exceed the context budget in descending order of the recall score.

6. The method according to claim 5, characterized in that, The assembly of the input context also includes: performing consistency checks and sensitive information filtering on the selected candidate compressed memories, and assembling them in the order of working memory priority, task memory supplementation, and archived memory.

7. The method according to claim 1, characterized in that, The method further includes: Based on the execution results after the agent executes the input context, human feedback, and tool return results, the memory level corresponding to each original memory fragment is updated, and the association strength between each index item in the semantic index, entity index, task stage index, time index, and action item index and the corresponding compressed memory is updated.

8. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a computer program, and the processor executing the computer program to implement the method of any one of claims 1 to 7.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 7.

10. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1 to 7.