A memory operation processing method and system based on natural language instructions
By using a standardized processing pipeline based on natural language instructions, the inconsistency and redundancy issues of the AI agent memory system are resolved, enabling efficient and accurate management of the memory bank and improving the performance and reliability of the AI agent in long-term tasks.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- MEMORY TENSOR (SHANGHAI) TECHNOLOGY CO LTD
- Filing Date
- 2025-11-13
- Publication Date
- 2026-05-29
AI Technical Summary
Existing AI agent memory systems suffer from inconsistent memory operation execution, fuzzy conversion, memory priority drift, and redundancy issues during long-term tasks, resulting in low system efficiency and poor reliability.
By using a memory operation processing method based on natural language instructions, a standardized processing pipeline is established from natural language instructions to the backend database. This includes receiving, verifying, parsing, and executing structured memory operation instructions. JSON Schema is used to define format specifications, perform priority adjustment, merging, and splitting operations, and adapt to different backend systems.
It improves the reliability and functionality of AI agents, dynamically manages the memory bank structure, reduces maintenance costs and technology migration difficulties, and enhances the success rate and intelligence level of long-term tasks.
Smart Images

Figure CN121684013B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, and in particular to a memory operation processing method and system based on natural language instructions. Background Technology
[0002] In recent years, AI agent technology based on large language models has developed rapidly. These AI agents aim to simulate human behavior and autonomously perform complex tasks spanning multiple steps and lasting for several days, such as project management, market research report writing, and personal schedule planning. In these long-duration tasks, memory capability is the cornerstone of the AI agent's success. An ideal memory system should enable the AI agent to remember historical interactions, decisions, user preferences, and contextual information.
[0003] However, current mainstream AI agent memory systems face a series of deep-seated and urgent technical problems in their implementation, which severely restrict the performance, reliability, and intelligence level of AI agents in long-term tasks.
[0004] In particular, when the backend system uses a vector database, efficiently adjusting the retrieval weights of memory entries is a challenge. Existing technologies typically require reading the vector and metadata corresponding to the target memory entry from the vector database, modifying the weight values within the metadata in the application-layer memory of the computing device, and then rewriting the modified metadata and vector as a whole back into the vector database. This frequent read-write operation, especially in large-scale memory databases, significantly reduces system efficiency and response speed. Furthermore, how to effectively utilize the updated weight information in subsequent retrieval processes to improve retrieval accuracy and relevance is also a problem that needs to be solved.
[0005] Furthermore, AI agents face even more severe challenges when performing long-duration, complex tasks that last for days or weeks. First, there's the issue of memory priority drift, where critical information from the early stages of a task becomes less important in subsequent massive interactions, causing the agent to deviate from its core objective. Second, there's the problem of memory redundancy and clutter; long-duration tasks inevitably generate a large number of similar or duplicated memory entries, which not only reduces retrieval efficiency but may also trigger logical conflicts within the agent. Current technologies generally lack proactive memory management and optimization mechanisms to address these dynamic problems in long-duration task scenarios.
[0006] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of the present invention, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention
[0007] In view of this, the present invention provides a memory operation processing method and system based on natural language instructions, which aims to solve the problems of inconsistent execution of memory operations, ambiguity in transformation, memory priority drift and redundancy in long-term tasks in the existing AI agent memory management. By establishing a standardized memory processing pipeline from natural language instruction reception to backend database execution, the reliability, functionality and intelligence level of AI agent as a computer system are improved.
[0008] This invention provides a memory operation processing method based on natural language instructions, applied to the memory management of long-duration task AI agents, and executed by a computing device, including:
[0009] Receive natural language instructions continuously generated by the AI agent for long-duration tasks;
[0010] The language model is invoked, and natural language instructions are transformed into structured memory operation instructions according to the instruction format specifications that include multiple memory operation types.
[0011] The structured memory operation instructions are verified to confirm that they conform to the preset syntax rules of the instruction format specification.
[0012] The validated structured memory operation instructions are parsed into standardized operation objects;
[0013] Based on the backend system used by the memory bank of the long-duration task AI agent, the standardized operation objects are translated into backend operation instructions that can be executed by the backend system.
[0014] Execute backend operation instructions to process memory entries in the memory bank.
[0015] In some alternative embodiments, the instruction format specification is based on the JSON Schema definition, and the structured memory operation instructions include: stage field, operation field, target field, and parameter field.
[0016] In some optional embodiments, among the various memory operation types defined by the instruction format specification, there is at least one priority adjustment operation for adjusting the retrieval weight of memory entries, and at least one structural adjustment operation for integrating or decomposing the content of memory entries.
[0017] In some optional embodiments, the priority adjustment operation is an upgrade operation or a downgrade operation; the structure adjustment operation is a merge operation or a split operation.
[0018] In some optional embodiments, the method further includes:
[0019] Calculate the semantic similarity between the embedding vectors of natural language instructions and the predefined vectors representing the core objectives of long-term tasks;
[0020] When the semantic similarity is higher than the first preset threshold, an instruction for boosting is generated.
[0021] In some optional embodiments, the method further includes:
[0022] After performing a retrieval based on the query intent, the semantic similarity between the returned memory entries is calculated;
[0023] When the semantic similarity between multiple memory entries is higher than the second preset threshold, a merging operation instruction is generated.
[0024] In some optional embodiments, the method further includes:
[0025] When a signal indicating that the status of a subtask in a long-running task has changed to "completed" is received, a downgrade operation instruction is generated to act on the memory entries associated with the subtask.
[0026] In some optional embodiments, the method further includes:
[0027] When a complex natural language instruction containing multiple decomposable steps is received, instructions for splitting operations are generated to decompose a single memory entry corresponding to the complex natural language instruction into multiple sub-memory entries corresponding to the decomposable steps.
[0028] In some alternative embodiments, the language model is invoked in the following ways:
[0029] Construct structured hints, which include: a role setting area, a knowledge injection area, and an output format constraint area.
[0030] In some optional embodiments, the method further includes:
[0031] When the intent of a natural language instruction is ambiguous, a language model generates a clarifying question to interact with the user, and after receiving the user's clarifying response, the natural language instruction is then converted into a structured memory operation instruction.
[0032] In some optional embodiments, the backend system is a vector database, and when a backend operation instruction is used to adjust the retrieval weight of a memory entry, the steps of executing the backend operation instruction include:
[0033] Read the vector and metadata corresponding to the target memory entry in the vector database;
[0034] In the application layer memory of the computing device, modify the weight values in the metadata;
[0035] The modified metadata and vectors are rewritten into the vector database as a whole.
[0036] In some optional embodiments, the method further includes:
[0037] When performing semantic retrieval through the vector database, the semantic similarity score obtained from the retrieval is used to perform a preset calculation with the weight value in the metadata to generate the final ranking score.
[0038] In some optional embodiments, the backend system is a relational database, and when the backend operation instruction is an operation for consolidating multiple memory entries, the steps of executing the backend operation instruction include:
[0039] Start a database transaction; within the database transaction, perform the following operations sequentially: First, execute a SELECT statement to read the contents of multiple target memory entries; then, call the language model to generate integrated new content from the read content; next, execute an INSERT statement to write the new content as a new memory entry into the memory; finally, execute an UPDATE or DELETE statement to process multiple target memory entries.
[0040] Finally, commit the database transaction.
[0041] In some optional embodiments, the step of converting natural language instructions into structured memory operation instructions includes converting complex natural language instructions into an ordered list containing multiple structured memory operation instructions, and the subsequent verification, parsing, translation and execution steps are performed sequentially on each structured memory operation instruction in the order of the ordered list.
[0042] In some alternative embodiments, the target field includes multiple ways to specify the scope of the operation, including: specifying it by a unique identifier of the memory entry; specifying it by filtering conditions that include tags, time ranges, or weight ranges; and specifying it by semantic search conditions that include query intent.
[0043] This invention provides a memory operation processing system based on natural language instructions. This system is applied to memory management of long-duration AI agents and includes:
[0044] The receiving module is used to receive natural language instructions continuously generated by the long-term task AI agent;
[0045] The conversion module is configured to call the language model and convert natural language instructions into structured memory operation instructions according to the instruction format specifications that include multiple memory operation types.
[0046] The verification module is configured to verify structured memory operation instructions to confirm that the structured memory operation instructions conform to the preset syntax rules of the instruction format specification.
[0047] The parsing module is configured to parse verified structured memory operation instructions into standardized operation objects.
[0048] The adaptation module is configured to translate standardized operation objects into backend operation instructions that can be executed by the backend system based on the memory bank of the long-term task AI agent.
[0049] The execution module is configured to execute backend operation instructions to process memory entries in the memory bank.
[0050] In some optional embodiments, among the various memory operation types defined by the instruction format specification, there is at least one priority adjustment operation for adjusting the retrieval weight of memory entries, and at least one structural adjustment operation for integrating or decomposing the content of memory entries.
[0051] In some alternative embodiments, the system further includes:
[0052] The scheduling module is configured to: when the semantic similarity between a natural language instruction and a preset core objective of a long-running task is detected to be higher than a first preset threshold, trigger the conversion module to generate an instruction for the priority adjustment operation; or
[0053] When it is detected that the semantic similarity between multiple memory entries retrieved for the query intent is higher than the second preset threshold, the conversion module is triggered to generate the instruction for the merging operation in the structural adjustment operation.
[0054] In some optional embodiments, the backend system is a vector database, and the execution module is configured to: When backend operation instructions are used to adjust the retrieval weights of memory entries,
[0055] Read the vector and metadata corresponding to the target memory entry in the vector database;
[0056] Modify the weight values within the metadata in the system's application layer memory;
[0057] The modified metadata and vectors are written back to the vector database as a whole;
[0058] In the subsequent retrieval process, the semantic similarity scores between vectors are pre-calculated based on the weight values to generate the final ranking score.
[0059] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit the invention.
[0060] The memory operation processing method and system based on natural language instructions of the present invention have the following beneficial effects:
[0061] This invention improves the reliability of AI agents by introducing a unified memory operation language and standardized processing pipelines, ensuring that natural language intents are translated into consistent and predictable underlying operations. The system defines advanced operations such as merging, splitting, and priority adjustment, enhancing functionality and flexibility. An intelligent scheduling mechanism proactively combats memory priority drift and redundancy in long-running tasks, dynamically maintaining high weights for task memories and optimizing the memory bank structure, reducing the risk of AI agents deviating from their goals or generating logical inconsistencies, and improving the success rate of long-running tasks. The adapter layer decouples application logic from underlying storage, reducing maintenance costs and the difficulty of technology migration. Attached Figure Description
[0062] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings.
[0063] Figure 1 This is a flowchart of a memory operation processing method based on natural language instructions according to an embodiment of the present invention;
[0064] Figure 2 This is a schematic diagram of the structure of a memory operation processing system based on natural language instructions according to an embodiment of the present invention. Detailed Implementation
[0065] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, they are provided so that the invention will be more comprehensive and complete, and will fully convey the concept of the exemplary embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
[0066] Furthermore, the accompanying drawings are merely illustrative of the invention and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0067] The flowchart shown in the attached diagram is merely an illustrative example and does not necessarily include all steps. For example, some steps may be broken down, while others may be combined or partially combined. Therefore, the actual execution order may change depending on the specific circumstances.
[0068] This invention relates to multiple fields, including natural language processing, knowledge representation, and database operations. Natural language processing technology is used to understand and parse user-input natural language instructions, transforming them into machine-executable structured instructions through language models. Knowledge representation is embodied in the definition of instruction format specifications, which abstract memory operations into standardized data structures, enabling computers to effectively organize and manage knowledge. Database operations are responsible for converting structured instructions into CRUD operations on the underlying memory database. Through the synergistic effect of these technologies, this invention aims to solve the memory management challenge faced by AI agents in long-duration tasks, namely, how to accurately and consistently convert natural language instructions into effective operations on the memory database. This conversion process involves multiple stages, including semantic understanding, knowledge reasoning, and data manipulation; deviations in any stage can lead to memory management failures. By establishing standardized instruction formats and rigorous verification mechanisms, this invention aims to eliminate these deviations and ensure the accuracy and reliability of memory operations. When operations on the memory database are more precise and efficient, AI agents exhibit better stability and higher success rates in long-duration tasks.
[0069] like Figure 1 As shown, this embodiment of the invention provides a memory operation processing method based on natural language instructions, applied to the memory management of long-duration task AI agents, and executed by a computing device. The method includes the following steps:
[0070] Step S100: Receive natural language instructions continuously generated by the long-running AI agent. For example, in an automated customer service agent, a user enters a command through the chat interface: "Please record that user ID 12345 reported that the logistics information for order number ABCDE has not been updated for a long time." This command is received by the receiving module deployed on the server.
[0071] Step S200 involves invoking a language model to convert the natural language instruction into a structured memory operation instruction based on an instruction format specification that includes various memory operation types. For example, the system may invoke a third-party language model service deployed in the cloud. This language model receives the natural language instruction and converts it into a structured data format according to a pre-defined format specification. The converted instruction may include tags to identify the operation type (e.g., "Encode" indicating encoding new memory) and tags to encapsulate the specific content of the natural language instruction (e.g., specific information from user feedback). In other optional implementations, a locally deployed lightweight language model or other natural language processing technologies such as a rule engine can be used to achieve similar functionality in resource-constrained environments.
[0072] Step S300 verifies the structured memory operation instructions to confirm that they conform to the preset syntax rules of the instruction format specification. For example, the system uses a predefined pattern to verify the instructions generated in step S200. The verification process checks whether the instructions contain required fields, whether the field types are correct, etc. If the instructions do not conform to the preset rules, the verification fails, and a corresponding error report is generated.
[0073] Step S400 involves parsing the verified structured memory operation instructions into standardized operation objects. For example, the system parses the verified instructions into class instances in a predefined programming language. These class instances contain attributes to store the values of various fields in the instruction, such as operation type, operation target, and operation parameters.
[0074] Step S500: Based on the backend system used by the long-duration task AI agent's memory, the standardized operation objects are translated into backend operation instructions executable by the backend system. For example, if the long-duration task AI agent's memory uses a relational database management system (RDBMS), the system translates the standardized operation objects into SQL statements. If the memory uses a key-value store system, the system translates the standardized operation objects into corresponding API calls.
[0075] Step S600: Execute backend operation instructions to process memory entries in the memory. For example, execute SQL statements to insert new memory entries into the relational database or update the content of existing memory entries. Alternatively, call the API of the key-value store system to store new memory entries in the key-value store system.
[0076] The aforementioned steps work together to form a complete memory operation processing flow. Received natural language instructions are first converted into machine-understandable structured instructions, then their validity is verified, and finally translated into executable instructions for the backend system, thereby enabling reliable operation of the memory bank. In this way, the method solves the ambiguity and uncertainty problems in natural language instruction processing in existing technologies, achieving efficient, accurate, and consistent management of the memory bank for long-duration AI agents.
[0077] Through the above-described scheme, this embodiment can convert natural language instructions into executable backend operation instructions, enabling the processing of memory entries in the memory bank. Compared with existing technologies, this embodiment can convert user natural language instructions into structured, machine-understandable instructions, ensuring the accuracy and reliability of instruction execution; by translating structured instructions into backend system executable instructions, it achieves compatibility with different types of memory banks; this method can be applied to memory management of long-duration task AI agents, meeting the memory processing needs of long-duration tasks.
[0078] In one specific implementation, the instruction format specification is defined using JSON Schema to ensure the standardization and machine readability of structured memory operation instructions. First, a JSON Schema file is defined, which details all allowed fields, data types, and constraints between fields. For example, the value of the `stage` field must be a predefined enumeration type ("ENC", "STO", "RET"), the value of the `op` field must be a predefined memory operation type name ("Encode", "Update", "Delete", etc.), and the content of the `args` field has different structural requirements depending on the `op` field.
[0079] Specifically, structured memory operation instructions contain the following four fields: stage, op, target, and args. The stage field indicates the stage at which the operation occurs, such as the encoding stage ("ENC"), storage stage ("STO"), or retrieval stage ("RET"). The op field specifies the specific memory operation to be performed; for example, "Encode" creates a new memory entry, "Update" updates an existing memory entry, and "Delete" deletes a memory entry. The target field defines the target object of the operation, i.e., the memory entry to be operated on; it can be an identifier for one or more memory entries. The args field contains the parameters required to perform the operation, which vary depending on the operation type. For example, for the "Encode" operation, args might contain the text content, type, and label information of the memory entry; for the "Update" operation, args might contain the fields to be updated and their corresponding new values. Upon receiving the structured memory operation instructions, the validation module uses a predefined JSON Schema to validate the instructions, ensuring that the structure and data types of the instructions conform to the specification. Any instructions that do not conform to the specification will be rejected and an error message will be returned.
[0080] Then, through the above scheme, this embodiment can achieve standardized description and verification of memory operation instructions, ensuring that the structure of the instructions is clear and the content is accurate, laying a solid foundation for subsequent parsing, translation and execution, and improving the reliability and maintainability of the entire system.
[0081] In one specific implementation, based on the above embodiments, the memory operation types are expanded to include priority adjustment operations and structure adjustment operations. Specifically, priority adjustment operations are used to adjust the retrieval weight of memory entries, and are implemented in ways including but not limited to: modifying the weight coefficient of memory entries, adjusting the position of memory entries in the inverted index, or changing the vector representation of memory entries in the vector database. Structure adjustment operations are used to integrate or decompose the content of memory entries, and are implemented in ways including but not limited to: merging multiple similar memory entries into a more comprehensive entry, or splitting a complex memory entry into multiple simpler entries.
[0082] Furthermore, upon receiving a new natural language instruction, the conversion module not only generates basic operations for recording the instruction but may also generate priority adjustment or structure adjustment operations based on the instruction content and system state. For example, when an instruction indicates a performance upgrade for a task, the conversion module generates a priority upgrade operation to increase the weight of memory entries related to that task. When the information contained in the instruction can be merged with existing memory entries, the conversion module generates a structure adjustment operation to integrate relevant information and reduce redundancy.
[0083] In other alternative implementations, priority adjustment operations can also be achieved by adjusting the access frequency or time decay factor of memory entries, while structure adjustment operations can be achieved by using knowledge graph technology to model and adjust the relationships between memory entries in a more refined manner.
[0084] Through the above solution, this embodiment can provide more flexible and intelligent memory management capabilities, thereby improving the performance of AI agents in long-term tasks.
[0085] In one specific implementation, the priority adjustment operation defined in the instruction format specification is specifically implemented as promotion and demotion operations, and the structure adjustment operation is specifically implemented as merge and split operations.
[0086] Promotion operations increase the ranking weight of specific memory entries in search results, placing current information in a more prominent position based on task progress or user feedback. Specifically, promotion can be achieved by modifying the weight field of a memory entry, such as increasing the weight value by a preset increment or setting it to a higher absolute value. Demotion operations reduce the priority of certain memory entries; for example, after a subtask is completed, the weight of memory entries related to that subtask can be reduced to prevent this information from interfering with subsequent tasks. Merging operations combine multiple related memory entries into a more comprehensive entry, reducing redundant information in the memory bank and improving retrieval efficiency. Merging operations can be achieved by integrating the content of multiple entries and creating a new memory entry. During the merging process, original entries can be retained or deleted. Furthermore, splitting operations break down a memory entry containing multiple topics into multiple finer-grained entries for more precise retrieval and management of memories. Splitting operations can be achieved by dividing the content of the original entry and creating multiple new memory entries. In some other alternative implementations, priority adjustment operations can also be implemented by modifying other attributes of memory entries, such as modifying their access frequency or timestamp; structure adjustment operations can also be implemented by establishing associations between memory entries, for example, using a graph database to represent the connections between memory entries.
[0087] Through the above solution, this embodiment can manage the information in the memory bank more flexibly and dynamically adjust the priority and structure of memory entries according to the needs of the task, thereby improving the performance and reliability of the AI agent.
[0088] In one specific implementation, the method further includes: after receiving a natural language instruction, the computing device calculates the embedding vector of the natural language instruction. Specifically, a pre-trained Sentence-BERT model is used to convert the natural language instruction into a fixed-dimensional vector representation. Then, the semantic similarity between the embedding vector and a preset vector representing a long-term task objective is calculated. The semantic similarity is calculated using cosine similarity, where the cosine of the angle between the two vectors is used as the similarity score; the closer the cosine value is to 1, the higher the similarity. Next, the calculated cosine similarity score is compared with a first preset threshold. The first preset threshold is a pre-set value, such as 0.8, used to determine the degree of association between the natural language instruction and the task objective. When the cosine similarity score is higher than the first preset threshold, the system determines that the natural language instruction is closely related to the task objective and generates an instruction for improvement. In other optional implementations, the method for calculating semantic similarity can also use dot product, Euclidean distance, etc., and the preset vector can be updated periodically based on task progress or dynamically adjusted based on user feedback.
[0089] Through the above scheme, this embodiment can automatically prioritize relevant memory entries based on the degree of association between natural language instructions and task objectives, ensuring that the AI agent always focuses on the objective during long-term tasks, avoiding information being overwhelmed, thereby improving the task success rate.
[0090] In one specific implementation, the method further includes performing a retrieval operation based on a defined query intent. Specifically, the query intent can be a natural language question explicitly posed by the user, or a query request automatically generated by the system based on the current task status. For example, in a project management agent, a user might ask, "What feedback have team members given regarding 'UI design' in the past week?" Or, the system might detect that it is currently in the "requirements analysis" phase and automatically generate the query: "Retrieve all meeting minutes and documents related to 'user experience'."
[0091] Then, the system uses a retrieval module to retrieve multiple memory entries related to the query intent from the memory database. The retrieval module can employ either word-based full-text search or semantic similarity search based on embedded vectors. For example, using the Milvus vector database, multiple similar memory entries can be obtained by calculating the cosine similarity between the query vector and the memory entry vectors.
[0092] Next, the semantic similarity between the returned memory entries is calculated. Specifically, the following steps can be taken:
[0093] For each memory entry, extract its text content.
[0094] Each text content is converted into an embedding vector, for example, using the Sentence-BERT model.
[0095] Calculate the cosine similarity between every two embedding vectors to obtain a similarity matrix.
[0096] For each memory entry, calculate its average similarity score with all other memory entries.
[0097] When the semantic similarity between multiple memory entries is higher than a second preset threshold, a merge operation instruction is generated. The second preset threshold is a pre-set parameter used to control the strictness of the merge. For example, the second preset threshold can be set to 0.85, meaning that only when the average similarity score between multiple memory entries is higher than 0.85 are they considered sufficiently similar to be merged. In this embodiment, the second preset threshold is preferably 0.85. Those skilled in the art will understand that the specific value of this second preset threshold is not fixed, but can be dynamically adjusted by the system administrator or through an adaptive learning algorithm according to the strictness of the correlation requirements for different long-term tasks. Specifically, the process of generating the merge operation instruction may include the following steps:
[0098] From the similarity matrix, identify all memory entries with an average similarity score higher than the second preset threshold, forming a "similar memory entry cluster".
[0099] For each "similar memory entry cluster", generate a Merge operation instruction.
[0100] The target field of the Merge operation instruction specifies the ID of all memory entries in the cluster.
[0101] The args field of the Merge operation command contains the merging strategy. The merging strategy can be "select the longest text as the merge result", "select the newest text as the merge result", or "call the language model to summarize all texts".
[0102] In other alternative implementations, semantic similarity can be calculated using methods such as Jaccard similarity and edit distance. The similarity threshold can be dynamically adjusted based on the specific application scenario and the characteristics of the memory bank; for example, the optimal threshold strategy can be learned through reinforcement learning. The merging strategy can also be adaptively adjusted based on the type of memory entry. For example, a "summary" strategy can be used for "meeting minutes" type entries, while a "select latest text" strategy can be used for "knowledge points" type entries.
[0103] Through the above solution, this embodiment can automatically detect and merge redundant information in the memory bank, reduce the storage space of the memory bank, improve retrieval efficiency, and enhance the cognitive consistency of the AI agent.
[0104] In one specific implementation, to address the memory management issue after the completion of subtasks in a long-running task, the following operations are performed: First, the task management module maintains a task status table, recording the current status (e.g., "not started", "in progress", "completed") of each subtask (e.g., "gathering competitor intelligence", "analyzing user feedback", "writing a draft market analysis"). The status table is automatically updated by the task execution engine after the subtask is completed.
[0105] Specifically, when the task management module receives a subtask completion signal from the task execution engine, such as the status of "Drafting Market Analysis" changing to "Completed," this signal contains the unique identifier of the subtask. Then, the intelligent scheduling module subscribes to the status change events of the task management module. Upon receiving this signal, the module first queries the memory entries related to the subtask based on its unique identifier. The query can be based on pre-defined tags (e.g., all memory entries tagged "Draft Market Analysis") or on semantic search (e.g., retrieving all memory entries related to the topic "Draft Market Analysis"). Next, for each retrieved memory entry, the intelligent scheduling module generates a Demote (degrade) operation instruction. This instruction specifies a reduction in the retrieval weight of these memory entries. For example, the weight can be reduced to a fixed value (e.g., -0.3) or to a preset minimum value (e.g., 0.1).
[0106] In some alternative implementations, the downgrade operation may not directly reduce the weight of a memory entry, but rather modify the "active time" attribute of that memory entry. Active time represents the duration for which the memory entry is considered still valid. After a subtask is completed, the active time of the relevant memory entry can be shortened or directly cleared, making it less likely to be considered in subsequent searches or even excluded altogether. Active time can be implemented, for example, by setting an expiration timestamp in the metadata; during retrieval, all entries with expiration timestamps earlier than the current time are ignored.
[0107] By employing the above approach, this embodiment can effectively prevent information related to completed sub-tasks from interfering with the AI agent's subsequent decision-making, thereby improving the quality and efficiency of completing long-term tasks.
[0108] In one specific implementation, when a complex natural language instruction containing multiple decomposable steps is received, the conversion module is configured to generate a splitting operation instruction to decompose a single memory entry corresponding to the complex natural language instruction into multiple sub-memory entries corresponding to the decomposable steps. Specifically, the conversion module first identifies the multiple steps contained in the natural language instruction. This identification process can be achieved by performing syntactic analysis on the instruction or by using a large language model to perform semantic parsing of the instruction. For example, if the received natural language instruction is "Reserve a meeting room from 9:00 AM to 11:00 AM tomorrow, prepare the meeting agenda, and notify the participants," the conversion module identifies three steps: reserving the meeting room, preparing the meeting agenda, and notifying the participants. Then, the conversion module generates a splitting operation instruction, which includes the identifier of the original memory entry and the content of the sub-memory entries associated with each decomposition step. The JSON instruction format for this splitting operation is as follows:
[0109] {"stage": "STO",
[0110] "op": "Split",
[0111] "target": { "ids": ["<ID of the original memory entry>"]},
[0112] "args": {"splits": [{"text": "Reserved meeting room from 9:00 AM to 11:00 AM tomorrow",
[0113] "type": "meeting_booking"},
[0114] {"text": "Preparing the Meeting Agenda",
[0115] "type": "agenda_preparation"},
[0116] {"text": "Notify attendees",
[0117] "type": "notification"}]}}
[0118] The `target` field specifies the ID of the original memory entry to be split, and the `args` field contains a `splits` array, where each element corresponds to a sub-memory entry, containing its text content and type. Next, the adapter receives the standardized operation object for the `Split` operation and transforms it into a sequence of instructions executable by the backend system. Taking a relational database as an example, the adapter will convert this operation into a series of `INSERT` statements to create new sub-memory entries and link them to the original memory entries via foreign keys. Simultaneously, the original memory entries are marked as "split" to avoid subsequent duplicate processing. In other optional implementations, identifying multiple steps contained in the instructions can also be achieved through a predefined rule base. This rule base contains a series of regular expressions or terms used to match specific patterns in the instructions and extract the corresponding step information.
[0119] Through the above scheme, this embodiment can decompose complex natural language instructions into multiple independent subtasks and manage each subtask as a separate memory entry, thereby improving the task execution efficiency and accuracy of the AI agent.
[0120] In one specific implementation, the method of invoking the language model in step S200 is achieved by constructing a structured prompt. This structured prompt is a multi-part, structured text template designed to precisely guide the language model in converting natural language instructions into structured, memorized operational instructions that conform to a preset instruction format specification. Specifically, the structured prompt may include the following four functional areas:
[0121] The role setting area is used to assign an expert role to the language model, focusing its reasoning capabilities on instruction translation tasks. An example of this area would be: "You are a memory manipulation expert, and your task is to convert a piece of natural language into a text2mem memory operation."
[0122] The knowledge injection area is used to dynamically provide the language model with the complete technical details of the instruction format specification. This area provides a typical JSON code example, a detailed parameter description table, and key implementation points for each memorized operation type defined in the instruction format specification, in a format easily understood by the language model (such as Markdown). For example, for the merge operation, this area might contain the following:
[0123] {\"stage\": \"STO\", \"op\": \"Merge\", \"target\": {\"ids\": [\"id_2\", \"id_3\"]}, \"args\": {\"strategy\": \"merge_into_primary\", \"primary_id\": \"id_1\"}}
[0124] Table 1: Merge — Parameter Table for Merging Records:
[0125] Fields type Required illustrate target.ids array yes Sub-records to be merged args.primary_id string yes Master Record ID
[0126] The output format constraint area is used to strictly limit the output format of the language model to ensure that the generated results can be directly parsed by subsequent computer programs. An example of this area is: "You should output directly as a JSON list format, without any additional explanations or text, without any extra characters, directly outputting parseable JSON text."
[0127] The few-sample area provides one or more example pairs of "natural language input - structured instruction output" to teach the language model to handle complex situations through contextual learning, especially instructions that need to be broken down into multi-step workflows.
[0128] By combining the four functional areas mentioned above and filling in the user's actual natural language commands, the system can generate a complete and information-rich prompt, thereby efficiently and accurately completing the command conversion task.
[0129] In one specific implementation, the method further includes: upon receiving a user's natural language instruction, the intent recognition module first performs a preliminary analysis of the instruction. Specifically, the intent recognition module can use a pre-trained natural language understanding model (such as BERT or RoBERTa) to extract the semantic features of the instruction and input them into a classifier to determine whether the intent of the instruction is clear. If the confidence level of the classifier's output is lower than a preset threshold (e.g., 0.7), the intent of the instruction is considered ambiguous.
[0130] Then, the language model generates clarifying questions. This can be done by pre-defining a series of template questions for different types of ambiguous intents and selecting an appropriate template question to fill in the blanks based on the analysis results from the intent recognition module. For example, if the intent recognition module determines that the instruction lacks an object to be operated on, it selects the template question "Which object do you wish to operate on?". Alternatively, the original instruction can be directly input into the language model, prompting it to generate a clarifying question for that instruction. For example, the prompt could be "Please generate a clarifying question based on the following user instruction: {user's natural language instruction}".
[0131] Next, the clarifying question is presented to the user through the AI agent's interactive interface, and the user's response is awaited. In other alternative implementations, the clarifying question can be presented to the user in various forms such as voice, text, or images.
[0132] Upon receiving the user's clarifying response, the original instruction and the clarifying response are concatenated into a new instruction, and the step of converting the natural language instruction into a structured memory operation instruction is re-executed. Specifically, the original instruction and the clarifying response can be directly concatenated into a new text and then input into the conversion module. Alternatively, the original instruction and the clarifying response can be input into the conversion module separately, and the conversion module can be asked to combine the two to generate the final structured memory operation instruction. In some other optional implementations, a multi-round clarifying interaction can be used to gradually clarify the user's intent.
[0133] Through the above solution, this embodiment can effectively solve the problem of ambiguous intentions in natural language commands, improve the accuracy and reliability of command conversion, thereby avoiding erroneous operations caused by command ambiguity and enhancing the intelligence level and user experience of AI agents.
[0134] In one specific implementation, when the AI agent's memory bank backend uses a vector database, for backend operation instructions to adjust the retrieval weight of memory entries, the computing device first reads the vector data and metadata information corresponding to the target memory entry from the vector database. Specifically, this read operation can be implemented through the query interface provided by the vector database, with the query condition being the unique identifier of the target memory entry. The result returned by the query interface includes the vector representation of the memory entry and associated metadata stored in the vector database, such as text content, creation time, and tags. Then, in the application layer memory of the computing device, the read metadata information is modified, specifically updating the stored weight values. The computing device can use dictionaries or mapping data structures provided by any programming language (e.g., Python) to represent and modify the metadata. The modified metadata reflects the adjustment of the retrieval weight of the memory entry. Next, the computing device rewrites the modified metadata and the original vector data as a whole into the vector database. Specifically, the computing device calls the update interface provided by the vector database to write a new data entry containing the updated metadata into the vector database. This update operation overwrites the original data entry, thereby realizing the adjustment of the retrieval weight of the memory entry. In some other alternative implementations, modifications to metadata and rewriting of vector data can be achieved by calling the atomic update interface provided by the vector database to ensure data consistency.
[0135] Through the above scheme, this embodiment can utilize the vector storage and approximate retrieval capabilities provided by the vector database to achieve efficient management and dynamic adjustment of memory entries, thereby better supporting the memory needs of AI agents in long-term tasks.
[0136] In one specific implementation, based on the above embodiments, the adapter receives search results from a vector database. These results include a cosine similarity score, calculated by the vector database, representing semantic similarity, and metadata for the corresponding memory entry. Specifically, the metadata includes a pre-stored weight value representing the degree of the memory entry. The adapter then substitutes the cosine similarity score and the weight value into a preset calculation formula to calculate a final ranking score. Specifically, the calculation formula can be: Final Ranking Score = Cosine Similarity Score (1 + Weight Value). Next, the adapter uses this final ranking score to rank all search results and returns the ranked results to the upper-layer application. In other optional implementations, the above calculation formula can adopt different functional forms, such as using weighted average, exponential weighting, etc., to fuse the semantic similarity score and the weight value; alternatively, the weight value can also be mapped to a specific numerical range using a preset normalization function before participating in the calculation.
[0137] Through the above scheme, this embodiment can perform more refined sorting control on the retrieval results of the vector database, so that in addition to semantic relevance, the sorting results can be dynamically adjusted according to the degree of memory of the items, thereby improving the accuracy and practicality of the retrieval results.
[0138] In one specific implementation, if the memory bank of the long-running task AI agent uses a relational database (e.g., PostgreSQL) as the backend storage, and the current operation to be performed is a merge operation of multiple memory entries, then the specific steps for executing the backend operation instruction are as follows:
[0139] First, initiate a database transaction. Specifically, this is done by executing the `BEGINTRANSACTION;` statement through the database connection object. The purpose of initiating a transaction is to ensure the atomicity of subsequent database operations—either all operations execute successfully or all are rolled back—thereby preventing data inconsistencies.
[0140] Then, within the database transaction, the following operations are performed sequentially:
[0141] Specifically, first, a SELECT statement is executed to read the contents of multiple target memory entries. Assuming the memory entries to be merged have IDs of memory_id_1 and memory_id_2, the executed SQL statement might look like this:
[0142] SELECT id, text, metadata FROM memories WHERE id IN ('memory_id_1', 'memory_id_2');
[0143] This statement is used to read the id, text (text content), and metadata fields of these memory entries from the memories table and store the results in the memory of the computing device.
[0144] Next, a large language model (LLM) is invoked to generate a new, integrated summary from the read content. Specifically, the text fields and related metadata of multiple memory entries read from the database are passed to the pre-trained LLM, prompting it to integrate this content and generate a new, more concise text summary. For example, a prompt like the following could be sent to the LLM: "Please combine the following content into a coherent summary while retaining information:"
[0145] Memory entry 1: {text corresponding to memory_id_1}
[0146] Memory entry 2: {text corresponding to memory_id_2}
[0147] Upon receiving this prompt, LLM will generate a new text as the content of the merged memory entry.
[0148] Then, execute the INSERT statement to write the new content generated by the LLM as a new memory entry into the memory bank. For example, the following SQL statement can be executed:
[0149] INSERT INTO memories (text, metadata, created_at) VALUES ('{new text generated by LLM}', '{merged metadata}', NOW());
[0150] This statement writes the new text content, the merged metadata (e.g., a list of IDs of the original memory entries), and the creation time to the memories table.
[0151] Next, execute an UPDATE or DELETE statement to process multiple target memory entries. To preserve the historical record of the original memory entries, you can choose to execute an UPDATE statement to mark these memory entries as "merged" or "deleted" instead of deleting them directly. For example, you can execute the following SQL statement:
[0152] UPDATE memories SET status = 'merged', merged_into = '{new memory entry ID}' WHERE id IN ('memory_id_1', 'memory_id_2');
[0153] This statement updates the status field of the original memory entry to merged and sets the merged_into field to the ID of the new memory entry, indicating that these memory entries have been merged into the new memory entry.
[0154] Finally, commit the database transaction. Specifically, execute the COMMIT statement through the database connection object. If any of the above steps fails, execute the ROLLBACK statement to roll back all operations and ensure data consistency.
[0155] In other alternative implementations, the SQL statements used to initiate and commit database transactions can be tailored to different relational database management systems (such as MySQL, SQL Server, etc.). For example, in MySQL, `START TRANSACTION;` can be used instead of `BEGIN TRANSACTION;`. Similarly, LLM can be replaced with other models that have text digest capabilities, such as BART or T5. LLM can also be deployed as a native model or invoked via API. The metadata merging method can also be replaced with other strategies, such as using metadata from master memory entries or merging all metadata. The field names used for soft deletes can also be replaced with other names.
[0156] Through the above approach, this embodiment can ensure data consistency when performing merge operations in a relational database, while using LLM to generate high-quality merged content, thereby improving the quality of the database memory and retrieval efficiency.
[0157] In one specific implementation, when the received natural language instruction indicates that a complex task involving multiple operation steps needs to be performed, the conversion module does not directly generate a single structured operation instruction, but generates a structured list of memorized operation instructions.
[0158] First, the conversion module identifies the multiple subtasks or operation steps contained in the complex natural language instruction. Specifically, natural language processing techniques (such as dependency parsing and named entity recognition) can be used to decompose the instruction into smaller semantic units, each corresponding to a basic operation. Then, for each subtask or operation step, the conversion module calls a language model to convert it into a structured memory operation instruction conforming to the Unified Memory Operations Language specification. These instructions are encapsulated in an ordered list, where each element corresponds to a structured memory operation instruction, arranged according to their execution order in the original complex instruction. Next, the verification module, parsing module, adaptation module, and execution module process each structured memory operation instruction in the list sequentially, according to the list's order. That is, the next instruction in the list is only processed after the previous structured memory operation instruction has been successfully executed. The execution result of the instruction (such as the retrieved memory entry or the updated database state) can be passed as context information to the processing of subsequent instructions. In some optional implementations, concurrent processing can also be used, that is, multiple instructions in the list can be processed simultaneously while ensuring that there are no dependencies between operations, in order to improve overall processing efficiency.
[0159] Through the above solution, this embodiment can ensure that each operation step of a complex instruction can be executed precisely in a predetermined order, thus guaranteeing the integrity and logical correctness of the task.
[0160] In one specific implementation, the various methods for specifying the operation range in the target field can be implemented as follows: For specifying by the unique identifier of the memory entry, after receiving the structured operation instruction containing the target field, the adapter parses the identifier list from the target field. Specifically, if the backend system is a relational database, an SQL query statement containing a WHERE id IN (...) clause is generated to accurately locate the memory entry to be operated on. For specifying by filtering conditions containing tags, time ranges, or weight ranges, the validation module passes the filtering conditions to the adapter after completing syntax validation. The adapter converts these filtering conditions into the native query statement of the backend system. For example, if the backend is a vector database, the tags are converted into metadata filtering expressions; if the backend is a relational database, the time range and weight range are converted into BETWEEN and comparison operators in the WHERE clause. For specifying by semantic search conditions containing query intent, the conversion module passes the query intent to the adapter. The adapter first uses the similarity search function of the vector database to obtain a list of memory entry IDs most relevant to the query intent; then, in subsequent operations, only memory entries in this ID list are processed. In some other alternative implementations, when the backend system does not support filtering using semantic search conditions directly, a full semantic search of the entire database can be performed first to obtain a sorted list of memory entries, and then only the Top-N results can be taken for subsequent operations.
[0161] Through the above solution, this embodiment can support more flexible and refined management of memory entries. It can select the most suitable designation method according to different scenarios and needs, thereby improving the efficiency and accuracy of memory operations.
[0162] In one specific implementation, the method of the present invention can process complex natural language instructions containing multiple operation steps and transform them into a structured, ordered list of memorized operation instructions. A specific example is given below.
[0163] First, the receiving module receives a complex natural language instruction from the user: "Find emails about battery technology from the past week and combine them into a summary."
[0164] Next, the language model of the conversion module recognizes that the instruction contains two consecutive operational intentions: the first is "retrieve," and the second is "merge." Therefore, the conversion module generates an ordered list containing the two structured memory operation instructions, with the following JSON content: [
[0166] {
[0167] "stage": "RET",
[0168] "op": "Retrieve",
[0169] "target": {
[0170] "filter": {
[0171] "type": "email",
[0172] "has_tags": ["battery technology"],
[0173] "time_range": {"relative": "last", "amount": 7, "unit": "days"}
[0174] }
[0175] }
[0176] },
[0177] {
[0178] "stage": "STO",
[0179] "op": "Merge",
[0180] "target": { "ids": []},
[0181] "args": {
[0182] "strategy": "merge_into_primary",
[0183] "primary_id": ""
[0184] }
[0185] } ]
[0187] The ordered list is then passed to subsequent processing modules. The system will process each instruction sequentially according to the list's order.
[0188] First, the first Retrieve instruction in the list is verified, parsed, adapted, and executed. After the execution module performs the retrieval operation, it returns a result containing a list of unique identifiers for email memory entries that meet the criteria, such as ["email_01", "email_05", "email_12"].
[0189] The execution result is not returned directly to the user, but is used as context information for the next operation. The system will dynamically populate the target.ids field of the second Merge instruction in the ordered list with the result (i.e., ["email_01", "email_05", "email_12"]), and can select one of them (e.g., the latest email_12) as args.primary_id.
[0190] Then, the system verifies, parses, adapts, and executes the dynamically populated and improved Merge instruction.
[0191] By using the output of the previous operation as the input of the next operation and executing the instruction list in sequence, this invention can reliably complete complex multi-step tasks.
[0192] This invention provides a memory operation processing system based on natural language instructions. This system is applied to the memory management of long-duration task AI agents and is used to implement the memory operation processing method based on natural language instructions described in any of the above embodiments, such as... Figure 2 As shown, the system includes: a receiving module M100, a conversion module M200, a verification module M300, a parsing module M400, an adaptation module M500, and an execution module M400.
[0193] The receiving module M100 is configured to receive natural language instructions continuously generated by a long-running AI agent. In one embodiment, the receiving module M100 can be an API interface, such as an HTTP interface implemented based on a RESTful architecture, through which the long-running AI agent sends natural language instructions in JSON format. In another implementation, the receiving module M100 can also be a message queue, such as Apache Kafka, where the long-running AI agent pushes natural language instructions as messages to the message queue. The receiving module M100 then passes the received natural language instructions to the conversion module M200.
[0194] The conversion module M200 is configured to invoke a language model and convert natural language instructions into structured memory operation instructions based on an instruction format specification that includes various memory operation types. Specifically, the conversion module M200 may include one or more pre-trained large language models (LLMs), such as GPT-3 or a later version. The conversion module M200 also includes a prompt engineering component, which is responsible for constructing structured prompts sent to the LLM. These structured prompts contain a description of the instruction format specification and a small number of example input-output pairs to guide the LLM in converting the natural language instructions into compliant structured instructions. In other optional implementations, the conversion module M200 may integrate multiple LLMs, for example, through voting or ensemble learning, to improve the accuracy and robustness of the conversion results.
[0195] The verification module M300 is configured to verify structured memory operation instructions to confirm that the structured memory operation instructions conform to the preset syntax rules of the instruction format specification. The verification module M300 includes a syntax validator that verifies the format and content of the structured instructions based on predefined rules (such as JSON Schema). For example, the verification module M300 can check whether the structured instruction contains all required fields and whether the field value types are correct. In one embodiment, if verification fails, the verification module M300 returns an error message to the long-running task AI agent and refuses to execute the instruction. In some other optional implementations, the verification module M300 can attempt to automatically correct some common errors, such as converting string-type numbers to numeric types.
[0196] The parsing module M400 is configured to parse verified structured memory operation instructions into standardized operation objects. The parsing module M400 includes one or more parsers, each corresponding to a specific type of structured instruction. The parser is responsible for extracting the fields from the structured instructions and assigning them to the corresponding attributes of the standardized operation objects. The standardized operation objects can be implemented using object-oriented programming, for example, defining a base class `MemoryOperation` and then defining a subclass for each operation type (such as `Encode`, `Retrieve`). In some alternative implementations, the parsing module M400 can use reflection to dynamically create the corresponding operation objects based on the operation type in the structured instructions.
[0197] The M500 adapter module is configured to translate standardized operation objects into executable backend operation instructions based on the backend system used by the memory of the long-running AI agent. The M500 adapter module includes multiple adapters, each corresponding to a specific backend system. For example, if the backend system is a relational database (such as MySQL), the M500 adapter module will select the relational database adapter; if the backend system is a vector database (such as Milvus), the M500 adapter module will select the vector database adapter. The adapters are responsible for converting standardized operation objects into instructions that the backend system can understand and execute. For example, the relational database adapter will convert the operation objects into SQL statements, while the vector database adapter will convert the operation objects into vector database API calls. In some alternative implementations, the adapters can adopt a plug-in architecture for easy expansion to support new backend systems.
[0198] The execution module M400 is configured to execute backend operation instructions to process memory entries in the memory bank. The execution module M400 includes one or more executors, each responsible for interacting with a specific backend system. The executor receives backend operation instructions generated by the adapter and sends them to the backend system for execution. The executor also processes the results returned by the backend system and converts them into a unified format within the system. In one embodiment, the executor may employ connection pooling technology to improve the efficiency of interaction with the backend system. In some other alternative implementations, the execution module M400 may support transaction operations to guarantee the atomicity of multiple backend operation instructions.
[0199] The aforementioned receiving module M100, conversion module M200, verification module M300, parsing module M400, adaptation module M500, and execution module M400 cooperate and work together to form a complete memory operation processing pipeline. Natural language instructions generated by the long-duration task AI agent are first received by the receiving module M100, then converted into structured memory operation instructions by the conversion module M200, verified by the verification module M300 to ensure the legality of the instructions, parsed by the parsing module M400 into standardized operation objects, translated into executable instructions for the backend system by the adaptation module M500, and finally sent to the backend system for execution by the execution module M400 to complete the modification or query of the memory. This cooperative relationship solves the ambiguity and uncertainty problems in the conversion process from natural language instructions to machine instructions in existing technologies, improving the accuracy and reliability of memory operations.
[0200] Through the above scheme, this embodiment can transform the natural language instructions generated by the long-running AI agent into a series of accurate and reliable database operations, thereby achieving efficient, accurate, and consistent management of the database memory. Compared with the prior art, this embodiment, through modular design, enables the system to have good scalability and maintainability; through standardized operation objects and unified instruction formats, it reduces the coupling between various modules of the system; and through the verification of natural language instructions, it improves the robustness and security of the system.
[0201] In one specific implementation, the instruction format specification utilized by the system defines various memory operation types designed to cover diverse needs in the memory management process. On one hand, the instruction format specification includes at least one priority adjustment operation, used to adjust the retrieval weight of memory entries, thereby affecting their ranking in subsequent searches. In one implementation, the priority adjustment operation can be implemented by directly modifying the weight field in the memory entry's metadata. In another implementation, it can be implemented by adjusting the vector representation of the memory entry in the vector database. On the other hand, the instruction format specification also includes at least one structure adjustment operation, used to integrate or decompose memory entry content, thereby optimizing the memory bank's structure and reducing redundant information. For example, the structure adjustment operation can be used to merge multiple semantically similar memory entries, or to split a memory entry containing multiple topics into multiple smaller, single-topic memory entries. In some alternative implementations, the priority adjustment operation can also be implemented by modifying the memory entry's expiration time, and the structure adjustment operation can also be implemented by classifying and clustering memory entries.
[0202] Through the above solution, this embodiment can provide richer memory management functions, enabling the AI agent to more flexibly control the degree and organization of memory items, thereby improving the performance of the AI agent in long-term tasks.
[0203] In a preferred embodiment, the system further includes a separate intelligent scheduling module designed to address the memory priority drift and memory redundancy issues faced by long-running task AI agents. This intelligent scheduling module operates independently of direct user commands and can proactively and automatically generate and trigger advanced memory operations based on system status and task context. This intelligent scheduling module may include, but is not limited to, the following two sub-modules:
[0204] The target relevance detection submodule dynamically identifies and prioritizes key memories strongly correlated with the core objectives of long-term tasks. Its implementation includes the following steps:
[0205] First, during the long-duration task initialization phase, the system obtains an initial natural language description of the long-duration task (e.g., "Write an annual analysis report on the new energy vehicle market in 2025, focusing on solid-state battery technology and supply chain changes"), and calls a pre-trained sentence embedding model (e.g., Sentence-BERT) to transform the descriptive text into one or more pre-defined target vectors that can represent the core objectives of the task. .
[0206] Secondly, during the execution of long-running tasks, whenever the system receives a new natural language instruction, the target correlation detection submodule performs the following operations:
[0207] Using the same sentence embedding model as described above, the instruction embedding vector corresponding to this natural language instruction is calculated. .
[0208] Calculate instruction embedding vector With the preset target vector Cosine similarity between The calculation formula is:
[0209]
[0210] in, Represents the dot product of vectors. and Let represent the Euclidean norms of the two vectors respectively.
[0211] The calculated cosine similarity With a first preset threshold The comparison is performed. This threshold is a value used to determine strong correlation, and its value can be dynamically adjusted between 0.7 and 0.95. In this embodiment, it is preferably 0.85.
[0212] When it is determined When this submodule determines that the current instruction is closely related to the core task objective, it sends a trigger signal to the conversion module. This trigger signal contains a unique identifier (ID) for the memory entry generated from the current natural language instruction, and a suggested weight increment value (e.g., 0.2). Upon receiving this signal, the conversion module generates an additional structured instruction for a Promote operation and adds it to the sequence of instructions to be processed.
[0213] The memory redundancy detection submodule is responsible for periodically scanning the memory, automatically detecting and integrating redundant memory entries to optimize the memory structure. Its implementation includes the following steps:
[0214] First, the submodule is configured to run periodically in the background (e.g., set to execute at 2 AM daily) or be triggered by a specific event (e.g., a broad search that returns more than 20 results at a time).
[0215] Secondly, when this submodule runs, it performs the following operations:
[0216] Select a set of memory entries to be tested from the memory bank, such as all memory entries added in the past 24 hours.
[0217] A clustering algorithm, such as DBSCAN, is used to cluster the embedding vectors of all entries in the set of memories to be tested. The DBSCAN algorithm clusters based on neighborhood density, which can effectively discover clusters of arbitrary shapes and identify noise points.
[0218] For each cluster generated by the algorithm, if the number of memory entries contained in the cluster is greater than 1, the submodule will further calculate the average semantic similarity between all pairwise memory entries in the cluster. .
[0219] The calculated average semantic similarity With a second preset threshold A comparison is then made. This threshold is a value used to determine the high redundancy of content, and its value can be dynamically adjusted between 0.8 and 0.99. In this embodiment, it is preferably 0.9.
[0220] When it is determined When a node is selected, the submodule determines that all memory entries within that cluster are redundant. It then sends a trigger signal to the transformation module. This trigger signal contains a list of IDs for all memory entries within the cluster, and a suggested primary_id for merging (e.g., selecting the entry with the most recent timestamp in the cluster). Upon receiving this signal, the transformation module generates a structured instruction for the Merge operation.
[0221] In some implementations, a task phase status linkage module is also included, the specific implementation of which is as follows:
[0222] This module uses a message subscription mechanism to subscribe to state change events published by the task management module inside the AI agent.
[0223] When the status of a subtask in the task management module is updated to "completed", the task management module will publish a status change message containing the unique identifier of that subtask.
[0224] Upon receiving the message, the linkage module immediately queries the memory bank for all memory entries related to the subtask based on the subtask's unique identifier (e.g., by associating them through tags or metadata).
[0225] For all relevant memory entries retrieved, this module generates one or more demote instructions in the priority adjustment operation and sends these instructions to subsequent processing flows to reduce the retrieval weight of these memories related to completed tasks.
[0226] Through the collaborative work of the above sub-modules, the intelligent scheduling module of the present invention can proactively and automatically perform dynamic maintenance on the memory bank, effectively solving the problems of memory priority drift and redundancy in long-term tasks.
[0227] In one specific implementation, when the backend system is a vector database and the execution module M400 receives a backend operation instruction to increase the retrieval weight, the adaptation module M500 first retrieves the vector data and metadata corresponding to the memory entry from the vector database based on the unique identifier of the target memory entry. The metadata includes, but is not limited to, text content, creation time, tags, and weight values. The execution module M400 then directly reads and modifies the values representing the weights in the metadata in the system's application layer memory. Modification methods include, but are not limited to, directly assigning new weight values or making incremental adjustments based on the original weight values. The adjusted metadata, along with the original vector data, is then atomically rewritten into the vector database by calling the update interface provided by the vector database. In subsequent retrieval processes, the adaptation module M500 obtains the similarity scores and corresponding weight values between vectors from the retrieval results of the vector database. Then, the similarity scores and weight values are input into a preset function to obtain the final ranking score of the target memory entry. The preset function can be a linear function, an exponential function, or a logarithmic function. For example, in one embodiment, the preset function is a linear function, and the final ranking score is equal to the sum of the similarity score and the weight value; in another embodiment, the preset function is an exponential function, and the final ranking score is equal to the similarity score multiplied by an exponent with the weight value as the base. In some other optional implementations, the adaptation module M500 can also adjust the final ranking score through other weighting strategies, such as setting a weight threshold, and only weighting the similarity score when the weight value exceeds the threshold; or, adjusting the similarity score using different weighting coefficients according to the magnitude of the weight value.
[0228] Through the above scheme, this embodiment can utilize the characteristics of vector databases to adjust the retrieval weights of memory entries while ensuring retrieval efficiency and accuracy, and provide a more flexible sorting strategy for subsequent retrievals.
[0229] In some optional embodiments, the backend system is a relational database (e.g., PostgreSQL), and when an operation to merge multiple memory entries needs to be performed, the adapter module M500 and the execution module M600 will guarantee the atomicity of the operation through a database transaction. The specific execution steps are as follows:
[0230] First, the execution module starts a database transaction, for example, by executing the BEGIN TRANSACTION; statement.
[0231] Within a database transaction, perform the following operations sequentially:
[0232] The first step is to execute a SELECT statement to read the contents of multiple target memory entries, for example: SELECT id,text, metadata FROM memories WHERE id IN ('memory_id_1', 'memory_id_2');.
[0233] The second step involves the adaptation module M500 sending the text content of multiple memory entries, along with a preset integration instruction (e.g., "Please merge the following content into a coherent summary"), to the language model in the conversion module M200 to generate the integrated new content.
[0234] The third step is to execute an INSERT statement to write the new content generated by the language model into the memory bank as a new memory entry, for example: INSERT INTO memories (text, metadata) VALUES ('{new text generated by LLM}', '{merged metadata}');.
[0235] The fourth step is to execute an UPDATE statement to process the original multiple target memory entries, for example, by marking their status as "merged" instead of deleting them directly, in order to preserve the operation history: UPDATE memories SET status = 'merged' WHERE id IN ('memory_id_1', 'memory_id_2');.
[0236] Finally, if all the above steps have been executed successfully, the database transaction is committed, for example, by executing a COMMIT statement. If an error occurs at any step, a ROLLBACK statement is executed to roll back all operations performed to ensure data consistency.
[0237] In some optional embodiments, the backend system is a vector database, and when backend operation instructions are used to adjust the retrieval weight of memory entries (e.g., to perform a boosting operation), since vector databases typically do not support direct atomic updates to metadata, the adaptation module M500 and the execution module M600 employ a "read-modify-rewrite" strategy combined with retrieval-time score modulation. The specific execution steps are as follows:
[0238] First, the execution module reads the corresponding vector and metadata from the vector database based on the unique identifier of the target memory entry.
[0239] Then, in the application layer memory of the computing device, the adaptation module M500 modifies the weight values in the metadata according to the instructions. For example, for a boost operation, the original weight values in the metadata are added with a preset increment.
[0240] Next, the execution module M600 treats the modified metadata and the original vector as a whole and rewrites it into the vector database by calling the vector database's update or insert interface (such as upsert). This operation overwrites the original data entries.
[0241] When performing semantic retrieval via the vector database, the adaptation module will perform an additional processing step after obtaining the retrieval results to ensure the modified weight values take effect. Specifically, the original score representing semantic similarity returned by the vector database and the weight values read from the metadata are subjected to a preset calculation to generate a final ranking score. In a preferred embodiment, the calculation formula for this preset calculation is as follows:
[0242]
[0243] in, Represents the final sort score. The original cosine similarity score is calculated from the vector database, and w represents the weight value read from the metadata. In this embodiment, the weight value w can be set in the range of [0, +∞). When w=0, it means that the memory entry has no additional weight; when w>0, the larger the value, the more significant the improvement effect on the original cosine similarity score, and thus the higher it ranks in the sorting results.
[0244] Through this approach, the present invention can reliably achieve dynamic adjustment of the retrieval weight of memory entries without relying on the native support of the vector database.
[0245] In some optional embodiments, the system can also process user-inputted, ambiguous natural language commands and ensure the accuracy of the final generated operation commands through a clarifying interaction. A specific example is provided below.
[0246] First, the receiving module M100 receives a vague natural language instruction input by the user: "Find all the relevant information for that project report and increase its priority."
[0247] Next, the instruction is passed to the conversion module M200. Before being formally converted into a structured memory operation instruction, an intent recognition submodule (which can be implemented based on a pre-trained natural language understanding model such as BERT) first performs a preliminary analysis of the instruction. This submodule identifies at least two ambiguities in the instruction: first, "that project report" is an ambiguous referent, and there may be multiple memories related to project reports in the system; second, "turn it up a little" is an imprecise description of degree. The analysis results of the intent recognition submodule (e.g., structured data containing the type and location of ambiguities) are then passed to the language model.
[0248] Then, the language model in the conversion module M200 generates one or more specific clarifying questions aimed at dispelling ambiguity, based on the received ambiguity analysis results. In this embodiment, the language model might generate the following clarifying questions: "Please confirm: 1. Are you referring to the '2025 New Energy Vehicle Market Analysis Report'? 2. To what priority level would you like to prioritize the relevant information? (A. High, corresponding weight increment 0.2 B. Urgent, corresponding weight increment 0.4)"
[0249] The clarifying question is presented to the user through an AI-assisted user interface.
[0250] Subsequently, the receiving module M100 receives a clarifying reply from the user, such as: "Yes, choose A."
[0251] Finally, the conversion module M200 processes the user's original vague instruction ("Increase the project report... a little"), the system's clarifying question, and the user's clarifying response ("Yes, select A") as a complete context. The language model can then accurately parse the user's full intent and generate a structured, ordered list of memory operation instructions containing two operations with clearly defined parameters. The JSON content of this list is as follows: [
[0253] {
[0254] "stage": "RET",
[0255] "op": "Retrieve",
[0256] "target": {
[0257] "search": {
[0258] "intent": { "query":"Information related to the 2025 New Energy Vehicle Market Analysis Report"}
[0259] }
[0260] }
[0261] },
[0262] {
[0263] "stage": "STO",
[0264] "op": "Promote",
[0265] "target": { "ids": []},
[0266] "args": { "weight_delta": 0.2}
[0267] } ]
[0269] In this case, the target.ids field of the second Promote directive will be dynamically filled by the execution result of the first Retrieve directive.
[0270] Through the complete process including clarification interaction described above, the present invention effectively solves the problem of erroneous operation that may be caused by the ambiguity of natural language command intent, and greatly improves the accuracy of command conversion and the reliability and user experience of the entire system.
[0271] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of the present invention, and all such modifications and substitutions should be considered within the scope of protection of the present invention.
Claims
1. A memory operation processing method based on natural language instructions, characterized in that, Memory management applied to long-duration AI agents, and performed by computing devices, includes: Receive natural language instructions continuously generated by the AI agent for long-duration tasks; The language model is invoked, and the natural language instructions are transformed into structured memory operation instructions according to the instruction format specification that includes multiple memory operation types. The structured memory operation instructions are verified to confirm that they conform to the preset syntax rules of the instruction format specification. The verified structured memory operation instructions are parsed into standardized operation objects; Based on the backend system used by the memory bank of the long-duration task AI agent, the standardized operation objects are translated into backend operation instructions that can be executed by the backend system. The backend operation instructions are executed to process the memory entries in the memory bank.
2. The method according to claim 1, characterized in that, Among the various memory operation types defined in the instruction format specification, there is at least one priority adjustment operation for adjusting the retrieval weight of memory entries, and at least one structural adjustment operation for integrating or decomposing the content of memory entries.
3. The method according to claim 2, characterized in that, The priority adjustment operation is either an upgrade operation or a downgrade operation; the structure adjustment operation is either a merge operation or a split operation.
4. The method according to claim 3, characterized in that, The method further includes: Calculate the semantic similarity between the embedding vector of the natural language instruction and the preset vector representing the core objective of the long-term task; When the semantic similarity is higher than a first preset threshold, the instruction for the boosting operation is generated.
5. The method according to claim 3, characterized in that, The method further includes: After performing a retrieval based on the query intent, the semantic similarity between the returned memory entries is calculated; When the semantic similarity between the multiple memory entries is higher than a second preset threshold, an instruction for the merging operation is generated.
6. The method according to claim 3, characterized in that, The method further includes: When a signal indicating that the status of a subtask in the long-running task has changed to "completed" is received, an instruction for the downgrade operation is generated to act on the memory entry associated with the subtask.
7. The method according to claim 3, characterized in that, The method further includes: When a complex natural language instruction containing multiple decomposable steps is received, instructions for the splitting operation are generated to decompose a single memory entry corresponding to the complex natural language instruction into multiple sub-memory entries corresponding to the decomposable steps.
8. The method according to claim 1, characterized in that, The backend system is a vector database, and when the backend operation instruction is used to adjust the retrieval weight of the memory entry, the step of executing the backend operation instruction includes: Read the vector and metadata corresponding to the target memory entry in the vector database; In the application layer memory of the computing device, modify the weight value within the metadata; The modified metadata and the vector are then rewritten into the vector database as a whole.
9. The method according to claim 8, characterized in that, The method further includes: When performing semantic retrieval through the vector database, the retrieved semantic similarity score is calculated in a preset manner with the weight value in the metadata to generate the final ranking score. Finally, commit the database transaction.
10. A memory operation processing system based on natural language instructions, characterized in that, This system is applied to memory management of long-duration AI agents and includes: The receiving module is used to receive natural language instructions continuously generated by the long-term task AI agent; The conversion module is configured to call the language model and convert the natural language instructions into structured memory operation instructions according to the instruction format specification that includes multiple memory operation types. The verification module is configured to verify the structured memory operation instructions to confirm that the structured memory operation instructions conform to the preset syntax rules of the instruction format specification. The parsing module is configured to parse the verified structured memory operation instructions into standardized operation objects; The adaptation module is configured to translate the standardized operation objects into backend operation instructions executable by the backend system used by the memory bank of the long-term task AI agent. The execution module is configured to execute the backend operation instructions to process memory entries in the memory bank.