Memory management method for LLM intelligent agent, electronic device and storage medium

MemPrism solves the multifaceted problem of information management in LLM agent memory systems by autonomously segmenting interactive information into structured working slots, generating multiple types of long-term memories and performing SVD orthogonal direction decomposition. It achieves efficient information retrieval and knowledge abstraction, and improves the robustness and interpretability of the agent.

CN122113988APending Publication Date: 2026-05-29AISPEECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
AISPEECH CO LTD
Filing Date
2026-03-02
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Existing LLM intelligent agent memory systems struggle to effectively distinguish and manage multifaceted information, resulting in noisy retrieval results, poor reusability, severe cross-session interference, and difficulty in forming evolvable abstract knowledge.

Method used

The retrospective multifaceted memory management method (MemPrism) is adopted. By autonomously segmenting interactive information into structured working slots, three types of long-term memory are generated: semantic, contextual, and process. Similarity threshold gating and DenStream clustering mechanism are used, combined with SVD orthogonal direction decomposition for retrieval, to achieve lightweight updates and isolation of interference.

Benefits of technology

It improves retrieval coverage in multi-objective, multi-step reasoning scenarios, reduces interference from long-term memory, forms evolvable abstract knowledge, enhances the robustness and interpretability of intelligent agents in open environments, and supports continuous learning and self-improvement.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122113988A_ABST
    Figure CN122113988A_ABST
Patent Text Reader

Abstract

The embodiment of the application discloses a memory management method for an LLM agent, an electronic device and a storage medium, wherein the memory management method for the LLM agent comprises the following steps: thinking / acting / observation generated by interaction is automatically divided and absorbed into structured work slots by the LLM in a review window; each work slot is filtered and routed according to a preset factor, and three types of long-term memory, namely semantic memory, episodic memory and procedural memory, are generated respectively; similarity threshold gating is adopted for updating or inserting long-term memory writing; and different retrieval strategies are adopted for the work slots and the long-term memory in the memory access stage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of large language model technology, and particularly relates to memory management methods, electronic devices and storage media for LLM agents. Background Technology

[0002] In related technologies, LLM (Large Language Model) contains various memory systems. These include: agent-based memory systems using external memory banks and vector retrieval, such as Mem0 / Mem0-Graph, which write interaction information into a vector database or graph structure and retrieve it using similarity when needed; prospective memory systems, such as A-Mem, which determine when to store or remind based on pre-planned / triggered conditions; RAG-style memory access using single semantic vector nearest neighbor retrieval, which encodes historical records into a single vector space and performs Top-k retrieval, commonly seen in multi-turn dialogues and multi-step tool invocation scenarios; and training-driven memory systems, such as those requiring additional training to learn memory write / retrieval strategies (e.g., Mem-α).

[0003] The aforementioned technologies typically revolve around the core idea of ​​"external memory + retrieval enhancement": historical dialogues, actions, and observations are encoded and written into a unified memory. Then, when the current query or context arrives, semantic similarity (or combined with BM25 / keyword matching) is used to select the top-k records from the memory and concatenate them into prompts to help the model answer questions or make decisions. Among these, look-ahead methods often require defining subtask boundaries or setting trigger conditions at the start of the task; training-driven methods learn the write / read strategies, but introduce additional training costs and data dependencies. Summary of the Invention

[0004] This invention provides a memory management method, electronic device, and storage medium for LLM agents, which at least solve one of the above-mentioned technical problems.

[0005] In a first aspect, embodiments of the present invention provide a memory management method for LLM agents, comprising: placing the thoughts / actions / observations generated by interactions within a retrospective window, which are then automatically segmented and absorbed by the LLM into structured work slots; filtering and routing each work slot according to preset factors to generate three types of long-term memories: semantic memory, contextual memory, and process memory; updating or inserting long-term memories using similarity threshold gating; and adopting different retrieval strategies for the work slots and the long-term memories during the memory access phase.

[0006] Secondly, embodiments of the present invention also provide a computer program product, the computer program product including a computer program stored on a non-volatile computer-readable storage medium, the computer program including program instructions, which, when executed by a computer, cause the computer to perform the steps of the memory management method for LLM intelligent agents according to any embodiment of the present invention.

[0007] Thirdly, embodiments of the present invention also provide an electronic device comprising: at least one processor, and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the steps of the method described in the first aspect.

[0008] Fourthly, embodiments of the present invention also provide a storage medium storing a computer program thereon, characterized in that the computer program, when executed by a processor, implements the steps of the method described in the first aspect.

[0009] The method in this application can improve retrieval coverage in multi-objective, multi-step reasoning scenarios: through SVD orthogonal direction decomposition and budget allocation, retrieval results are no longer concentrated on a single dominant direction, and can simultaneously cover multiple aspects of information such as objectives, constraints, and assumptions. It can also reduce interference from long-term memory: long-term memory introduces similarity thresholds and isolated retrieval, reducing the entry of cross-session / cross-task irrelevant content into the current context. Furthermore, it can form evolvable abstract knowledge: through DenStream online clustering and semantic consistency judgment, stable repetitive experiences are condensed into semantic memory, and abstraction is withdrawn when distribution changes, balancing stability and adaptability. Moreover, the solution in this application is lightweight and easy to implement: similarity-gated upsert avoids unnecessary expansion, and periodic clearing of working slots controls scale. Attached Figure Description

[0010] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0011] Figure 1 This is a schematic diagram of a solution architecture provided in an embodiment of the present invention; Figure 2 A flowchart illustrating a memory management method for LLM agents provided in an embodiment of the present invention; Figure 3 This is a comparison diagram of MemPrism provided in an embodiment of the present invention with other related works; Figure 4 An overview of the MemPrism system provided in an embodiment of the present invention; Figure 5 The test results of GPT-4o-mini and Qwen3-4B provided in an embodiment of the present invention; Figure 6 This is a progressive representation in a question-answering task provided by an embodiment of the present invention; Figure 7 This refers to the category accuracy under the LongMemEval S setting provided in an embodiment of the present invention. Figure 8 Ablation study on the maximum number of slots for quality assurance tasks provided in an embodiment of the present invention; Figure 9 A study on slot retrieval ablation based on singular value decomposition (SVD) provided as an embodiment of the present invention; Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0012] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0013] The inventors found that the above-mentioned related technologies have one or more of the following defects: (1) Mixed information types: The execution of real intelligent agents will generate multifaceted information such as factual knowledge, lessons learned, and reusable processes, but existing systems often store them as homogeneous records, which are difficult to distinguish and manage in a targeted manner, resulting in high noise and poor reusability of retrieval results. (2) "One-way collapse" of retrieval: Typical similarity Top-k retrieval will be dominated by a dominant semantic direction, resulting in redundant / homogeneous memory entries, which cannot cover multiple aspects required for the query (goals, constraints, assumptions, etc.). (3) Difficulty in pre-defining forward-looking boundaries: It is often impossible to accurately divide sub-tasks or context blocks in advance during execution. In open dynamic environments, it is even more difficult to specify boundaries in advance, resulting in the failure of storage / reminder strategies or high costs. (4) Cross-session interference: When long-term memory is reused across tasks / sessions, it is easy to bring irrelevant or outdated content into the current context, causing interference or even performance degradation. (5) Difficulty in forming evolvable abstract knowledge: Many methods only accumulate original fragments and lack online clustering / abstraction mechanisms to condense multiple similar experiences into stable semantic knowledge.

[0014] The inventors found that the root cause of the above defects mainly comes from the following design in the related technologies: (1) "Unified mode + single retrieval strategy": Heterogeneous information is represented by the same field / vector and retrieved with a single Top-k similarity, which is naturally difficult to distinguish semantic / contextual / process information, and the retrieval is easily dominated by a single semantic direction. (2) "Look-forward pre-segmentation hypothesis": It is assumed that the information structure is known in advance (sub-tasks can be pre-divided or conditions can be set), which does not match the actual dynamic and open interaction. (3) Lack of similarity gating update and anti-interference mechanism: Long-term memory is directly added to the context, and no threshold or isolation is set for cross-session similarity, resulting in the introduction of irrelevant memory. (4) Lack of online abstraction and stability judgment: There is no judgment on whether "multiple repeated experiences are sufficiently consistent / stable", making it difficult to form generalizable semantic memory from contextual memory.

[0015] When addressing these shortcomings, industry professionals commonly employ the following improvement paths: (1) Increase retrieval diversity: for example, redundancy removal via MMR, cluster sampling after clustering, multi-query rewriting of queries, hierarchical retrieval, etc., to alleviate Top-k homogeneity. (2) More complex memory selection / writing rules: use manual rules or additional models to determine "whether it is worth storing" and "where to store it", and even introduce reinforcement learning / supervised learning to train reading and writing strategies. (3) Stronger context compression / summarization: use summarization models to compress history into short texts to reduce window limitations.

[0016] However, these methods either still rely on patching within a single schema / retrieval paradigm or depend on retraining / reengineering, and typically do not design "retrospective segmentation encoding + multi-faceted routing storage + online abstraction + directional decomposition retrieval + long-term memory isolation gating" as a consistent closed loop. The reason this solution is not immediately obvious is that it maps the cognitively inspired encoding-consolidation-integration cycle to a five-module system that can be engineered, and introduces the following key elements: (i) retrospective autonomous segmentation working slots; (ii) multi-metric routing and similarity gating upsert; (iii) DenStream clustering for streaming data and using "semantic consistency" to determine stable abstractions; (iv) SVD (Singular Value Decomposition, used to decompose the working slot embedding matrix into orthogonal semantic directions) orthogonal directional decomposition for working slot retrieval to ensure multi-faceted coverage; and (v) setting thresholds and isolating retrieval for long-term memory to suppress cross-session interference. This combination spans multiple stages of "representation / storage / update / abstraction / retrieval / context assembly," and is not a single-point modification.

[0017] This application proposes a retrospective multifaceted memory management method (MemPrism) for LLM agents. Its core approach is as follows: (1) The thoughts / actions / observations generated by the interaction are automatically segmented and absorbed by the LLM into structured "working slots" within a retrospective window to balance granularity and latency; (2) Each working slot is filtered and routed based on factors such as novelty, utility, stability, and evidence to generate three types of long-term memories (LTM, Long-Term Memory, which is retained across sessions / tasks) in semantics, context, and process; (3) Upsert (a hybrid word of Update + Insert) with similarity threshold gating is used for writing to long-term memories: similarity results in updates, and dissimilarity results in insertions; (4) Contextual memories are clustered online (DenStream) to identify stable micro-clusters (PMC, Potential Micro-Cluster, which represents a stable pattern formed by multiple contextual memory reinforcements). Abstract into semantic memory, and withdraw the abstraction when consistency decreases to ensure adaptability to distribution changes; (5) adopt different retrieval strategies for working slots and long-term memory in the memory access stage: working slot retrieval uses SVD to decompose the query into multiple orthogonal semantic directions to improve multi-faceted coverage; long-term memory retrieval adopts threshold filtering and isolation mechanism to reduce cross-session interference; finally, the history is formed according to the task strategy and the context is generated.

[0018] Please refer to Figure 1 The diagram illustrates the architecture of a retrospective multifaceted memory consolidation and integration framework (MemPrism) of this application.

[0019] like Figure 1 As shown, (1) Interaction generation: The system generates a series of Thoughts, Actions and Observations during task execution and maintains a history that can be reviewed, providing a context for the generation of subsequent work slots.

[0020] (2) Retrospective autonomous segmentation coding: After accumulating a certain number of steps i, LLM is called to retrospectively summarize the "most recent i-step interaction" and automatically identify information boundaries in combination with history to output multiple structured slots.

[0021] (3) Multi-index filtering and routing: For each slot, evaluate indicators such as novelty, utility, stability, and evidence to determine whether to write it into long-term memory and whether it should be routed to semantic, contextual, or procedural memory types.

[0022] (4) Long-term memory Upsert: Performs similarity-gated writing on selected memory entries: compares with the nearest neighbor of the same type of memory bank. If the similarity is greater than the threshold, it is updated and merged; otherwise, a new entry is inserted to reduce duplication and drift.

[0023] (5) Online clustering and abstraction of episodic memories: Episodic memories are clustered using streaming. DenStream continuously maintains OMC (Outlier Micro-Cluster, representing the initial semantic buds / outlier clusters formed by a small number of episodic memories) and PMC. Semantic Consistency (SC) is calculated for PMC to determine whether PMC is stable and triggers abstraction. When SC is greater than a threshold, more generalized semantic memories are abstracted from the cluster; when subsequent data causes SC to decrease, the abstraction results are withdrawn to ensure adaptability.

[0024] (6) Memory integration and retrieval: SVD is performed on the slot embedding matrix to decompose the query into multiple orthogonal semantic directions, and the retrieval budget is allocated according to the direction strength to achieve multi-faceted coverage. Top-k retrieval is performed on long-term memory and threshold filtering is performed using the relationship between similarity and threshold. At the same time, an isolation mechanism is used to maintain the independence of multi-source contexts and reduce cross-session interference.

[0025] (7) History Formation and Context Generation: Organizing the retrieved slots and long-term memory entries into h t It is then concatenated with the current task input to form the final context, input into LLM to obtain the next output, and then returns to the interaction to form a closed loop.

[0026] In implementing this application, the inventors also adopted the following alternative solutions: Alternative Solution A: Single memory bank + diverse retrieval (MMR / cluster sampling / multi-query rewriting). This solution still stores all memories in a single vector library, improving Top-k diversity through MMR or cluster sampling after clustering. The advantages are its simplicity and minimal modification to existing RAG / vector libraries. The disadvantages are the lack of "multi-faceted routing and schema differentiation," resulting in semantic / context / process mixing; the diversity strategy cannot guarantee the retrieval of the correct type of information according to task function, and cross-session interference still exists. Alternative Solution B: Proactive subtask planning + block storage. This solution pre-divides subtasks / context blocks at the start of a task or during each planning phase, storing and retrieving each block separately. The advantages are more controllable retrieval when the task structure is stable and boundaries are clear. The disadvantages are the difficulty in accurately pre-dividing boundaries in open dynamic environments; planning errors can lead to systematic deviations in subsequent storage / retrieval; and poor adaptability to long-term interactions.

[0027] In the process of obtaining the final solution of this application, the inventors also adopted the following beta versions: (1) Only working slots + no long-term memory: Retain retrospective working slot segmentation and multi-faceted slot retrieval, but do not consolidate information into long-term memory (not retained across sessions). The implementation is the lightest, with the least cross-session interference, and is suitable as a short task enhancement. However, it lacks long-term accumulation and reuse, and it is difficult to form increasingly stronger stable knowledge as the task progresses. (2) Complete long-term memory and abstraction, but slot retrieval does not use SVD directional decomposition: Retain multi-faceted routing, upsert and DenStream abstraction, but slot retrieval degenerates into ordinary similarity Top-k. The system has the ability to accumulate and abstract in the long term. However, when facing multi-target / multi-constraint queries, retrieval is prone to "one-way collapse", insufficient coverage, and performance degradation. (3) No online abstraction from contextual memory to semantic memory: Retain the three types of storage and upsert, but do not abstract contextual memory clusters into semantic knowledge. The implementation is simpler and avoids the additional complexity brought by clustering. Semantic knowledge is difficult to automatically condense from repeated experiences, resulting in a more redundant memory and reduced reusability.

[0028] The direct effects of this application are: (1) Improved retrieval coverage in multi-objective and multi-step reasoning scenarios: Through SVD orthogonal direction decomposition and budget allocation, the retrieval results are no longer concentrated in a single dominant direction, and can simultaneously cover multiple aspects of information such as objectives, constraints, and assumptions. (2) Reduced interference from long-term memory: Long-term memory introduces similarity thresholds and isolated retrieval, reducing cross-session / cross-task irrelevant content from entering the current context. (3) Formation of evolvable abstract knowledge: Through DenStream online clustering and semantic consistency discrimination, stable repeated experiences are condensed into semantic memory, and abstraction is withdrawn when the distribution changes, taking into account both stability and adaptability. (4) Lightweight updates and easy implementation: Similarity gating upsert avoids unnecessary expansion, and the periodic clearing of work slots controls the scale. Chain reaction and deeper effects: (1) Support for continuous learning and self-improvement over a longer period of time: The system can continuously accumulate, abstract, and correct knowledge with interaction, showing the evolutionary characteristic of "getting better and better". (2) Improve the robustness and interpretability of agents in open environments: Structured slots and categorical long-term memory make the evidence chain of "why do it this way" clearer, facilitating auditing and debugging. (3) Provide infrastructure for multi-agent / multi-task migration: Multifaceted schemas and isolated access facilitate the migration of reusable processes and facts between different tasks, while reducing the risk of negative migration. (4) Have engineering value for productization: Without relying on large-scale additional training, the effect can be improved through modular components, which is suitable for various applications such as retrieval-enhanced dialogue, tool invocation, and long-term task planning.

[0029] Please refer to Figure 2The diagram illustrates a flowchart of a memory management method for LLM agents provided in an embodiment of this application.

[0030] like Figure 2 As shown, in step 201, the thoughts / actions / observations generated by the interaction are automatically segmented and absorbed into structured work slots by LLM within the retrospective window; In step 202, each work slot is filtered and routed according to preset factors to generate three types of long-term memory: semantic memory, contextual memory, and process memory. In step 203, long-term memory writes are updated or inserted using similarity threshold gating; In step 204, different retrieval strategies are adopted for the working slot and the long-term memory during the memory access phase.

[0031] In this embodiment, the Thought → Action → Observation loop is the basic thinking unit of the LLM agent in each round of decision-making. Thought represents reasoning and planning: the LLM analyzes the current state and decides what to do next. Action represents execution and invocation: performing specific actions, usually invoking external tools (such as searching or calculating) or outputting the final answer. Observation represents feedback and perception: obtaining the results after the action (such as data returned by an API, the status of tool execution). These three form a closed loop, which the agent continuously cycles until the task is completed. The retrospective window refers to the agent's ability to review its action trajectory (window) after completing a task or stage, reflecting on what was done well and what mistakes were made, and summarizing these experiences for long-term memory to optimize future behavior.

[0032] This application embodiment automatically segments and absorbs thoughts / actions / observations in the retrospective window into structured work slots through LLM. Then, based on preset factors, the work slots are filtered and routed to generate three types of long-term memories: semantic memory, contextual memory, and process memory. Subsequently, upsert with similarity threshold gating is applied to the long-term memories. During the memory access phase, different retrieval strategies are adopted for the work slots and the long-term memories. This can support continuous learning and self-improvement over a longer period, improve the robustness and interpretability of the agent in an open environment, provide infrastructure for multi-agent / multi-task migration, and has engineering value for productization.

[0033] In some optional embodiments, the method further includes: online clustering of the contextual memories, abstracting stable micro-clusters into semantic memories, and withdrawing the abstraction when consistency decreases to ensure adaptability to distribution changes. Further optionally, the online clustering of the contextual memories, abstracting stable micro-clusters into semantic memories, and withdrawing the abstraction when consistency decreases includes: performing streaming clustering on the contextual memories, continuously maintaining abnormal micro-clusters and potential micro-clusters; calculating semantic consistency for the potential micro-clusters, abstracting semantic memories from the clusters when semantic consistency exceeds a threshold; and withdrawing the abstraction results when subsequent data causes a decrease in semantic consistency to ensure adaptability. Specifically, DenStream online clustering and semantic consistency discrimination can be used to condense stable repetitive experiences into semantic memories, and withdraw the abstraction when the distribution changes, balancing stability and adaptability. Thus, the system possesses long-term accumulation and abstraction capabilities, semantic knowledge can be automatically condensed from repetitive experiences, the memory bank is more refined, and reusability is improved.

[0034] In some optional embodiments, the different retrieval strategies applied to the working slots and the long-term memory during the memory access phase include: using singular value decomposition (SVD) to decompose the query into multiple orthogonal semantic directions for working slot retrieval to improve multi-faceted coverage; employing threshold filtering and isolation mechanisms for long-term memory retrieval to reduce cross-session interference; and forming a history and generating context according to task strategies. Specifically, SVD is performed on the slot embedding matrix to decompose the query into multiple orthogonal semantic directions, and retrieval budgets are allocated according to directional strength to achieve multi-faceted coverage; Top-k retrieval is performed on the long-term memory, and threshold filtering is performed using the relationship between similarity and threshold, while isolation mechanisms are used to maintain the independence of multi-source contexts and reduce cross-session interference; preferably, the retrieved slots and long-term memory entries are organized into h t It is then concatenated with the current task input to form the final context, input into LLM to obtain the next output, and then returns to the interaction to form a closed loop.

[0035] In some optional embodiments, the step of automatically segmenting and absorbing the thoughts / actions / observations generated by the interaction into structured work slots within a retrospective window by the LLM includes: storing the thoughts / actions / observations generated by the interaction within the retrospective window; and, after accumulating a certain number of steps i, calling the LLM to perform a retrospective summary of the most recent i-step interactions, and automatically identifying information boundaries by combining the history, outputting multiple structured work slots. Thus, the system generates continuous Thoughts, Actions, and Observations during task execution, maintains a history available for retrospection, provides context for the generation of subsequent work slots, and then the LLM performs a retrospective summary, outputting multiple structured work slots, which can balance granularity and latency.

[0036] In some optional embodiments, the preset factors include novelty, utility, stability, and evidence. The filtering and routing of each work slot based on these preset factors to generate three types of long-term memory—semantic memory, contextual memory, and process memory—includes: evaluating the preset factors for each work slot, deciding whether to write it into long-term memory, and determining the type of long-term memory to which it is routed. These long-term memory types include semantic memory, contextual memory, and process memory. Thus, through long-term accumulation and reuse, increasingly stable knowledge is formed as the task progresses.

[0037] In a further optional embodiment, the similarity threshold gating for updating or inserting long-term memory entries includes: performing similarity-gated writing on selected memory entries, including comparing with nearest neighbors in the same type of memory bank; if the similarity is greater than the threshold, the entries are updated and merged; otherwise, new entries are inserted. This enables lightweight updates that are easy to implement, similarity-gated upserts prevent unnecessary expansion, and periodic clearing of working slots controls their size.

[0038] Large Language Model (LLM) agents have demonstrated outstanding performance across numerous domains. However, due to their limited context windows and stateless nature, they underperform in tasks requiring long-term interactions. Existing agent memory systems are often designed for homogeneous task growth and tend to emphasize only a single type of information, even though in actual execution, agents generate multiple information signals across various facets, such as factual knowledge, temporally semantic experience, and reusable operational processes. The inventors propose MemPrism, a retrospective, multifaceted memory consolidation and integration framework. MemPrism encodes interaction trajectories as structured work slots and integrates them into various long-term memory forms, such as semantic memory, episodic memory, and procedural memory, through lightweight memory writing and online abstraction mechanisms. Furthermore, it effectively integrates these memories back into the working context through an information-dimensional retrieval mechanism. Specifically, MemPrism achieves the following: (i) autonomously dividing recent interaction history into task-oriented work slots; (ii) abstracting stable semantic knowledge based on a similarity-gated writing strategy and streaming contextual memory clustering; and (iii) decomposing slot retrieval into orthogonal semantic directions, thereby surpassing traditional single-vector nearest neighbor-based retrieval methods in terms of coverage. Experiments show that MemPrism significantly outperforms existing methods in multiple benchmarks and diverse tasks, achieving competitive overall performance.

[0039] In recent years, large language model (LLM) agents have demonstrated superior performance across a wide range of domains and tasks. However, due to the stateless nature of these agents, they are typically limited by a finite context window, making them suitable only for relatively short dialogues or tasks. Although recent research has significantly extended the physical context length of large models, their effective context length has still shortened considerably. Therefore, for tasks requiring long-term interactions, maintaining interaction states and effectively managing interaction history has become an important research topic.

[0040] One feasible solution is to design memory systems for large-scale agent models, offloading most of the information in the context window to external storage, thereby maintaining the simplicity and order of the context. However, existing research on agent memory is often limited to homogeneous tasks and interaction scenarios, such as multi-hop question answering, multi-step function calls, or multi-turn dialogues. Furthermore, even in a single task, an agent may generate multifaceted information during execution, including domain knowledge (semantic memory), experiential insights (epistemological memory), or reusable combinations of behaviors (procedural memory). Previous research has often focused on only one aspect of this, without comprehensively considering all aspects.

[0041] To address these limitations, the inventors proposed MemPrism, a retrospective, multifaceted memory consolidation and integration framework for large-scale language model agents. Inspired by research in cognitive neuroscience, this invention divides the memory management cycle into three stages: 1. Memory Encoding: Working slot management integrates information generated during the context generation stage in a retrospective manner through autonomous partitioning and absorption. 2. Memory Consolidation: Working memory (i.e., working slots) is filtered and routed to generate three types of long-term memory. Among them, episodic memory is clustered using DenStream (Density-based Stream Clustering: a density-based streaming clustering algorithm used for online clustering of episodic memory) and transferred to semantic memory through a memory abstraction mechanism. In the memory update design, inspired by predictive coding theory, the agent decides to update existing memories or directly insert new memories into the memory bank based on a similarity threshold with nearest neighbor memory entries of the same type, thereby ensuring the flexibility and simplicity of the memory bank. 3. Memory Integration: Working memory and long-term memory are preprocessed and then integrated into the context using different retrieval methods. Specifically, MemPrism implements slot retrieval based on the semantic direction decomposition method of singular value decomposition, thus taking into account multi-faceted information; at the same time, it introduces a long-term memory isolation retrieval mechanism to maintain the multi-source characteristics of the context. Experiments on three types of tasks show that MemPrism significantly outperforms other agent memory systems under various task and experimental settings, proving that it can effectively utilize the multi-faceted characteristics of task information.

[0042] Figure 3This section compares MemPrism with other related works, focusing on two main directions: a. Retrospective vs. Prospective. When an agent performs a task, the boundaries of subtasks are often not accurately defined in advance. In other words, prospective methods assume that the information structure is known a priori. However, in reality, the environment faced by the agent is often dynamic, ambiguous, and open, making it difficult to clearly define such boundaries beforehand. In contrast, retrospective methods extract and store historical information for future retrieval as needed. b. Multi-faceted vs. Single-faceted. Task-related information is inherently diverse. When using single-faceted memory encoding, heterogeneous information is difficult to distinguish effectively. Multi-faceted memory, on the other hand, explicitly employs multiple routing criteria and patterns to guide different types of information to their corresponding memory types.

[0043] Introduction and Background Context Management For a single-agent system, context C t The structure is as follows:

[0044] Where τ, a, and o represent thought, action, and observation, respectively, and h t-i This represents the historical trajectory up to timestamp ti. The current time step h... t The historical trajectory is through previous history h t-i This is achieved by integrating with the most recent i thoughts, actions, and observations:

[0045] f(·) can correspond to various processing methods, such as compression, folding, and integration. In recent years, intelligent agent memory systems have become increasingly complex, requiring more sophisticated processing mechanisms to complete memory encoding, consolidation, and integration. Here, f(·) is considered a composite function containing multiple processing operations.

[0046] Intelligent agent memory management cycle In cognitive neuroscience, memory management follows a dynamic cycle: it begins with encoding (forming patterns of neural activity), then consolidates (strengthening stable representations in the hippocampus), and finally integrates (integrating memories into a broader knowledge structure). Memory updates occur when prediction errors trigger differentiation or integration. The retrieval process triggered by environmental cues involves the completion of hippocampal patterns and the restoration of neocortical representations. Crucially, the retrieval behavior itself is transformative: it involves a reconsolidation process that modifies existing memory traces and facilitates subsequent encoding.

[0047] Analogous to the encoding-consolidation-integration cycle in cognitive neuroscience, the memory system of a large language model agent should achieve: (i) encoding interactions as structured short-term traces, (ii) consolidating them into stable long-term representations through filtering and decay, and (iii) integrating repetitive patterns into semantic facts and procedural skills. Prediction errors caused by environmental feedback trigger memory updates, leading to differentiation or integration. The retrieval mechanism is similar to pattern completion: sparse cues reconstruct relevant contextual background and re-implant it into the agent's working context. The key is to perform a similar reconsolidation update after retrieval—revising the retrieval content according to the memory's usefulness and re-encoding it for future use.

[0048] MemPrism Figure 4 This section provides an overview of the MemPrism system. The working slot management module autonomously partitions and absorbs information generated during the context generation phase in a retrospective manner. Subsequently, working memory (i.e., working slots) undergoes filtering and routing to generate three types of long-term memory. Among them, episodic memory is clustered and abstracted through memory abstraction functions, transforming it into semantic memory. In the memory integration phase, working memory and long-term memory are preprocessed separately and then integrated into the context using different retrieval strategies.

[0049] This embodiment proposes MemPrism—a retrospective, multi-faceted memory consolidation and integration framework for LLM agents. For example... Figure 4 As shown, this method comprises five modules: a working slot management module autonomously partitions and absorbs information generated during the context generation stage in a retrospective manner, corresponding to the memory encoding stage. Subsequently, working memory (i.e., working slots) is filtered and routed to generate three types of long-term memory. Episodic memory is clustered using DenStream and transformed into semantic memory through memory abstraction, corresponding to the memory consolidation stage. In the memory integration stage, working memory and long-term memory are preprocessed separately and then integrated into the context using different retrieval methods.

[0050] Memory Encoding: Recall and Autonomous Information Classification and Absorption This invention treats the thoughts, actions, and observations acquired by an intelligent agent through environmental interaction as raw information. Once sufficient information has been accumulated, it is encoded into several working slots {k}. j} n j =1:

[0051] In the design of the work slot, this invention draws inspiration from the concept of a distributed sensory-prefrontal network. Notes and related fields correspond to distributed sensory representations, while actions and related fields correspond to prefrontal control. This process is both retrospective and autonomous. Through this design, MemPrism achieves a balance between granularity and latency. Furthermore, this invention incorporates historical information h t-i As context input to a large language model, it enables the automatic segmentation and extraction of useful information, ensuring that the generated slots are both atomic and fully carry the relevant context.

[0052] Why use a retrospective approach? When an agent performs a task, it is often impossible to precisely define the boundaries of subtasks in advance. In other words, a look-ahead approach, which pre-plans context blocks or subtasks, assumes that the information structure is known a priori. In reality, the environment in which an agent operates is often dynamic, fuzzy, and open, making it difficult to define boundaries in advance.

[0053] Why adopt an autonomous mode? Because the agent can access the interaction history, it can grasp the core content and state of the overall task. Based on this understanding, the agent can automatically segment and extract context of appropriate length and sufficient information to generate task-oriented information slots.

[0054] Memory Integration: Multifaceted Information Processing The information extracted by the intelligent agent from the environment is multifaceted, encompassing domain knowledge, experiential or trial-and-error insights, and reusable processes. The agent filters and routes data from various corpus slots based on factors such as novelty, usability, stability, and evidence, generating different types of long-term memory according to the content of the corpus slots and task requirements. Specifically, long-term memory is categorized by functional role as follows: Semantic memory: responsible for factual content; Episodic memory: Recording experiential or time-related content; Program memory: Encodes reusable knowledge and behavioral patterns.

[0055] Memory updating and insertion. The agent retrieves content from the working slot and long-term memory respectively, forming a historical trajectory. Based on this historical trajectory, the agent interacts with the environment to generate new long-term memories. For each newly formed long-term memory entry m... i This invention calculates its nearest neighbor m of the same type. j The semantic similarity is used to determine whether to directly insert into the memory M or update the existing entry.

[0056]

[0057] This implementation scheme aligns with predictive coding theory: environmental feedback acts as a prediction error signal to regulate memory updates, while cue-triggered retrieval reproduces relevant potential scenarios through a pattern completion mechanism.

[0058] Abstraction of Memory. This invention draws on the concept of complementary learning systems theory—transforming multiple similar experiences into more abstract and generalizable knowledge through induction and extraction of common features. In the MemPrism model, this invention defines this process as: aggregating several closely related event memories into representative semantic memories. This invention uses the DenStream algorithm to perform this streaming clustering process. Anomaly clusters (OMCs) are considered as initial semantic buds sprouting from a small number of episodic memories, while latent clusters (PMCs) represent abstract patterns that have gained stability after being reinforced by multiple episodic experiences. This invention calls the threshold for their mutual transformation semantic consistency (SC), which is determined by pairwise comparison of all episodic memory embedding vectors within the i-th PMC:

[0059] Here, N i This represents the number of data points in the i-th PMC. Throughout the process, this invention dynamically maintains the squared L2 norm of the sum of the embedding vectors within each cluster, ∥v. sum ∥ 2 This ensures that the semantic clustering computation for a single update has an O(1) time complexity. When a new context memory is added, it is first assigned to an OMC or PMC based on Euclidean distance; otherwise, a new OMC is created. After updating the clustering based on multiple context memories, this invention abstracts each PMC into a corresponding semantic memory:

[0060] Where m e i,j Let m represent the j-th episodic memory within the i-th episodic memory. s i Let represent the i-th semantic memory. If the addition of a new contextual memory causes the SC value of a certain contextual memory to fall below a threshold, the corresponding abstract semantic memory will be removed. This mechanism ensures MemPrism's adaptability to changes in data distribution.

[0061] Memory Integration: Multifaceted Retrieval of Slots and Long-Term Memory In existing research, memory access is typically achieved by retrieving historical records most similar to the current context or query. However, agent queries often have multifaceted characteristics, involving goals, constraints, requirements, and underlying assumptions. Similarity-based retrieval tends to compress memory access into a single dominant semantic direction, leading to redundancy or homogenization of memory items and failing to cover all relevant directions required for decision-making. Therefore, this invention designs differentiated retrieval strategies for working slots and long-term memory.

[0062] Slot retrieval. Let the total number of working slots be N, and the embedding vector of the i-th slot be k. i ∈R dAll slots are stacked to form a matrix K = [k1, ..., k]. N ] ∈ R d ×N. This invention considers query vector q ∈ R d In scenarios where both the slot embedding k and the similarity vector k are unit vectors, the similarity vector s is calculated as follows:

[0063] Here, V and U are obtained by performing singular value decomposition (SVD) on matrix K. The vector z is obtained by projecting the query vector onto U, thus mapping the query to the main semantic direction defined by the orthogonal basis of the column space. This means |z i | reflects the query requirement in the i-th direction. Then press |z. i Sort the directions to obtain the main direction sequence i1, i2, ... In round t, based on the main direction i t Select slots. For each candidate slot k j Calculate the score:

[0064] Where sim(·) represents a similarity function, such as lexical overlap, BM25 (Best Matching 25 - a classic term-based information retrieval relevance scoring method) score, or semantic similarity. This invention allocates the number of retrieval iterations according to the proportion of |zi|. The retrieval operation in the i-th direction is defined as:

[0065] Where M represents the total number of searches, and m represents the number of searches allocated in the current round. Therefore, the more dominant direction will receive more search visits.

[0066] Long-term memory retrieval. Since MemPrism explicitly performs routing and differentiation operations on long-term memory, directly calculating similarity scores and applying Top-k selection is sufficient. However, given the cross-session or cross-task nature of long-term memory, retrieved long-term memories may significantly interfere with the current context. To mitigate this problem, this invention sets a similarity threshold T, including only long-term memories with similarity exceeding this threshold in the context:

[0067] History formation. Once the corresponding working slot and long-term memory are retrieved, the agent can adopt different history formation strategies based on task characteristics:

[0068] experiment This section evaluates MemPrism through three diverse and challenging tasks and compares it with different context management strategies to verify the superior performance of the invention. Specifically, the presentation includes: 1. Overall performance across the three tasks; 2. Ablation studies of maximum slot count, memory abstraction, and slot retrieval.

[0069] Experimental setup Benchmark datasets. Three challenging tasks were selected: 1. Multi-objective, multi-hop question answering, an extension of HotpotQA and NaturalQuestions; 2. Multi-turn tool invocation task on the BFCL-V3 multi-turn base dataset; 3. Multi-turn dialogue task on the LongMemEval dataset.

[0070] Evaluation Metrics. Following Mem1 standards, for multi-objective, multi-step question-answering tasks, report the exact match metric (EM) and F1 score. Note: In n-objective question-answering tasks, the theoretical upper limit for both EM and F1 is n. For multi-turn function call tasks, report both Avg@4 and Pass@4 metrics: the former is the average success rate across four independent trials, and the latter is the probability of success in at least one trial. For multi-conversation dialogue tasks, report the overall accuracy (approximately 115,000 tokens per dialogue) under both Oracle and S settings.

[0071] Memory Protocol. Following the distinction between working memory and long-term memory, the working memory slot is cleared after each interaction unit, while long-term memory persists throughout the entire task. Baseline Model. MemPrism is compared to 1. direct inference; 2. context compression; and 3. cutting-edge memory systems, including A-Mem, Mem0, and Mem-α.

[0072] Performance and Analysis Figure 5 The test results for GPT-4o-mini and Qwen3-4B are shown. Best and second-best performances are highlighted. MemPrism achieves average leadership across three diverse task classes, significantly outperforming existing agent memory systems.

[0073] Question answering task performance. First, the performance of MemPrism in multi-objective, multi-step question answering tasks is evaluated. Based on the HotpotQA and NQ datasets, this invention constructs test sets containing 2, 8, and 16 objectives. (See table below for details.) Figure 5As shown, in the GPT-4o-mini configuration, MemPrism consistently outperforms all baseline models, and its missing-function variants (with LTM or SVD removed) still exhibit strong performance. MemPrism achieves a significant performance improvement compared to the missing-function variants. This improvement stems from the generalization and diversity of the knowledge required for the task. MemPrism enables agents to efficiently reuse experience through explicit differentiation and abstraction of long-term memory. Diversity is related to knowledge density: a single query typically retrieves documents in only one direction, and this limitation prompts the retrieval of knowledge to cover a wider range of aspects as the number of targets increases. MemPrism alleviates this problem by employing slot retrieval using SVD-based semantic decomposition. In the Qwen3-4B setting, Mem-α achieves state-of-the-art performance on the bi-objective branch because it incorporates HotpotQA into its training data. However, its performance gradually lags behind MemPrism as the number of targets increases. Furthermore, since Qwen3-4B is a reasoning-oriented model (with thinking enabled during evaluation), it can deduce the correct answer with relatively little contextual information, which explains why MemPrism performs comparably to most baselines in this setting.

[0074] Figure 6 This demonstrates MemPrism's progressive performance on the question-and-answer task. As the number of questions increases, MemPrism gradually accumulates long-term memory.

[0075] Progressive performance analysis. Figure 6 This demonstrates MemPrism's progressive performance in question-answering tasks. It was observed that MemPrism develops increasingly robust long-term memories as the number of questions increases. Although initial performance fluctuations may occur due to uneven question difficulty distribution, it consistently recovers stably in later stages. Compared to other baseline models and variants, MemPrism clearly demonstrates its ability to dynamically evolve as the task progresses.

[0076] Tool Invocation Task Performance. In the GPT-4o-mini setup, MemPrism underperformed the direct inference baseline. The inventors emphasize that this behavior is closely related to the BFCL evaluation setup. During interaction, the agent only receives grammatical feedback, lacking task-level feedback. Furthermore, the setup of this invention is entirely online, while previous studies used pipelines that were partially offline and then switched to online.

[0077] Figure 7 The class accuracy is shown in the LongMemEval S setting. In the LongMemEval S test, MemPrism demonstrates consistently strong and balanced class performance, regardless of whether the GPT-4o-mini or Qwen3-4B model is used, with a particularly significant advantage in knowledge updates based on memory updates and pattern differentiation.

[0078] However, compared to other memory systems, MemPrism still exhibits significant advantages, even reaching top-tier performance in the Qwen3-4B setting. This advantage stems from the core emphasis of this invention on faceted memory: most baseline models assume that task information is homogeneous, thus employing a single memory pattern for encoding, which fails to meet the fundamental requirements of function call tasks. In contrast, MemPrism overcomes this limitation by explicitly distinguishing memory into subjective memory and procedural memory.

[0079] Performance on dialogue tasks. In LongMemEval, MemPrism was observed to perform relatively poorly in the Oracle setting. One possible explanation is that in this setting, the agent can directly obtain the correct answer from the original dialogue text, while MemPrism introduces additional computation to process multifaceted information, resulting in redundant memory for the agent. This hypothesis is validated by comparison with the ablation variant—removing the LTM (Long Memory) or SVD module actually improves performance. However, in the S setting, MemPrism achieves state-of-the-art performance. Notably, the context lengths of GPT-4o-mini and Qwen3-4B are 128K and 32K, respectively. In the S setting, the average length of a single dialogue reaches 115K words, and direct inference leads to a significant performance drop. Furthermore, since most LongMemEval tasks require fine-grained consideration of dialogue details, context compression is also ineffective for Qwen3-4B.

[0080] Category analysis under setting S. Figure 7This paper demonstrates the class accuracy of MemPrism and other baseline models on the LongMemEval S settings of the GPT-4o-mini and Qwen3-4B platforms. On the GPT-4o-mini platform, MemPrism performs particularly well in the knowledge update category, which is closely related to its memory update mechanism based on similarity thresholds. Furthermore, compared to other memory systems, MemPrism exhibits more balanced performance across categories, thanks to its memory pattern design and explicit memory differentiation mechanism. The only significant limitation appears in the single-preference category, possibly because this category requires the agent to comprehensively infer the user's historical preferences and needs across sessions. This invention further confirms that noise introduced by semantic direction decomposition may be one of the influencing factors by comparing a variant of MemPrism's SVD with the single-preference scenario (0.433 vs. 0.500). For models like Qwen3-4B, where the context length is much shorter than the average dialogue length, a memory system is indispensable. In this scenario, MemPrism achieved a significant performance improvement (0.172 → 0.558), comparable to the direct inference performance of GPT-4o-mini. Furthermore, MemPrism exhibited classification performance characteristics similar to GPT-4o-mini, indicating that this technique can be effectively applied to short-context models.

[0081] ablation experiment Figure 8 An ablation study of the maximum number of slots for question-answering tasks is presented. MemPrism benefits from a larger slot budget, especially as task objectives increase, because it retains more atomic, context-based slots. However, its improvement gradually diminishes as effective slot utilization reaches saturation due to diminishing marginal returns.

[0082] Maximum number of slots. This invention examines the impact of different upper limits on the number of slots in a single context transition setting for question-answering tasks, with results as follows: Figure 8 As shown, agent performance gradually improves with increasing maximum slot count, and this trend becomes more pronounced with increasing target number. This phenomenon stems from the slot design philosophy in MemPrism: it aims to capture atomic knowledge based on context and task environment. Increasing the slot budget allows the agent to store more of this knowledge. It is worth noting that performance improvement exhibits a significant diminishing marginal effect as the maximum number of slots continues to increase. Since this parameter only controls the maximum number of slots, after exceeding a certain threshold, the actual number of slots used in a single query no longer changes significantly except in very rare cases.

[0083] Memory abstraction. This invention evaluated the performance of memoryless abstraction in tool invocation and dialogue tasks. As shown in Table 2, memory abstraction consistently delivers superior performance in the LongMemEval S setting. However, in other settings, the reasoning capabilities of Qwen3-4B allow it to utilize abstracted semantic memory more effectively.

[0084] Figure 9 This paper presents a slot retrieval ablation study based on singular value decomposition (SVD). Under the same budget of the first M results, the MemPrism SVD-based retrieval system significantly improves the orientation coverage compared to cosine nearest neighbor (cosine NN), demonstrating its ability to present diverse cross-directional slots for a single multifaceted query.

[0085] Slot retrieval. This invention constructs a synthetic multi-step retrieval environment: each slot is an atomic embedding associated with a single direction, while each query is a multi-faceted mixture with a dominant direction. To simulate multimodal features in real-world scenarios, slots for each direction are extracted from multiple sub-centers, and the mixing weights are unbalanced. This invention evaluates the performance of multi-step fixed-budget Top-M retrieval using directional coverage and redundancy metrics. Figure 9 As shown, MemPrism's SVD-based slot retrieval method significantly outperforms standard cosine similarity retrieval in terms of directional coverage. This result verifies the design intent of this invention to achieve cross-directional slot retrieval through a single query.

[0086] Related research Context Management for Intelligent Agents. Intelligent agents differ significantly from traditional chatbots, primarily due to the long-term and procedural nature of the tasks they perform. Therefore, increasing research focuses on context management for intelligent agents, such as selectively compressing and recombining context, or offloading parts of the context through Retrieval Enhancement Generation (RAG) and retrieving them when needed. Several recent studies have proposed context management schemes based on just-in-time compilation. In contrast, MemPrism manages context based on a comprehensive understanding, enabling the agent to autonomously determine the granularity and scale of information extraction, rather than directly employing compression techniques or relying on static RAG systems.

[0087] Intelligent agent memory systems. Many researchers have recognized the importance of context management for intelligent agents, and one solution is to design reliable memory systems. Some methods draw inspiration from operating systems, attempting to model memory from the perspective of file management and storage systems. Other studies, based on cognitive science, focus on designing memory systems corresponding to the hippocampus and neocortex. However, these systems often emphasize a single direction or store all information uniformly in a homogeneous repository. MemPrism, through a clear encoding scheme and memory consolidation and differentiation mechanisms, fully explores the value of multifaceted information.

[0088] in conclusion This invention proposes MemPrism, a retrospective multifaceted memory consolidation and integration framework for large-scale language model agents. This framework allows the agent to autonomously segment and extract sufficient contextual information, encoding it into storage slots according to predefined patterns, thereby capturing the multifaceted information features inherent in the task. Furthermore, MemPrism follows complementary learning theory, explicitly allocating storage slots to three types of long-term memory and abstracting similar episodic memories into semantic memories. Experiments show that under various tasks and experimental settings, MemPrism significantly outperforms other agent memory systems, demonstrating its effective ability to mine the multifaceted characteristics of task information.

[0089] In other embodiments, the present invention also provides a non-volatile computer storage medium storing computer-executable instructions that can execute the memory management method for LLM agents in any of the above method embodiments for draft models and target verification models. In one embodiment, the non-volatile computer storage medium of the present invention stores computer-executable instructions, which are configured as follows: The thoughts, actions, and observations generated from the interaction are automatically segmented and absorbed into structured work slots by LLM within a retrospective window; Each work slot is filtered and routed according to preset factors to generate three types of long-term memory: semantic memory, contextual memory, and process memory. Similarity threshold gating is used for updating or inserting long-term memory writes; Different retrieval strategies are adopted for the working slot and the long-term memory during the memory access phase.

[0090] Non-volatile computer-readable storage media may include a stored program area and a stored data area, wherein the stored program area may store an operating system and application programs required for at least one function; the stored data area may store data created according to the use of the memory management method and system for LLM agents. Furthermore, the non-volatile computer-readable storage medium may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other non-volatile solid-state storage device. In some embodiments, the non-volatile computer-readable storage medium may optionally include memory remotely located relative to the processor, and these remote memories may be connected to the memory management method for LLM agents via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0091] This invention also provides a computer program product, which includes a computer program stored on a non-volatile computer-readable storage medium. The computer program includes program instructions, which, when executed by a computer, cause the computer to perform any of the above-described memory management methods for LLM agents.

[0092] Figure 10 This is a schematic diagram of the structure of the electronic device provided in the embodiment of the present invention, such as... Figure 10 As shown, the device includes: one or more processors 710 and memory 720. Figure 10 Taking a processor 710 as an example, the device for memory management methods and systems for LLM agents may further include an input device 730 and an output device 740. The processor 710, memory 720, input device 730, and output device 740 can be connected via a bus or other means. Figure 10 Taking a bus connection as an example, the memory 720 is the aforementioned non-volatile computer-readable storage medium. The processor 710 executes various server functions and data processing by running non-volatile software programs, instructions, and modules stored in the memory 720, thereby implementing the memory management method for LLM intelligent agents described in the above method embodiment. The input device 730 can receive input digital or character information and generate key signal inputs related to user settings and function control of the large language model routing device. The output device 740 may include a display screen or other display device.

[0093] The above-described product can execute the method provided in the embodiments of the present invention, and has the corresponding functional modules and beneficial effects for executing the method. Technical details not described in detail in this embodiment can be found in the method provided in the embodiments of the present invention.

[0094] In one implementation, the above-described electronic device is applied in a large-scale language model routing device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to: The thoughts, actions, and observations generated from the interaction are automatically segmented and absorbed into structured work slots by LLM within a retrospective window; Each work slot is filtered and routed according to preset factors to generate three types of long-term memory: semantic memory, contextual memory, and process memory. Similarity threshold gating is used for updating or inserting long-term memory writes; Different retrieval strategies are adopted for the working slot and the long-term memory during the memory access phase.

[0095] The electronic devices described in this application exist in various forms, including but not limited to: (1) Mobile communication devices: These devices are characterized by their mobile communication capabilities and primarily aim to provide voice and data communication. These terminals include: smartphones, multimedia phones, feature phones, and low-end phones, etc.

[0096] (2) Ultra-mobile personal computer devices: These devices fall under the category of personal computers, possessing computing and processing capabilities, and generally also have mobile internet access features. These terminals include PDAs, MIDs, and UMPCs, etc.

[0097] (3) Portable entertainment devices: These devices can display and play multimedia content. This category includes: audio and video players, handheld game consoles, e-book readers, as well as smart toys and portable car navigation devices.

[0098] (4) Server: A device that provides computing services. The components of a server include a processor, hard disk, memory, system bus, etc. Servers are similar to general computer architectures, but because they need to provide highly reliable services, they have higher requirements in terms of processing power, stability, reliability, security, scalability, and manageability.

[0099] (5) Other electronic devices with data interaction functions.

[0100] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and 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 modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0101] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods of various embodiments or some parts of embodiments.

[0102] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention 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 of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A memory management method for LLM agents, comprising: The thoughts, actions, and observations generated from the interaction are automatically segmented and absorbed into structured work slots by LLM within a retrospective window; Each work slot is filtered and routed according to preset factors to generate three types of long-term memory: semantic memory, contextual memory, and process memory. Similarity threshold gating is used for updating or inserting long-term memory writes; Different retrieval strategies are adopted for the working slot and the long-term memory during the memory access phase.

2. The method according to claim 1, characterized in that, The method further includes: The online clustering of the aforementioned contextual memories abstracts stable micro-clusters into semantic memories, and withdraws the abstraction when consistency decreases, ensuring adaptability to distribution changes.

3. The method according to claim 2, characterized in that, The online clustering of the contextual memories, abstracting stable micro-clusters into semantic memories, and withdrawing the abstraction when consistency decreases, includes: The aforementioned contextual memories are subjected to streaming clustering, and abnormal micro-clusters and potential micro-clusters are continuously maintained; Semantic consistency is calculated for the potential micro-clusters, and semantic memory is abstracted from the cluster when the semantic consistency is greater than a threshold. When subsequent data leads to a decrease in semantic consistency, the abstract results are retracted to ensure adaptability.

4. The method according to claim 1, characterized in that, The different retrieval strategies adopted for the working slot and the long-term memory during the memory access phase include: The working slot retrieval uses singular value decomposition to decompose the query into multiple orthogonal semantic directions to improve multi-faceted coverage; For the long-term memory retrieval, a threshold filtering and isolation mechanism is used to reduce cross-session interference; The history is formed and the context is generated according to the task strategy.

5. The method according to claim 3, characterized in that, The process of automatically segmenting and absorbing the thoughts, actions, and observations generated by the interaction into structured work slots within a retrospective window by LLM includes: Store the thoughts, actions, and observations generated from the interaction in a retrospective window; Once a certain number of steps i are accumulated, the LLM is invoked to retrospectively summarize the interactions of the most recent i steps, and information boundaries are automatically identified by combining the history, outputting multiple structured work slots.

6. The method according to claim 4, characterized in that, The preset factors include novelty, utility, stability, and evidence. The filtering and routing of each work slot based on these preset factors generates three types of long-term memory: semantic memory, contextual memory, and process memory. For each work slot, preset factors are evaluated to determine whether to write to long-term memory and to determine the type of long-term memory to which it is routed. The types of long-term memory include semantic memory, contextual memory, and process memory.

7. The method according to any one of claims 1-6, wherein the update or insertion of long-term memory writes using similarity threshold gating comprises: The selected memory entries are written with similarity-gated values, including comparison with the nearest neighbors of the same type of memory. If the similarity is greater than the threshold, the entries are updated and merged; otherwise, new entries are inserted.

8. An electronic device comprising: At least one processor, and a memory communicatively connected to the at least one processor, wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the steps of the method according to any one of claims 1-7.

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