A method, device, and medium for acquiring LLM context information for intelligent agents.
By detecting historical interaction records of the current session in the agent and performing intent recognition and classification, and combining short-term and long-term memory data to generate LLM context information, the problems of information loss and resource waste in the prior art are solved, and the response accuracy and efficiency of the agent are improved.
Patent Information
- Application Number
- CN202611620240.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-20
- Publication Date
- 2026-11-17
AI Technical Summary
In existing technologies, agents based on large language models (LLM) are prone to losing key early interaction information when generating contextual information, resulting in wasted resources and low accuracy, which affects response accuracy and task execution efficiency.
By detecting whether there are historical interaction records of the current session in the short-term memory data of the agent, key context information is obtained and intent is identified and classified. The user profile is extracted based on the intent type. LLM context information is generated by combining long-term memory data. User profile fusion is only performed when the intent is strongly correlated with personalized preferences.
It improves the accuracy of LLM context information, avoids resource waste, and enhances the response accuracy and task execution efficiency of the agent.
Smart Images

Figure CN123115406A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of large language models, and in particular to a method, device and medium for obtaining LLM context information for intelligent agents. Background Technology
[0002] With the rapid development of natural language processing technology, intelligent agents built based on large language models (LLMs) are widely used in dialogue systems, personal assistants, intelligent customer service, and other scenarios. These intelligent agents understand the user's natural language input, combine it with contextual information used for LLM (i.e., LLM context information) to perform reasoning, and call on the corresponding tools to complete the task. In existing technologies, LLM context information is usually generated by using a sliding window approach, which involves splicing the user's recent historical interaction records and user profile to generate LLM context information.
[0003] However, using a sliding window approach to generate LLM context information can lead to the loss of early key interaction information, affecting the reference value of the LLM context information. Furthermore, for each question in the session, during the task of generating the corresponding answer, regardless of whether the user's intent is related to personalized preferences, the complete user profile is indiscriminately spliced with historical interaction records to generate LLM context information. Therefore, it can be seen that generating LLM context information based on the above method not only easily leads to resource waste but also results in low accuracy of the generated LLM context information, thereby affecting the agent's response accuracy and task execution efficiency. Summary of the Invention
[0004] To address the aforementioned technical problem, the technical solution adopted in this application is as follows:
[0005] According to a first aspect of this application, a method for obtaining LLM context information for an intelligent agent is provided, the method comprising the following steps:
[0006] S1. When the agent receives the question text B currently input by user A, it checks whether there is a historical interaction record belonging to the current session D in the agent's short-term memory data C.
[0007] S2. If there are historical interaction records belonging to D in C, then based on C, obtain the key context information corresponding to B, and perform intent recognition and intent classification processing on B through the first LLM to obtain the intent type E of the current user intent; where E is the first intent type or the second intent type; the first intent type indicates that the current user intent is strongly correlated with the user's personalized preferences; the second intent type indicates that the current user intent is weakly correlated with the user's personalized preferences.
[0008] S3. When E is the first intent type, the user profile is extracted from the key context information through the first LLM to obtain the intermediate user profile corresponding to A.
[0009] S4. Based on the agent's long-term memory data, obtain the initial user profile corresponding to A, the tool calling experience text corresponding to B, and the task planning experience text.
[0010] S5. Merge the intermediate user profile corresponding to A with the initial user profile corresponding to A to obtain the temporary user profile corresponding to A, and generate LLM context information based on the temporary user profile corresponding to A, the key context information corresponding to B, the tool call experience text and task planning experience text corresponding to B.
[0011] According to a second aspect of this application, a non-transitory computer-readable storage medium is provided, which stores at least one instruction or at least one program, wherein the at least one instruction or at least one program is loaded and executed by a processor to implement the above-described method for obtaining LLM context information for an intelligent agent.
[0012] According to a third aspect of this application, an electronic device is provided, including a processor and the aforementioned non-transitory computer-readable storage medium.
[0013] This application has at least the following beneficial effects:
[0014] This application provides a method, device, and medium for acquiring LLM context information for an intelligent agent. The method involves the following steps: When the intelligent agent receives the question text B currently input by user A, it detects whether there is a historical interaction record belonging to the current session D in the agent's short-term memory data C. If there is a historical interaction record belonging to D in C, then based on C, it acquires the key context information corresponding to B, and performs intent recognition and intent classification processing on B through a first LLM to obtain the intent type E of the current user's intent. When E is the first intent type, it extracts a user profile from the key context information through the first LLM to obtain an intermediate user profile corresponding to A. Based on the agent's long-term memory data, it acquires the initial user profile corresponding to A, the tool call experience text corresponding to B, and the task planning experience text. It then merges the intermediate user profile corresponding to A with the initial user profile corresponding to A to obtain a temporary user profile corresponding to A, and generates LLM context information based on the temporary user profile corresponding to A, the key context information corresponding to B, the tool call experience text corresponding to B, and the task planning experience text. As can be seen, this application combines not only short-term memory data but also long-term memory data when generating LLM context information. Furthermore, it performs intent recognition and intent classification on each question text in the conversation. Only when the user's intent type is the first intent type, i.e., the user's intent is strongly correlated with the user's personalized preferences, does it combine temporary user profiles to generate LLM context information. This approach preserves key early interaction information while avoiding blindly piecing together user profiles when generating LLM context information. It can improve the accuracy of LLM context information, avoid resource waste, and effectively improve the agent's response accuracy and task execution efficiency. Attached Figure Description
[0015] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 A flowchart illustrating an LLM context information acquisition method for an intelligent agent, provided in an embodiment of this application. Detailed Implementation
[0017] The technical solutions in the embodiments of this application will be clearly and completely described below. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0018] It is worth noting that in the following description, specific details such as particular system structures and techniques are set forth for illustrative purposes rather than for limiting purposes, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application can also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods are omitted so as not to obscure the description of this application with unnecessary details.
[0019] Embodiments of this application provide a method for obtaining LLM context information for an intelligent agent, the method comprising the following steps, such as... Figure 1 As shown:
[0020] S1. When the agent receives the question text B currently input by user A, it checks whether there is a historical interaction record belonging to the current session D in the agent's short-term memory data C.
[0021] Specifically, in step S1, C is searched based on the current session identifier corresponding to B to detect whether there are any historical interaction records belonging to D in C.
[0022] Furthermore, if there is a historical interaction record in C whose corresponding session identifier is consistent with the current session identifier of B, then it is determined that there is a historical interaction record belonging to D in C; otherwise, it is determined that there is no historical interaction record belonging to D in C.
[0023] Specifically, the session identifier is a unique identifier for the session.
[0024] S2. If there are historical interaction records belonging to D in C, then based on C, obtain the key context information corresponding to B, and perform intent recognition and intent classification processing on B through the first LLM to obtain the intent type E of the current user intent; where E is the first intent type or the second intent type; the first intent type indicates that the current user intent is strongly correlated with the user's personalized preferences; the second intent type indicates that the current user intent is weakly correlated with the user's personalized preferences.
[0025] Specifically, in step S2, intent recognition and intent classification are performed on B through the first LLM to obtain E, including the following steps:
[0026] S201. Concatenate the key context information corresponding to B and the preset prompt words corresponding to the intent recognition task to form the model input text corresponding to the intent recognition task; wherein, as those skilled in the art know, the preset prompt words corresponding to the intent recognition task are preset by those skilled in the art according to actual needs, and are used to guide the LLM to perform the intent recognition task and output the intent recognition result, which will not be described in detail here.
[0027] S202. Input the model input text corresponding to the intent recognition task into the first LLM to obtain the intent recognition result corresponding to B output by the first LLM.
[0028] Specifically, the intent recognition result is natural language text used to describe the user's intent.
[0029] S203. Concatenate the key context information corresponding to B, the intent recognition result corresponding to B, and the preset prompt words corresponding to the intent classification task into the model input text corresponding to the intent classification task; wherein, as those skilled in the art know, the preset prompt words corresponding to the intent classification task are preset by those skilled in the art according to actual needs, and are used to guide the LLM to perform the intent classification task and output the intent classification result, which will not be elaborated here.
[0030] S204. Input the model input text corresponding to the intent classification task into the first LLM to obtain the intent classification result output by the first LLM, and use the intent classification result as E; the intent classification result is either the first intent type or the second intent type.
[0031] Specifically, when E is the first intent type, the representation of generating the answer text corresponding to B needs to be combined with the user profile for personalized reasoning; when E is the second intent type, the representation of generating the answer text corresponding to B does not need to be combined with the user profile for personalized reasoning.
[0032] Through the above steps, for each question text, the first LLM performs intent recognition on B based on B and its corresponding key context information; then, the first LLM classifies B based on B, its corresponding key context information, and the intent recognition result to obtain E. The key context information originates from short-term memory data. While its content reflects the user's behavioral tendencies in the current session, it is compressed due to the limitations of the LLM's input context window. Therefore, the user profile it carries is not a complete user profile but a diluted one, making it difficult to accurately represent the user's personalized preferences. Thus, when E is the first intent type, it indicates that the answer to B is... The generation process is highly dependent on user-personalized information. The diluted user profile in the key context information is insufficient to support high-quality personalized reasoning in LLM, requiring an additional user profile extraction and fusion process. Conversely, if the user profile is diluted in the key context information, it indicates that the answer generation process for B is less dependent on user-personalized information, and the diluted user profile in the key context information can support conventional reasoning without the need to introduce additional user profiles or trigger user profile extraction and fusion processes. This provides a clear criterion for determining whether to trigger user profile extraction and fusion tasks in the future, enabling on-demand splicing of user profiles and avoiding blindly splicing user profiles every time LLM context information is generated, thus saving resources.
[0033] S3. When E is the first intent type, the user profile is extracted from the key context information through the first LLM to obtain the intermediate user profile corresponding to A.
[0034] Specifically, step S3 includes:
[0035] The key context information and the preset prompts corresponding to the user profile extraction task are concatenated to form the model input text corresponding to the user profile extraction task. As those skilled in the art know, the preset prompts corresponding to the user profile extraction task are preset by those skilled in the art according to actual needs, and are used to guide the LLM to perform the user profile extraction task and output structured user profile extraction results. This will not be elaborated further here.
[0036] The input text of the model corresponding to the user profile extraction task is input into the first LLM to obtain the user profile extraction result output by the first LLM, and the user profile extraction result is used as the intermediate user profile corresponding to A; wherein, the user profile extraction result output by the first LLM is structured data, including several user feature labels and the feature value corresponding to each user feature label.
[0037] In another specific embodiment, step S3 includes:
[0038] If the intent categories corresponding to n consecutive historical question texts in D that are temporally adjacent to B are all of the first intent type, then the key context information and the preset prompt words corresponding to the user profile extraction task are concatenated to form the model input text corresponding to the user profile extraction task; n is the preset number trigger threshold corresponding to the user profile extraction task; whereby those skilled in the art know that the preset number trigger threshold corresponding to the user profile extraction task is a threshold preset by those skilled in the art according to actual needs, such as 3, 4, which will not be elaborated here.
[0039] Input the model input text corresponding to the user profile extraction task into the first LLM to obtain the user profile extraction result output by the first LLM, and use the user profile extraction result as the intermediate user profile corresponding to A.
[0040] If a second intent type exists in the intent categories corresponding to n consecutive historical problem texts that are temporally adjacent to B in D, then based on the agent's long-term memory data, the tool invocation experience text and task planning experience text corresponding to B are obtained, and based on the key context information corresponding to B, the tool invocation experience text and task planning experience text corresponding to B are used to generate LLM context information.
[0041] Through the above steps, the user profile extraction task is triggered only when E is the first intent type, and the intent categories corresponding to the n consecutive historical question texts in D that are temporally adjacent to B are all of the first intent type. Frequency control of profile extraction is achieved by setting a preset trigger threshold for the user profile extraction task. Specifically, if the intent types obtained for n+1 consecutive times are all of the first intent type, it indicates that the user continues to exhibit a strong reliance on personalized reasoning in the current session. The user profile implicit in the key contextual information obtained based on short-term memory data has been further diluted, and its representational ability continues to decline. Therefore, a complete user profile needs to be introduced to ensure the reasoning quality of LLM. Otherwise, it indicates that the intent types corresponding to the first intent type in the current session are all of the first intent type. The frequency of the question text has not yet reached the preset threshold, so there is no need to trigger the user profile extraction task. This avoids blindly triggering the user profile extraction task when the first intent type appears in isolation or when personalized needs are not yet fully apparent, thus avoiding frequent and invalid calls and reducing the computational overhead and resource consumption of the first LLM. Furthermore, even when the triggering conditions for the user profile extraction task are not met, LLM context information can still be generated based on short-term memory data and long-term memory data. This preserves key early interaction information and avoids blindly piecing together user profiles when generating LLM context information. This improves the accuracy of LLM context information while avoiding resource waste, effectively improving the agent's response accuracy and task execution efficiency.
[0042] S4. Based on the agent's long-term memory data, obtain the initial user profile corresponding to A, the tool calling experience text corresponding to B, and the task planning experience text.
[0043] Specifically, step S4 includes:
[0044] S401. Use the user profile corresponding to the user identifier of A in the long-term memory data of the agent as the initial user profile corresponding to A.
[0045] S402. Based on the intent recognition result corresponding to B and the trigger condition label corresponding to the tool call experience text in the agent's long-term memory data, obtain the tool call experience text corresponding to B; wherein, the trigger condition label includes the applicable intent description text and the trigger keyword set.
[0046] Specifically, step S402 includes the following steps:
[0047] S4021. For each tool call experience text in the agent's long-term memory data, obtain the semantic feature vector of the applicable intent description text in the trigger condition label of the tool call experience text, and the first vector similarity between it and the semantic feature vector of the intent recognition result corresponding to B; wherein, those skilled in the art know that any method of obtaining the semantic feature vector of text in the prior art is within the protection scope of this invention, for example: obtaining the semantic feature vector of text through the BERT model, which will not be elaborated here.
[0048] Specifically, the first vector similarity value ranges from 0 to 1. The closer the first vector similarity value is to 1, the more similar the two semantic feature vectors are.
[0049] In one specific embodiment, the Euclidean distance between two semantic feature vectors is converted into a value between 0 and 1, and this value is used as the first vector similarity; wherein, the larger the Euclidean distance, the closer the converted value between 0 and 1 is to 0, and the smaller the Euclidean distance, the closer the converted value between 0 and 1 is to 1.
[0050] S4022. Select the tool call experience text corresponding to the first vector similarity greater than the preset similarity threshold as candidate text.
[0051] S4023. Extract keywords from B, the intent recognition results of B, and key context information to obtain the keyword set corresponding to B.
[0052] S4024. For each candidate text, obtain the feature vector of the keyword set in the trigger condition label corresponding to the candidate text, and the second vector similarity between it and the feature vector of the keyword set corresponding to B.
[0053] Specifically, the second vector similarity value ranges from 0 to 1. The closer the second vector similarity value is to 1, the more similar the two corresponding feature vectors are.
[0054] S4025. Sort the texts according to the second vector similarity from largest to smallest, and take the top m candidate texts after sorting as the tool call experience texts corresponding to B; m is the preset number of tool call experience texts to select.
[0055] Through the above steps, candidate texts are first selected by comparing the semantic feature vector of the applicable intent description text in the trigger condition label of the tool call experience text with the semantic feature vector of the intent recognition result corresponding to B. Then, the tool call experience text corresponding to B is selected by comparing the feature vector of the keyword set in the trigger condition label of the candidate text with the feature vector of the keyword set corresponding to B. This dual similarity judgment and quantity control ensures that the selected tool call experience text is relevant to the answer generation task corresponding to B, while avoiding the consumption of the limited context window resources of LLM due to the introduction of too many tool call experience texts. This achieves an effective balance between retrieval quality and resource consumption. Furthermore, the selected high-quality tool call experience text can effectively guide LLM to reuse historical successful experiences, retain early key interaction information, and avoid re-exploring and trial and error in similar task scenarios.
[0056] S403. Based on the intent recognition result corresponding to B and the trigger condition label corresponding to the task planning experience text in the agent's long-term memory data, obtain the task planning experience text corresponding to B.
[0057] Specifically, in step S403, the same method as in step S402 is used to obtain the tool call experience text corresponding to B based on the intent recognition result corresponding to B and the trigger condition label corresponding to the tool call experience text in the agent's long-term memory data. The same method is used to obtain the task planning experience text corresponding to B based on the intent recognition result corresponding to B and the trigger condition label corresponding to the task planning experience text in the agent's long-term memory data. This will not be elaborated further here.
[0058] Through the above steps, based on the user identifier of A and the intent recognition result of B, the initial user profile corresponding to A, the tool calling experience text corresponding to B, and the task planning experience text are obtained independently respectively; the on-demand and accurate acquisition of user profiles, tool calling experience text, and task planning experience text in long-term memory data is realized; it effectively supports the efficient reuse of historical successful experiences by large language models, effectively preserves key early interaction information, reduces the cost of repeated trial and error, and improves the accuracy and efficiency of answer generation tasks.
[0059] S5. Merge the intermediate user profile corresponding to A with the initial user profile corresponding to A to obtain the temporary user profile corresponding to A, and generate LLM context information based on the temporary user profile corresponding to A, the key context information corresponding to B, the tool call experience text and task planning experience text corresponding to B.
[0060] Specifically, in step S5, for user feature tags that exist in the intermediate user profile corresponding to A but not in the initial user profile corresponding to A, the user feature tag and the feature value corresponding to the user feature tag in the intermediate user profile corresponding to A are inserted into the initial user profile corresponding to A, so as to merge the intermediate user profile corresponding to A and the initial user profile corresponding to A to obtain the temporary user profile corresponding to A.
[0061] Specifically, LLM context information is generated based on the temporary user profile corresponding to A, the key context information corresponding to B, the tool call experience text corresponding to B, and the task planning experience text corresponding to B. This includes concatenating the temporary user profile corresponding to A, the key context information corresponding to B, the tool call experience text corresponding to B, and the task planning experience text corresponding to B to generate LLM context information.
[0062] Through the above steps, user feature tags that exist in the intermediate user profile corresponding to A but not in the initial user profile corresponding to A, along with their corresponding feature values in the intermediate user profile corresponding to A, are inserted into the initial user profile. This eliminates the need to update duplicate user feature tags in the intermediate and initial user profiles, and avoids the need to reconstruct or transform the entire profile structure. This achieves lightweight fusion of user profiles, enabling rapid profile updates in real-time interaction scenarios and effectively ensuring the responsiveness of the agent. Furthermore, when the feature values corresponding to user feature tags in the intermediate user profile differ from those in the initial user profile, the feature values in the initial user profile still prevail, preventing the accuracy of the user profile from being affected by a small amount of interaction data or instantaneous preference changes in a single session. This achieves a good balance between fusion efficiency and user profile quality.
[0063] Furthermore, when generating LLM context information, not only short-term memory data but also long-term memory data are incorporated. Intent recognition and classification are performed on each question text in the conversation. LLM context information is only generated by combining a temporary user profile when the user's intent is of the first intent type, i.e., when the user's intent is strongly correlated with the user's personalized preferences. This preserves key early interaction information while avoiding blindly piecing together user profiles when generating LLM context information. This improves the accuracy of LLM context information, avoids resource waste, and effectively enhances the agent's response accuracy and task execution efficiency.
[0064] Specifically, after step S1, the following is also included:
[0065] S10. If there are no historical interaction records belonging to D in C, then based on the agent's long-term memory data, obtain the initial user profile corresponding to A, the tool call experience text corresponding to B, and the task planning experience text.
[0066] S20. Generate LLM context information based on the initial user profile corresponding to A, the tool call experience text corresponding to B, and the task planning experience text.
[0067] Specifically, LLM context information is generated based on the initial user profile corresponding to A, the tool call experience text corresponding to B, and the task planning experience text. This includes concatenating the initial user profile corresponding to A, the tool call experience text corresponding to B, and the task planning experience text to generate LLM context information.
[0068] Through the above steps, if there is no historical interaction record belonging to D in the short-term memory data, it indicates that B is the first problem in D, that is, there is no available historical interaction information in the current session. In this scenario, directly obtaining the initial user profile corresponding to A, the tool calling experience text corresponding to B, and the task planning experience text corresponding to B based on the long-term memory data, and generating LLM context information accordingly, can ensure that the agent can still operate normally in a new session scenario lacking historical context, and provide users with service responses with basic personalized characteristics based on the long-term memory data.
[0069] Specifically, after step S2, the following steps are also included:
[0070] S100. When E is the second intention type, based on the agent's long-term memory data, obtain the tool calling experience text and task planning experience text corresponding to B.
[0071] S200: Based on the key context information corresponding to B, the tool call experience text corresponding to B, and the task planning experience text, generate LLM context information.
[0072] Specifically, based on the key context information corresponding to B, the tool call experience text corresponding to B, and the task planning experience text, LLM context information is generated, including: concatenating the key context information corresponding to B, the tool call experience text corresponding to B, and the task planning experience text to generate LLM context information.
[0073] Through the above steps, when E is the second intent type, it indicates that the answer generation process of B has a low dependence on user-personalized information. The diluted user profile in the key context information can support conventional reasoning, without the need to introduce additional user profiles or trigger the user profile extraction and fusion process. Therefore, based directly on long-term memory data, the tool call experience text and task planning experience text corresponding to B are obtained, and LLM context information is generated accordingly. When generating LLM context information, not only short-term memory data but also long-term memory data are combined. This preserves early key interaction information and avoids blindly piecing together user profiles when generating LLM context information. This improves the accuracy of LLM context information, avoids resource waste, and effectively improves the agent's response accuracy and task execution efficiency.
[0074] Specifically, after step S5, the following is also included:
[0075] S6. Input the first LLM input text into the first LLM to obtain the answer text corresponding to B output by the first LLM; wherein, the first LLM input text is obtained through B and LLM context information.
[0076] Specifically, before step S6, the method further includes: concatenating the B, LLM context information, and preset prompt words corresponding to the answer generation task to obtain the first LLM input text; wherein, as those skilled in the art know, the preset prompt words corresponding to the answer generation task are preset by those skilled in the art according to actual needs, and are used to guide the LLM to perform the answer generation task and output the answer text, which will not be elaborated here.
[0077] In a specific embodiment, the first LLM performs multi-step reasoning for B to generate the answer text corresponding to B. During the multi-step reasoning process, the data volume and cumulative number of LLM context information corresponding to the intermediate reasoning steps are monitored in real time. When the quotient obtained by dividing the number of LLM context information corresponding to the intermediate reasoning step by the preset maximum data volume corresponding to the input context window of the LLM is greater than a preset ratio, or when the cumulative number of steps corresponding to the intermediate reasoning step is greater than a preset reasoning step threshold, the LLM context information is compressed, and subsequent reasoning steps are continued based on the compressed LLM context information until a complete answer text is generated. After each intermediate reasoning step is completed, the data obtained based on the intermediate reasoning step is concatenated into the LLM context information to update the LLM context information.
[0078] S7. Take B and the answer text corresponding to B as the newly added historical interaction record belonging to D; take the intermediate process data generated by the first LLM when calling the API interface or external tool in the process of generating the answer text corresponding to B, and the return result obtained after calling the API interface or external tool as the tool call data corresponding to the newly added historical interaction record belonging to D.
[0079] Specifically, after step S6 and before step S7, the following steps are also included:
[0080] Obtain the tool call decision instruction output by the first LLM during the process of generating the answer text corresponding to B, and use the tool call decision instruction as intermediate process data generated when the first LLM calls the API interface or external tool during the process of generating the answer text corresponding to B; obtain the return result received by the agent after calling the API interface or external tool in response to the tool call decision instruction, and use the return result as the return result obtained by the first LLM after calling the API interface or external tool during the process of generating the answer text corresponding to B.
[0081] S8. Write the newly added historical interaction record belonging to D and the tool call data corresponding to the newly added historical interaction record belonging to D into C, and generate the compressed status label corresponding to the newly added historical interaction record belonging to D; the compressed status label is initially uncompressed.
[0082] Specifically, in step S8, while writing the newly added historical interaction record belonging to D and the tool call data corresponding to the newly added historical interaction record belonging to D into C, the session identifier of D is used as the session identifier of the newly added historical interaction record belonging to D and written into C.
[0083] Through the above steps, after the current answer generation task is completed, the newly added historical interaction records belonging to D and the tool call data corresponding to the newly added historical interaction records belonging to D are obtained and written into the short-term memory data in a timely manner along with the session identifier and compression status. This enables the agent to use the latest content in the short-term memory data to generate LLM context information in subsequent questions, which helps to improve the accuracy of LLM context information.
[0084] Specifically, the method further includes:
[0085] When the number of historical interaction records in C belonging to the same session and with the compression status tag set to uncompressed reaches the preset maximum number of uncompressed records, the following steps are executed:
[0086] If compressed short-term memory data corresponding to the session exists in C, then the second LLM is used to compress the most recently generated compressed short-term memory data corresponding to the session, all historical interaction records with uncompressed compression status tags corresponding to the session, and the tool call data corresponding to all historical interaction records with uncompressed compression status tags corresponding to the session, to obtain the latest compressed short-term memory data corresponding to the session; if compressed short-term memory data corresponding to the session does not exist in C, then the second LLM is used to compress all historical interaction records with uncompressed compression status tags corresponding to the session, and the tool call data corresponding to all historical interaction records with uncompressed compression status tags corresponding to the session, to obtain the latest compressed short-term memory data corresponding to the session.
[0087] Specifically, the latest short-term memory data compressed text corresponding to the session is compressed using the second LLM, along with all uncompressed historical interaction records corresponding to the session and all tool call data corresponding to the uncompressed historical interaction records corresponding to the session, to obtain the latest short-term memory data compressed text corresponding to the session, including:
[0088] The recently generated short-term memory data compressed text corresponding to the session, all historical interaction records with uncompressed compression status tags corresponding to the session, tool call data corresponding to all historical interaction records with uncompressed compression status tags corresponding to the session, and preset prompts corresponding to the data compression task are concatenated to obtain the model input text corresponding to the data compression task. This model input text is then input to the second LLM to obtain the data compression result output by the second LLM, and this data compression result is used as the latest short-term memory data compressed text corresponding to the session. As those skilled in the art know, the preset prompts corresponding to the data compression task are pre-set by those skilled in the art according to actual needs, and are used to guide the LLM to perform the data compression task and output the data compression result, which will not be elaborated here.
[0089] Specifically, the most recently generated short-term memory data compressed text corresponding to the session is the short-term memory data compressed text with the latest generation time among all short-term memory data compressed texts corresponding to that session.
[0090] Specifically, the second LLM is used to compress all historical interaction records with uncompressed compression status tags corresponding to this session, and the tool call data corresponding to all historical interaction records with uncompressed compression status tags corresponding to this session, to obtain the latest short-term memory data compressed text, including:
[0091] The system concatenates all historical interaction records with uncompressed compression status tags corresponding to the session, the tool call data corresponding to all historical interaction records with uncompressed compression status tags corresponding to the session, and the preset prompt words corresponding to the data compression task to obtain the model input text corresponding to the data compression task. The model input text is then input into the second LLM to obtain the data compression result output by the second LLM, and the data compression result is used as the latest short-term memory data compression text corresponding to the session.
[0092] Write the latest short-term memory data compressed text corresponding to the session to C, and at the same time update the compression status labels of all historical interaction records corresponding to the session that are currently uncompressed to compressed.
[0093] Through the above steps, when the number of historical interaction records in C belonging to the same session and with uncompressed status tags reaches the preset maximum number of uncompressed records, the historical interaction records and tool call data stored in C are compressed. An incremental iterative compression strategy is used: when short-term memory data compressed text exists for a session, the most recently generated short-term memory data compressed text corresponding to that session, all historical interaction records with uncompressed status tags for that session, and the tool call data corresponding to all historical interaction records with uncompressed status tags for that session are compressed to obtain the latest short-term memory data compressed text for that session; otherwise, all historical interaction records with uncompressed status tags for that session, and the tool call data corresponding to all historical interaction records with uncompressed status tags for that session are compressed to obtain the latest short-term memory data compressed text for that session. This ensures that the short-term memory data compressed text can summarize the complete conversation context while highlighting the latest interaction focus, maintaining semantic coherence in long-term dialogues. Furthermore, after compression, status tags are updated atomically to ensure data consistency and achieve precise management of uncompressed records.
[0094] Specifically, in step S2, based on C, the key context information corresponding to B is obtained, including:
[0095] S21. If there is no short-term memory data compressed text corresponding to D in C, then based on all historical interaction records with uncompressed compression status labels corresponding to D and the tool call data corresponding to all historical interaction records with uncompressed compression status labels corresponding to D, generate the key context information corresponding to B.
[0096] Specifically, based on all historical interaction records with uncompressed compression status tags corresponding to D and the tool call data corresponding to all historical interaction records with uncompressed compression status tags corresponding to D, key context information corresponding to B is generated, including:
[0097] The key context information corresponding to B is generated by concatenating all historical interaction records with the compressed status label of D being uncompressed and the tool call data corresponding to all historical interaction records with the compressed status label of D being uncompressed.
[0098] S22. If there is a short-term memory data compressed text corresponding to D in C, then based on the most recently generated short-term memory data compressed text corresponding to D, all historical interaction records with compression status labels of D being uncompressed, and the tool call data corresponding to all historical interaction records with compression status labels of D being uncompressed, generate the key context information corresponding to B.
[0099] Specifically, based on the recently generated short-term memory data compressed text corresponding to D, all historical interaction records with uncompressed compression status tags corresponding to D, and the tool call data corresponding to all historical interaction records with uncompressed compression status tags corresponding to D, key context information corresponding to B is generated, including:
[0100] The recently generated short-term memory data corresponding to D, compressed text, all historical interaction records with compressed status labels corresponding to D that are uncompressed, and tool call data corresponding to all historical interaction records with compressed status labels corresponding to D that are uncompressed are concatenated to generate the key context information corresponding to B.
[0101] Through the above steps, key context information is generated based on the short-term memory data compressed text corresponding to D, all historical interaction records with uncompressed compression status labels corresponding to D, and tool call data corresponding to all historical interaction records with uncompressed compression status labels corresponding to D. This ensures that the key context information can summarize the complete conversation context while highlighting the latest interaction focus. At the same time, since the short-term memory data compressed text is obtained by compressing historical interaction records and tool call data, the amount of key context information obtained based on the short-term memory data compressed text is much smaller than the amount of key context information generated based on all historical interaction records and tool call data corresponding to D. This effectively controls the amount of key context information within the limits of the LLM's input context window, avoiding overloading the LLM's input context window.
[0102] Specifically, after step S1, the following is also included:
[0103] S1000. If the agent does not receive a new question text input by A within the preset time period, then D is determined to end. The start time of the preset time period is the time when B is received, and the duration of the preset time period is the preset duration. As those skilled in the art know, the preset duration is the duration preset by those skilled in the art according to actual needs, such as 30 minutes or 1 hour, which will not be elaborated here.
[0104] Specifically, step S1000 also includes: if a session end instruction sent by A is received, then it is determined that D has ended.
[0105] S2000. After determining D, generate the user profile extraction task, tool call experience extraction task, and task planning experience extraction task corresponding to D.
[0106] Specifically, user profile extraction tasks, tool call experience extraction tasks, and task planning experience extraction tasks all include task type identifiers, session identifiers, and task execution instructions.
[0107] Specifically, the task type identifiers include: user profile extraction task, tool usage experience extraction task, and task planning experience extraction task.
[0108] Specifically, the user profile extraction task, tool call experience extraction task, and task planning experience extraction task do not contain any data to be processed.
[0109] S3000: Submit the user profile extraction task, tool call experience extraction task, and task planning experience extraction task corresponding to D as the tasks to be executed corresponding to D to the asynchronous task execution queue corresponding to the agent.
[0110] S4000: The task execution process reads the tasks to be executed from the asynchronous task execution queue and obtains the task generation results of the tasks to be executed through the third LLM.
[0111] S5000: Write the task generation result of the task to be executed into the long-term memory data of the agent.
[0112] Through the above steps, after the current session ends, user profile extraction tasks, tool call experience extraction tasks, and task planning experience extraction tasks are asynchronously generated. Lightweight task submission and queue management are performed using standardized metadata, including task type identifiers, session identifiers, and task execution instructions. The task execution process reads tasks to be executed from the asynchronous task execution queue and obtains the task generation results through a third-party LLM, writing the results into long-term memory. After the session ends, session resources are released and subsequent user requests are responded to without waiting for any pending tasks to be executed, significantly improving the agent's response speed and concurrent processing capabilities. Simultaneously, the independent scheduling mechanism based on the asynchronous task execution queue not only ensures accurate updates and persistent storage of long-term memory data but also effectively avoids system blocking caused by synchronous processing, effectively improving overall operating efficiency and user experience. This achieves complete decoupling between real-time interaction and background processing, as well as the automated and continuous accumulation and optimization of the agent's long-term memory data.
[0113] Specifically, step S4000 includes the following steps:
[0114] S4001. When the task execution process obtains a task to be executed from the asynchronous task execution queue, it retrieves the key dataset corresponding to the session identifier from the agent's short-term memory data based on the session identifier corresponding to the task to be executed. The key dataset includes: the short-term memory compressed text with the latest generation time among all short-term memory compressed texts corresponding to the session identifier, all historical interaction records with the compressed status label of uncompressed corresponding to the session identifier, and tool call data corresponding to all historical interaction records with the compressed status label of uncompressed. The task to be executed includes a task type identifier and a session identifier.
[0115] Specifically, the tasks to be executed also include task execution instructions.
[0116] S4002. Concatenate the key dataset corresponding to the session identifier and the preset prompt words corresponding to the task type identifier of the task to be executed to obtain the second LLM input text corresponding to the task to be executed.
[0117] Specifically, when the task type is identified as a user profile extraction task, the preset prompt word corresponding to the task type identifier of the task to be executed is the preset prompt word corresponding to the user profile extraction task.
[0118] Specifically, when the task type is identified as a tool call experience extraction task, the preset prompt word corresponding to the task type identifier of the task to be executed is the preset prompt word corresponding to the tool call experience extraction task; wherein, as those skilled in the art know, the tool call experience extraction task is a prompt word that is pre-set by those skilled in the art according to actual needs, used to guide the LLM to execute the tool call experience extraction task and output the tool call experience extraction result, which will not be elaborated here.
[0119] Specifically, when the task type is identified as a task planning experience extraction task, the preset prompt word corresponding to the task type identifier of the task to be executed is the preset prompt word corresponding to the task planning experience extraction task; wherein, as those skilled in the art know, the task planning experience extraction task is a prompt word that is pre-set by those skilled in the art according to actual needs, used to guide the LLM to execute the task planning experience extraction task and output the task planning experience extraction result, which will not be elaborated here.
[0120] S4003. Input the second LLM input text corresponding to the task to be executed into the third LLM to obtain the task generation result of the task to be executed.
[0121] Specifically, when the task type identifier corresponding to the task to be executed is a tool call experience extraction task, the task generation result of the task to be executed is the tool call experience extraction result output by the third LLM. The tool call experience extraction result includes the tool call experience text and the trigger condition label corresponding to the tool call experience text.
[0122] Specifically, when the task type identifier corresponding to the task to be executed is a task planning experience extraction task, the task generation result of the task to be executed is the task planning experience extraction result output by the third LLM. The task planning experience extraction result includes the task planning experience text and the trigger condition tag corresponding to the task planning experience text.
[0123] Through the above steps, there is no need to read or copy short-term memory data when submitting tasks to be executed, which enables the rapid submission of tasks to be executed. Furthermore, when executing tasks, the data to be processed is retrieved from the short-term memory data according to the session identifier, and the retrieved data is processed to ensure the real-time nature of the retrieved data, thereby improving the accuracy of the task generation results.
[0124] Specifically, step S5000 includes the following steps:
[0125] S5001. When the task generation result of the task to be executed is the user profile extraction result, the user profile extraction result shall be used as the key user profile corresponding to user U of the task to be executed.
[0126] S5002. For user feature tags that exist in the key user profile corresponding to U but not in the user profile corresponding to U stored in the agent's long-term memory data, write the user feature tag and the corresponding feature value of the user feature tag in the key user profile corresponding to U into the user profile corresponding to U stored in the agent's long-term memory data, so as to update the user profile corresponding to U stored in the agent's long-term memory data.
[0127] S5003. For user feature tags that exist in the key user profile corresponding to U and are stored in the long-term memory data of the agent, if the feature value corresponding to the user feature tag in the key user profile corresponding to U is inconsistent with the feature value corresponding to the user feature tag in the long-term memory data of the agent, then the feature value corresponding to the user feature tag in the key user profile corresponding to U is used to replace the feature value corresponding to the user feature tag in the long-term memory data of the agent, so as to update the user profile corresponding to U stored in the long-term memory data of the agent.
[0128] S5004. If the task generation result of the task to be executed is the tool call experience extraction result, then write the tool call experience extraction result into the tool call experience storage area in the agent's long-term memory data.
[0129] S5005. If the task generation result of the task to be executed is the task planning experience extraction result, then write the task planning experience extraction result into the task planning experience storage area in the agent's long-term memory data.
[0130] Specifically, once the task generation results of all tasks to be executed corresponding to the same session identifier have been written into the agent's long-term memory data, all historical interaction records, tool call data, and short-term memory data compressed text related to that session identifier in the agent's short-term memory data will be deleted.
[0131] Specifically, in the embodiments of this application, the first LLM, the second LLM, and the third LLM are three different LLMs.
[0132] Through the above steps, when the task generation result of the task to be executed is a user profile extraction result, this user profile extraction result is used as the key user profile; the user profile in the long-term memory data is updated based on the key user profile; specifically, user feature labels and corresponding feature values that are not in the user profile in the long-term memory data are written into this user profile; for user feature labels whose corresponding feature values in the user profile in the long-term memory data are inconsistent with those in the key user profile, their corresponding feature values in the long-term memory data are updated to their corresponding feature values in the key user profile, so that the user profile in the long-term memory data can continuously capture the dynamic evolution of user preferences, and the update operation is simple and efficient; when the task generation result of the task to be executed is a tool call experience extraction result or a task planning experience extraction result, the task generation result of the task to be executed is written into the corresponding storage area in the long-term memory data to avoid retrieval interference caused by mixed data storage.
[0133] In this application embodiment, a non-transitory computer-readable storage medium is also provided. This non-transitory computer-readable storage medium can be disposed in an electronic device to store at least one instruction or at least one program related to implementing the method provided in any embodiment of this application. The at least one instruction or the at least one program is loaded and executed by a processor to implement the method provided in any embodiment of this application, and can achieve the same technical effect. To avoid repetition, further details are omitted here.
[0134] Examples of non-transitory computer-readable storage media include: computer read-only memory (ROM), random access memory (RAM), erasable programmable read-only memory (EPROM), compact disc read-only memory (CD-ROM), flash memory, magnetic disk, optical disk, portable computer disk, hard disk and / or solid-state drive, etc.
[0135] In this application embodiment, an electronic device is also provided, the electronic device including a processor and the non-transitory computer-readable storage medium. The processor loads and executes at least one instruction or at least one program stored in the non-transitory computer-readable storage medium related to implementing the method provided in any embodiment of this application, so as to implement the method provided in the embodiment of this application.
[0136] For example, the electronic device may be a mobile electronic device or a non-mobile electronic device that also includes other functions such as a personal digital assistant and / or music player. Further, the mobile electronic device may be any one of a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA); the non-mobile electronic device includes any one of a server, network attached storage (NAS), personal computer (PC), television (TV), ATM, or self-service machine. No specific limitations are made in the embodiments of this application.
[0137] For example, the processor can be a processor in any electronic device.
[0138] Exemplary embodiments of this application also provide a feasible structure for an electronic device. For example, the electronic device may include a processor, an external memory interface, internal memory, a universal serial bus (USB) interface (hereinafter referred to as a USB interface), a charging management module, a power management module, a battery, a first antenna, a second antenna, a mobile communication module, a wireless communication module, an audio module, a speaker, a receiver, a microphone, a headphone jack, a sensor module, buttons, a motor, an indicator, a camera, a display screen, and a subscriber identification module (SIM) card interface (hereinafter referred to as a SIM card interface), etc. The sensor module may include pressure sensors, gyroscope sensors, barometric pressure sensors, magnetic sensors, accelerometers, distance sensors, proximity sensors, fingerprint sensors, temperature sensors, touch sensors, ambient light sensors, and / or bone conduction sensors, etc.
[0139] It should be understood that the exemplary structures of the embodiments of this application do not constitute a specific limitation on the electronic device. In other embodiments of this application, the electronic device may include more or fewer components than the structure described herein, or combine some components, or split some components, or have different component arrangements. The components may be implemented in hardware, software, or a combination of software and hardware.
[0140] For example, the processor may include one or more processing units, wherein the processing units include: an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural network processing unit (NPU). Different processing units may be independent devices or integrated into one or more processors. The controller may generate operation control signals based on instruction opcodes and timing signals to control instruction fetching and execution.
[0141] For example, the processor may further include a memory for storing instructions and data. In some embodiments of this application, the memory in the processor is a cache memory. The memory can store instructions or data that the processor has just used or that are used repeatedly. If the processor needs to use the instructions or data again, it can directly retrieve them from the memory.
[0142] For example, the processor may also include one or more interfaces. These interfaces include: an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a SIM card interface, and / or a USB interface, etc.
[0143] The integrated circuit interface is a bidirectional synchronous serial bus, which includes a serial data line (SDA) and a serial clock line (SCL).
[0144] Integrated circuits with built-in audio interfaces can be used for audio communication. In some embodiments of this application, the processor may include multiple sets of integrated circuit-based audio interfaces. The processor can couple with an audio module through the integrated circuit-based audio interface to achieve communication between the processor and the audio module.
[0145] The pulse code modulation interface can also be used for audio communication, specifically for sampling, quantizing, and encoding analog signals. In some embodiments of this application, the audio module and the wireless communication module can be coupled through the pulse code modulation interface.
[0146] A Universal Asynchronous Receiver / Transmitter (UART) is a universal serial data bus interface used for asynchronous communication. This bus can be a bidirectional communication bus interface. It converts the data to be transmitted between serial and parallel communication. In some embodiments of this application, the processor and the wireless communication module can be connected via the UART.
[0147] Mobile industry processor interfaces can be used to connect processors to peripheral devices such as displays and cameras.
[0148] General purpose input / output interfaces can be configured via software.
[0149] Furthermore, the general-purpose input / output interface can be configured as a control signal or a data signal. In some embodiments of this application, the general-purpose input / output interface can be used to connect the processor to a camera, display screen, wireless communication module, audio module, sensor module, etc.
[0150] A USB interface is an interface that conforms to the USB standard specification, specifically including Mini USB, Micro USB, and USB Type-C interfaces. USB interfaces can be used to connect chargers to charge electronic devices, and also for transferring data between electronic devices and peripheral devices.
[0151] It should be understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a limitation on the structure of the electronic device. In other embodiments of this application, the electronic device may also employ different interface connection methods or a combination of multiple interface connection methods as described in the embodiments.
[0152] The charging management module receives charging input from a charger, which can be either a wireless or wired charger. In some wired charging embodiments, the charging management module receives charging input from the wired charger via a USB interface. In some wireless charging embodiments, the charging management module receives wireless charging input via the wireless charging coil of the electronic device. While charging the battery, the charging management module can also supply power to various parts of the electronic device via the power management module.
[0153] The power management module is used to connect the battery, the charging management module, and the processor.
[0154] Wireless communication functionality in electronic devices can be achieved through a first antenna, a second antenna, a mobile communication module, a wireless communication module, a modem processor, and a baseband processor.
[0155] Mobile communication modules can enable wireless communication solutions, including 2G / 3G / 4G / 5G, for use in electronic devices.
[0156] A modem processor may include a modulator and a demodulator. The modulator modulates a low-frequency baseband signal to be transmitted into a mid-to-high frequency signal. The demodulator demodulates a received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to a baseband processor for processing. After processing by the baseband processor, the low-frequency baseband signal is transmitted to an application processor. The application processor outputs sound signals through audio devices (not limited to speakers, receivers, etc.) or displays images or videos on a display screen. In some embodiments of this application, the modem processor may be a separate device. In other embodiments, the modem processor may be independent of the processor and housed within the same device as the mobile communication module or other functional modules.
[0157] Wireless communication modules can enable solutions for wireless communication applications in electronic devices, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies.
[0158] In some embodiments of this application, the first antenna of the electronic device is coupled to the mobile communication module, and the second antenna is coupled to the wireless communication module, enabling the electronic device to communicate with networks and other devices via wireless communication technology.
[0159] Electronic devices utilize GPUs, displays, and application processors to achieve their display functions. A GPU is a microprocessor for image processing, connecting the display and the application processor. GPUs perform mathematical and geometric calculations and are used for graphics rendering. A processor may include one or more GPUs, which execute program instructions to generate or modify display information.
[0160] The display screen is used to display images, videos, etc. The display screen includes a display panel. The display panel can be a liquid crystal display (LCD), or a display panel made of materials selected from organic light-emitting diodes (OLEDs), active-matrix organic light-emitting diodes (AMOLEDs), flexible light-emitting diodes (FLEDs), minimized, microLEDs, micro-OLEDs, or quantum dot light-emitting diodes (QLEDs). In some embodiments of this application, the electronic device may include one or more display screens. In some embodiments of this application, the display screen may also integrate touch functionality and may also be referred to as a touch screen.
[0161] Electronic devices can achieve shooting functions through ISPs, cameras, video codecs, GPUs, displays, and application processors.
[0162] External storage interfaces can be used to connect external memory cards, such as Micro SD cards, to expand the storage capacity of electronic devices.
[0163] Internal memory can be used to store executable program code for a computer, which includes instructions. The processor executes the instructions stored in internal memory to perform various functional applications and data processing of electronic devices.
[0164] Electronic devices can implement audio functions through audio modules, speakers, receivers, microphones, headphone jacks, and application processors. Examples include music playback and recording.
[0165] The audio module converts digital audio information into analog audio signals for output, and also converts analog audio input into digital audio signals. The speaker, also called a "horn," converts audio electrical signals into sound signals. The receiver, also called a "handset," converts audio electrical signals into sound signals. The microphone, also called a "microphone" or "voice transducer," converts sound signals into electrical signals. The headphone jack is used to connect wired headphones.
[0166] Pressure sensors are used to sense pressure signals and convert them into electrical signals. In some embodiments of this application, the pressure sensor can be located on the display screen. A gyroscope sensor can be used to determine the motion posture of the electronic device. A barometric pressure sensor is used to measure air pressure. In some embodiments of this application, the electronic device calculates altitude using the air pressure value measured by the barometric pressure sensor, assisting in positioning and navigation. An accelerometer can detect the magnitude of acceleration of the electronic device in various directions (generally three axes). A distance sensor is used to measure distance. A fingerprint sensor is used to collect fingerprints. A touch sensor, also known as a "touch panel," can be located on the display screen, forming a touchscreen, also known as a "touch screen." A bone conduction sensor can acquire vibration signals. In some embodiments of this application, a bone conduction sensor can acquire vibration signals from vibrating bone fragments in the human vocal cords. A bone conduction sensor can also contact the human pulse to receive blood pressure signals.
[0167] The buttons include a power button and volume buttons. A motor can generate vibration alerts. Indicators can be indicator lights, used to show charging status, battery level changes, messages, missed calls, notifications, etc. A SIM card slot is used to connect a SIM card.
[0168] Embodiments of this application also provide a computer program product including program code that, when the program product is run on an electronic device, causes the electronic device to perform the steps of the methods described in this specification according to various exemplary embodiments of this application.
[0169] This application also provides a chip, which includes a processor and a communication interface. The communication interface is used to receive signals and transmit the signals to the processor. The processor processes the signals so that the methods described in the various exemplary embodiments of this application are executed.
[0170] While specific embodiments of this application have been described in detail by way of examples, those skilled in the art should understand that the examples are for illustrative purposes only and not intended to limit the scope of this application. Those skilled in the art should also understand that various modifications can be made to the embodiments without departing from the scope and spirit of this application. The scope of this application is defined by the appended claims.
Claims
1. A method for obtaining LLM context information for intelligent agents, characterized in that, The method includes the following steps: S1. When the agent receives the question text B currently input by user A, it checks whether there is a historical interaction record belonging to the current session D in the agent's short-term memory data C. S2. If there are historical interaction records belonging to D in C, then based on C, obtain the key context information corresponding to B, and perform intent recognition and intent classification processing on B through the first LLM to obtain the intent type E of the current user intent; where E is the first intent type or the second intent type; the first intent type indicates that the current user intent is strongly correlated with the user's personalized preferences; the second intent type indicates that the current user intent is weakly correlated with the user's personalized preferences. S3. When E is the first intent type, user profiles are extracted from key context information through the first LLM to obtain the intermediate user profiles corresponding to A. S4. Based on the agent's long-term memory data, obtain the initial user profile corresponding to A, the tool calling experience text and the task planning experience text corresponding to B; S5. Merge the intermediate user profile corresponding to A with the initial user profile corresponding to A to obtain the temporary user profile corresponding to A, and generate LLM context information based on the temporary user profile corresponding to A, the key context information corresponding to B, the tool call experience text and task planning experience text corresponding to B.
2. The method for obtaining LLM context information for an intelligent agent according to claim 1, characterized in that, The process after step S1 also includes: S10. If there is no historical interaction record belonging to D in C, then based on the agent's long-term memory data, obtain the initial user profile corresponding to A, the tool call experience text corresponding to B, and the task planning experience text. S20. Generate LLM context information based on the initial user profile corresponding to A, the tool call experience text corresponding to B, and the task planning experience text.
3. The method for obtaining LLM context information for an intelligent agent according to claim 1, characterized in that, Following step S2, the following is also included: S100. When E is the second intention type, based on the agent's long-term memory data, obtain the tool calling experience text and task planning experience text corresponding to B. S200: Based on the key context information corresponding to B, the tool call experience text corresponding to B, and the task planning experience text, generate LLM context information.
4. The method for obtaining LLM context information for an intelligent agent according to claim 1, characterized in that, Following step S5, the following is also included: S6. Input the first LLM input text into the first LLM to obtain the answer text corresponding to B output by the first LLM; wherein, the first LLM input text is obtained through B and LLM context information; S7. Take B and the answer text corresponding to B as the newly added historical interaction record belonging to D; take the intermediate process data generated by the first LLM when calling the API interface or external tool in the process of generating the answer text corresponding to B, and the return result obtained after calling the API interface or external tool as the tool call data corresponding to the newly added historical interaction record belonging to D. S8. Write the newly added historical interaction record belonging to D and the tool call data corresponding to the newly added historical interaction record belonging to D into C, and generate the compressed status label corresponding to the newly added historical interaction record belonging to D; the compressed status label is initially uncompressed.
5. The method for obtaining LLM context information for an intelligent agent according to claim 4, characterized in that, The method further includes: When the number of historical interaction records in C belonging to the same session and with the compression status tag set to uncompressed reaches the preset maximum number of uncompressed records, the following steps are executed: If compressed short-term memory data corresponding to the session exists in C, then the second LLM is used to compress the most recently generated compressed short-term memory data corresponding to the session, all historical interaction records with uncompressed compression status tags corresponding to the session, and the tool call data corresponding to all historical interaction records with uncompressed compression status tags corresponding to the session, to obtain the latest compressed short-term memory data corresponding to the session; if compressed short-term memory data corresponding to the session does not exist in C, then the second LLM is used to compress all historical interaction records with uncompressed compression status tags corresponding to the session, and the tool call data corresponding to all historical interaction records with uncompressed compression status tags corresponding to the session, to obtain the latest compressed short-term memory data corresponding to the session. Write the latest short-term memory data compressed text corresponding to the session to C, and at the same time update the compression status labels of all historical interaction records corresponding to the session that are currently uncompressed to compressed.
6. The method for obtaining LLM context information for an intelligent agent according to claim 5, characterized in that, In step S2, based on C, the key context information corresponding to B is obtained, including: S21. If there is no short-term memory data compressed text corresponding to D in C, then based on all historical interaction records with uncompressed compression status labels corresponding to D and the tool call data corresponding to all historical interaction records with uncompressed compression status labels corresponding to D, generate the key context information corresponding to B. S22. If there is a short-term memory data compressed text corresponding to D in C, then based on the most recently generated short-term memory data compressed text corresponding to D, all historical interaction records with compression status labels of D being uncompressed, and the tool call data corresponding to all historical interaction records with compression status labels of D being uncompressed, generate the key context information corresponding to B.
7. The method for obtaining LLM context information for an intelligent agent according to claim 1, characterized in that, The process after step S1 also includes: S1000. If the agent does not receive a new question text input by A within the preset time period, then D is determined to end; the start time of the preset time period is the time when B is received, and the duration of the preset time period is the preset duration. S2000. After D is determined, the user profile extraction task, tool call experience extraction task, and task planning experience extraction task corresponding to D are generated. S3000: Submit the user profile extraction task, tool call experience extraction task, and task planning experience extraction task corresponding to D as the tasks to be executed to the asynchronous task execution queue corresponding to the agent. S4000: The task execution process reads the tasks to be executed from the asynchronous task execution queue and obtains the task generation results of the tasks to be executed through the third LLM; S5000: Write the task generation result of the task to be executed into the long-term memory data of the agent.
8. The method for obtaining LLM context information for an intelligent agent according to claim 7, characterized in that, Step S4000 includes the following steps: S4001. When the task execution process obtains a task to be executed from the asynchronous task execution queue, it obtains the key dataset corresponding to the session identifier from the agent's short-term memory data according to the session identifier corresponding to the task to be executed. The key datasets include: the compressed short-term memory data text with the latest generation time among all compressed short-term memory data texts corresponding to the session identifier; all historical interaction records with compressed status labels of uncompressed corresponding to the session identifier; and tool call data corresponding to all historical interaction records with compressed status labels of uncompressed. The tasks to be executed include task type identifiers and session identifiers. S4002. Concatenate the key dataset corresponding to the session identifier and the preset prompt words corresponding to the task type identifier of the task to be executed to obtain the second LLM input text corresponding to the task to be executed. S4003. Input the second LLM input text corresponding to the task to be executed into the third LLM to obtain the task generation result of the task to be executed.
9. A non-transitory computer-readable storage medium, characterized in that, The non-transitory computer-readable storage medium stores at least one instruction or at least one program segment, which is loaded and executed by a processor to implement the LLM context information acquisition method for an agent as described in any one of claims 1-8.
10. An electronic device, characterized in that, Includes a processor and the non-transitory computer-readable storage medium as described in claim 9.
