Context loading method, apparatus, device, and storage medium
By utilizing topic tagging and content distillation in the response content of a large language model in an intelligent agent dialogue system, the problem of inconsistent context loading in existing technologies is solved, enabling user-initiated intervention and accurate loading of historical topics, thereby improving the usability and accuracy of responses.
Patent Information
- Application Number
- CN202611305811.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-26
- Publication Date
- 2026-11-24
AI Technical Summary
Existing context loading methods are ineffective in intelligent agent dialogue systems. Users need to memorize or infer the relevance of historical dialogues themselves, and automatic decision-making algorithms lead to inconsistent loaded content, affecting the quality of responses.
By acquiring the current round of questions and the collected set of historical topics, and using the topic tag confirmation operation in the response content of the large language model, the target historical topics are accurately extracted and sent as supplementary contextual information. Combined with content distillation processing, the historical topic content is optimized.
It enables users to actively intervene in loading historical topics, reduces the burden of manual operation, ensures that the context is consistent with user needs, and improves the usability and accuracy of the large language model's answers.
Smart Images

Figure CN123159531A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of large model technology, and in particular to context loading methods, context loading devices, electronic devices and storage media. Background Technology
[0002] In agent-based dialogue systems using large language models, multi-turn interaction messages between the user and the agent accumulate as the conversation continues, with messages of different content appearing intermittently in the same conversation stream. To control the length of prompts sent to the large language model context each time, existing methods typically employ sliding window mechanisms to retain only the most recent messages, or use vector retrieval to recall relevant text fragments based on similarity, or utilize external summarization services and other automatic decision-making algorithms to compress historical dialogues before placing them into the context. Under these schemes, the automatic decision-making method automatically determines which historical information needs to be loaded during actual interaction. If the user wishes to actively specify the loading of a particular historical dialogue segment, they must manually search the history and trigger the loading operation.
[0003] When faced with conversation records spanning weeks or months and containing dozens or even hundreds of topics, users need to manually remember or infer which historical conversations are relevant to the current question. This operational burden increases linearly with the conversation duration and the number of topics, and the accuracy of the user's judgment affects the quality of subsequent responses. If historical information is entirely loaded by an automated decision-making algorithm, users cannot know in advance which historical information will be loaded, nor can they intervene when the loading decision contradicts their intentions. This results in low consistency between the final context fed into the large language model and the user's actual needs, consequently reducing the usability of the agent's responses. Therefore, existing context loading methods are ineffective in agent dialogue systems. Summary of the Invention
[0004] The main objective of this application is to provide a context loading method, a context loading device, an electronic device, and a storage medium, aiming to solve the technical problem of poor effectiveness of existing context loading methods in intelligent agent dialogue systems.
[0005] To achieve the above objectives, this application proposes a context loading method, which includes: Retrieve the questions asked in the current round and the collected historical topics; The question content is sent to the large language model, and the first response content returned by the large language model is obtained; When the first response content includes a topic tag, in response to the confirmation operation of the topic tag, a target historical topic is extracted from the historical topic set according to the topic tag, wherein the topic tag is used to indicate at least one historical topic that needs to be loaded. The content of the target historical topic is sent to the large language model as supplementary contextual information for the question content, and the second response content returned by the large language model is obtained. The second response content is then used as the final response content.
[0006] In one embodiment, after the step of extracting the target historical topic from the historical topic set based on the topic tag, the method further includes: The target historical topic is subjected to content distillation to obtain distilled topic content; The distilled topic content is used as supplementary contextual information for the question content.
[0007] In one embodiment, the step of performing content distillation on the target historical topic to obtain distilled topic content includes: Delete the tool call records in the target historical topic to obtain the first distillation content; The response information returned by the large language model in the target historical topic is truncated based on a preset first character length threshold to obtain the second distilled content; The historical questions in the target historical topic are truncated based on a preset second character length threshold to obtain the third distilled content; Replace the attachment content in the target historical topic with filename references to obtain the fourth distillation content; Based on the first distillation content, the second distillation content, the third distillation content, and the fourth distillation content, the topic content after distillation is obtained.
[0008] In one embodiment, when the topic tag is a topic demand tag, the topic demand tag is used to indicate at least one historical topic that the large language model needs to load to answer the question content in the current round, and the step of obtaining the second response content returned by the large language model includes: The content of the target historical topic is combined with the question content of the current round to form the first prompt word; The first prompt word is sent to the large language model, and the second response content returned by the large language model for the question content of the current round is obtained.
[0009] In one embodiment, when the topic marker is a topic continuation marker, the topic continuation marker is used to indicate at least one historical topic that the large language model needs to load to answer the next question in the next round. The step of obtaining the second response content returned by the large language model includes: Cache the content of the target historical topic; When the content of the next question in the next round is obtained, the content of the target historical topic and the content of the next question are concatenated to form the second prompt word; The second prompt word is sent to the large language model, and the second response content returned by the large language model for the next question is obtained.
[0010] In one embodiment, after the step of obtaining the first response content returned by the large language model, the method includes: When the first response content contains the topic tag, a confirmation prompt for the target historical topic indicated by the topic tag is displayed; In response to the rejection operation of the confirmation prompt, the large language model is controlled to answer the question content of the current round based on the current visible context; Obtain the third response content returned by the large language model based on the current visible context; When the topic tag is included in the third response content, a reconfirmation prompt for the historical topic corresponding to the topic tag is displayed.
[0011] In one embodiment, the topic tag includes a dependency identifier for each target historical topic, the dependency identifier indicating that a first target historical topic depends on a second target historical topic; prior to the confirmation operation on the topic tag, the method further includes: Based on the dependency identifier, identify the first target historical topic and the second target historical topic, and arrange the second target historical topic before the first target historical topic; The content of the second target historical topic is sent as supplementary contextual information to the large language model; Obtain the first intermediate response content returned by the large language model based on the content of the second target historical topic; When the first intermediate response content does not contain all the information required to answer the question, the content of the first target historical topic and the content of the second target historical topic are sent together as supplementary context information to the large language model to obtain the fourth response content.
[0012] Furthermore, to achieve the above objectives, this application also proposes a context loading device, which includes: The acquisition module is used to acquire the questions asked in the current round and the collection of historical topics. The response module is used to send the question content to the large language model and obtain the first response content returned by the large language model; An extraction module is configured to, in response to a confirmation operation on the topic tag, extract a target historical topic from the historical topic set based on the topic tag when the first response content contains a topic tag, wherein the topic tag is used to indicate at least one historical topic that needs to be loaded. The supplementary module is used to send the content of the target historical topic as supplementary contextual information of the question content to the large language model, and to obtain the second response content returned by the large language model, and use the second response content as the final response content.
[0013] In addition, to achieve the above objectives, this application also proposes an electronic device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the context loading method as described above.
[0014] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and which, when executed by a processor, implements the steps of the context loading method described above.
[0015] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the context loading method described above.
[0016] One or more technical solutions proposed in this application have at least the following technical effects: After obtaining the aggregated set of historical topics and the question content of the current round, this application first sends the question content to the large language model and obtains the first response content returned by it, so that the loading decision is triggered at the inference output stage of the agent; when the first response content contains a topic tag indicating that at least one historical topic needs to be loaded, in response to the confirmation operation of the topic tag, the target historical topic is accurately extracted from the set of historical topics according to the topic tag, and then the content of the target historical topic is sent to the large language model as supplementary contextual information of the question content, and the final response content is obtained.
[0017] Therefore, the selection of historical topics to be loaded is no longer entirely determined by automatic decision-making algorithms such as sliding windows, vector retrieval, or automatic summarization. Instead, the large language model actively indicates these topics through topic tags during the reasoning process for the current question, allowing the user to intervene and grant permission through a confirmation operation. Users no longer need to manually search, memorize, or infer relevant historical dialogues from a long-running conversation record with numerous topics, eliminating the manual operation burden that increases linearly with the conversation duration and the number of topics. This also overcomes the shortcomings of existing automatic loading schemes, where users cannot know the loaded content in advance or intervene when the loading decision does not match their intentions. As a result, the final context fed into the large language model always aligns with the user's actual needs, significantly improving the usability and accuracy of the large language model's responses and effectively solving the problem of poor effectiveness of existing context loading methods in intelligent agent dialogue systems. Attached Figure Description
[0018] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 A flowchart illustrating an embodiment of the context loading method of this application. Figure 1 ; Figure 2 A flowchart illustrating an embodiment of the context loading method of this application. Figure 2 ; Figure 3 A flowchart illustrating an embodiment of the context loading method of this application. Figure 3 ; Figure 4 This is a schematic diagram of the module structure of the context loading device of this application; Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the context loading method of this application.
[0021] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0022] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of this application and are not intended to limit this application.
[0023] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0024] It should be noted that the executing entity in this embodiment can be an electronic device, such as a mobile phone, tablet computer, personal computer, or smart terminal; it can also be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone; or a client program, application program, or operating system component capable of implementing the above functions. The following description uses an electronic device as an example to illustrate this embodiment and the subsequent embodiments.
[0025] Based on this, embodiments of this application provide a context loading method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the context loading method of this application.
[0026] In one feasible embodiment, the application scenarios of the technical solution of this application can be: long conversation AI (Artificial Intelligence) assistant, enterprise team multi-topic collaboration assistant, cross-conversation knowledge continuation, conversation recovery, etc.
[0027] In this embodiment, the context loading method includes steps S1 to S4: Step S1: Obtain the questions in the current round and the collection of historical topics; It should be noted that when a user engages in a multi-turn dialogue with an intelligent agent (i.e., a program entity that provides capabilities based on a large language model), each time the user inputs one or more messages and waits for the intelligent agent's response, it constitutes one turn.
[0028] Optionally, the message entered by the user in the current round is the question content for the current round.
[0029] Optionally, as the conversation continues, a large number of historical messages will accumulate locally on the electronic device. These messages will be divided into several topics after topic aggregation processing.
[0030] Optionally, topic aggregation refers to aggregating multiple rounds of messages belonging to the same semantic topic into a single topic. After aggregation, each topic has a unique topic identifier, and all messages under the same topic identifier constitute a topic memory unit.
[0031] Optionally, the aggregated historical topic set is the collection of all topics that have been stored locally on the electronic device, with each topic containing all historical messages under that topic.
[0032] Alternatively, the electronic device may be a mobile phone, tablet, personal computer, or smart terminal, and the electronic device has applications or operating system components deployed on it to provide a user interface and the ability to communicate with a large language model.
[0033] Optionally, historical messages are stored locally on the electronic device in an array, and each message can be assigned to a topic identifier. The assignment method includes, but is not limited to, messages carrying a topic identifier field or topic-held message index segments.
[0034] Optionally, the topic aggregation results can be provided by an external aggregation system; this method does not limit the specific aggregation method. The questions in the current round can be obtained by listening to user input and submissions on the interactive interface using an electronic device. The aggregated historical topic set can be obtained by reading all topic data stored locally on an electronic device.
[0035] Understandably, this step is used by the subsequent large language model to obtain the current user intent and the historical context that may be needed.
[0036] Step S2: Send the question content to the large language model and obtain the first response content returned by the large language model; It should be noted that after the electronic device obtains the question content of the user in the current round, it sends the question content as a prompt message to the large language model by calling the application programming interface (API) provided by the large language model.
[0037] After receiving a prompt, the large language model infers based on its internal parameters and the currently available context information, generates a response text for the question, and returns the response text to the electronic device via API. The electronic device receives the response text as its first response.
[0038] Optionally, the large language model can be an API model (such as GPT, Gemini, etc.) or an open-source model (such as DeepSeek, Qwen, etc.). Sending a question to the large language model can be done using a Hypertext Transfer Protocol (HTTP) request, sending the question as a prompt field in the request body. Obtaining the first response from the large language model can be done by listening to the HTTP response and reading the reply text generated by the large language model from the response body.
[0039] Optionally, the electronic device can set a tag generation instruction in the prompt words sent to the large language model. This tag generation instruction is used to guide the large language model to generate topic tags in a pre-defined format when historical topics need to be loaded.
[0040] Understandably, this step enables the large language model to generate an initial response based on the current user's question. This initial response may include references to historical topics, which can then be loaded on demand for later use.
[0041] Step S3: When the first response content contains a topic tag, in response to the confirmation operation of the topic tag, extract the target historical topic from the historical topic set according to the topic tag, wherein the topic tag is used to indicate at least one historical topic that needs to be loaded. It should be noted that after the electronic device obtains the first response content, it parses the first response content and checks whether it contains topic tags.
[0042] Topic tags are predefined strings embedded in the first response content by the large language model. They declare which historical topics should be loaded to answer the questions in the current round. When a topic tag is detected, the electronic device does not immediately load the topic content, but instead prompts the user through the user interface to confirm whether to load the historical topics indicated by the topic tag.
[0043] The user agrees or disagrees with the confirmation prompt through the interactive interface. In response to the user's confirmation (i.e., the user agrees to load), the electronic device extracts the topic identifier of at least one historical topic that needs to be loaded from the topic tags, and then searches for and extracts the corresponding historical topic as the target historical topic from the collected historical topic set based on the topic identifier.
[0044] Optionally, the topic tag format can be [NEED_CONTEXT: N] or [TOPICS_NEEDED: list of topic names], where N is the topic number and the list of topic names contains at least one topic name.
[0045] Extracting target historical topics from the historical topic set based on topic tags includes: extracting topic IDs or topic names from topic tags; and using the extracted topic IDs or topic names as query conditions to search for and retrieve all messages of the corresponding topic in the historical topic set.
[0046] Optionally, if the first response content does not contain a topic tag, the electronic device will directly display the first response content as the final response content to the user without performing subsequent loading steps.
[0047] Understandably, this step achieves dual control over on-demand loading of historical topics by combining the big language model's self-decision with user confirmation. This avoids both the model blindly loading irrelevant history, which would pollute the context, and the inefficient operation of users manually searching for historical messages.
[0048] Step S4: Send the content of the target historical topic as supplementary contextual information for the question content to the large language model, obtain the second response content returned by the large language model, and use the second response content as the final response content.
[0049] It should be noted that after the electronic device extracts the target historical topic, it obtains the content of all messages contained in the target historical topic and uses this content as supplementary contextual information corresponding to the question content in the current round.
[0050] The electronic device concatenates the content of the target historical topic with the current user's question to form a new prompt, which is then sent back to the large language model via API. Upon receiving this new prompt, the large language model performs inference based on the content of the target historical topic and the current user's question, generates an updated response text, and returns it to the electronic device via API.
[0051] The electronic device receives the reply text as the second response content, determines the second response content as the final response content, and displays it to the user.
[0052] Optionally, before sending the content of the target historical topic to the large language model, content distillation can be performed on all messages of the target historical topic to obtain distilled topic content, and then the distilled topic content can be sent to the large language model as supplementary context information.
[0053] Optionally, the content of the target historical topic and the question content of the current round can be combined to form a new prompt message. This can be done by directly combining the two, that is, placing the content of the target historical topic in the first half of the prompt and the question content of the current round in the second half, and adding a clear separator between the two.
[0054] Understandably, this step involves resending historical topic content as supplementary information to the large language model, enabling it to refer to complete dialogue information from historical topics when answering the current question, thereby generating a more accurate and targeted response.
[0055] This embodiment provides a context loading method. After obtaining the collected historical topic set and the question content of the current round, the question content is first sent to the large language model and the first response content returned is obtained, so that the loading decision is triggered at the inference output stage of the agent. When the first response content contains a topic tag indicating that at least one historical topic needs to be loaded, in response to the confirmation operation of the topic tag, the target historical topic is accurately extracted from the historical topic set according to the topic tag, and then the content of the target historical topic is sent to the large language model as context supplementary information of the question content, and the final response content is obtained. Therefore, the selection of historical topics to be loaded is no longer entirely determined by automatic decision-making algorithms such as sliding windows, vector retrieval, or automatic summarization. Instead, the large language model actively indicates these topics through topic tags during the reasoning process for the current question, allowing the user to intervene and grant permission through a confirmation operation. Users no longer need to manually search, memorize, or infer relevant historical dialogues from a long-running conversation record with numerous topics, eliminating the manual operation burden that increases linearly with the conversation duration and the number of topics. This also overcomes the shortcomings of existing automatic loading schemes, where users cannot know the loaded content in advance or intervene when the loading decision does not match their intentions. As a result, the final context fed into the large language model always aligns with the user's actual needs, significantly improving the usability and accuracy of the large language model's responses and effectively solving the problem of poor effectiveness of existing context loading methods in intelligent agent dialogue systems.
[0056] Based on the above embodiments of this application, in another embodiment of this application, the same or similar content as the above embodiments can be referred to the above description, and will not be repeated hereafter. In addition, after step S3, the method further includes: Step S31: Perform content distillation on the target historical topic to obtain distilled topic content; It should be noted that after the electronic device extracts the target historical topic, in order to prevent the context window from being wasted and the effective semantic density from being reduced due to the inclusion of a large amount of unnecessary information (such as tool call logs, lengthy agent replies, thought processes, full text of attachments, etc.), the electronic device performs content distillation on all messages in the target historical topic.
[0057] Content distillation refers to the process of structurally reducing noise and compressing the content of each message in a target historical topic according to preset rules. After performing content distillation on an electronic device, the distilled topic content is obtained.
[0058] Optionally, content distillation may include at least one of the following operations: deleting tool call records in the target historical topic to obtain first distilled content; truncating agent replies returned by the large language model in the target historical topic based on a preset first character length threshold to obtain second distilled content; truncating user messages in the target historical topic based on a preset second character length threshold to obtain third distilled content; and replacing attachment content in the target historical topic with filename references to obtain fourth distilled content.
[0059] Understandably, this step significantly reduces the token usage of historical topics by performing content distillation on them, while retaining the core dialogue information needed to answer the current question, thus significantly improving the effective semantics of the contextual supplementary information subsequently sent to the large language model.
[0060] Step S32: Use the distilled topic content as supplementary contextual information for the question content.
[0061] It should be noted that after obtaining the distilled topic content, the electronic device determines the distilled topic content as supplementary contextual information corresponding to the question content in the current round.
[0062] This contextual supplementary information is used in subsequent steps to be concatenated with the question content of the current round and sent to the large language model, so that the large language model can refer to the information in the target historical topic when answering the question content of the current round.
[0063] Optionally, the contextual supplementary information can be the content of the target historical topic sent by the electronic device to the large language model in step S4. The distilled topic content, as contextual supplementary information, has a token volume much smaller than the total volume of the original message of the target historical topic.
[0064] Understandably, this step uses the compressed and simplified distilled topic content as supplementary contextual information. While ensuring that the core information of the historical topic is preserved, it effectively reduces the token occupation of the context window, thereby reducing the reasoning cost.
[0065] In one feasible implementation, step S32 includes: Step A31: Delete the tool call records in the target historical topic to obtain the first distillation content; It should be noted that after the electronic device extracts the target historical topic, it traverses all messages in the target historical topic, identifies the message type of each message, and identifies messages that belong to the tool call type as tool call records.
[0066] Optionally, deleting tool call records in the target historical topic means that the target historical topic may contain tool call processes, tool call parameters, and tool call return values. These records are usually not necessary for answering the questions in the current round, so the electronic device removes the tool call records from the target historical topic.
[0067] Tool call records are generated by the large language model during historical dialogues when it invokes external tools (such as search engines, database query interfaces, code execution environments, etc.) to obtain external information or perform specific operations. These records include at least the tool call process, tool call parameters, and tool call return values. While these tool call records are valuable for understanding the dialogue logic and results in historical topics, they are generally not necessary for answering questions in the current round, and their long text length consumes a significant amount of tokens. Therefore, the electronic device identifies and deletes tool call records from the target historical topic, meaning it does not retain any fields or text from tool call records in the distilled topic content. After deleting the tool call records, the electronic device uses all remaining messages in the target historical topic as the first distillation content.
[0068] Understandably, this step removes log-like information from historical topics that is irrelevant to the core semantic dialogue by deleting tool call records, effectively reducing the volume of content subsequently sent to the large language model.
[0069] Step A32: Extract the response information returned by the large language model in the target historical topic based on a preset first character length threshold to obtain the second distilled content; It should be noted that the electronic device extracts all the response information returned by the large language model in the historical dialogue from the remaining messages of the target historical topic.
[0070] The response information is the text generated by the large language model in each round of the historical dialogue in response to the user's previous questions. It includes the complete analysis process, reasoning steps, and conclusion statements, and the text is quite long. However, the contribution of each response information in the historical topics to answering the question in the current round is different. Retaining the full content of all response information would lead to token waste and introduce redundant information. Therefore, the electronic device truncates each extracted response information based on a preset first character length threshold.
[0071] Optionally, the agent's responses returned by the large language model in the target historical topic are truncated based on a preset first character length threshold. This means that the electronic device truncates the complete text of each response from the beginning to the character position indicated by the first character length threshold, discarding any portion exceeding this threshold. The preset first character length threshold is a configurable upper limit for the number of characters, for example, it can be set to 80 characters. The electronic device then combines all the truncated response messages according to their original order in the target historical topic to obtain the second distilled content.
[0072] Understandably, this step preserves the core message of each response by extracting the text of the agent's reply, while significantly reducing the token usage of the reply information.
[0073] Step A33: Extract the historical question content from the target historical topic based on a preset second character length threshold to obtain the third distilled content; It should be noted that electronic devices extract the questions that users entered in historical conversations from the remaining messages of the target historical topic.
[0074] Historical question content comprises messages entered by the user in each round of the historical dialogue—that is, every question or instruction the user posed to the large language model during the conversation. Since user-entered questions in historical dialogues may contain lengthy background descriptions, complex problem statements, or multi-layered nested instructions, retaining the entire body of all historical question content would lead to excessive token consumption. Therefore, the electronic device truncates each extracted historical question content based on a preset second character length threshold. This preset second character length threshold is a configurable upper limit for the number of characters; its value can differ from the first character length threshold, for example, it can be set to 200 characters. Alternatively, its value can be the same as the first character length threshold, depending on the length of the historical question content.
[0075] The electronic device truncates the complete text of each historical question from the beginning to the character position indicated by the second character length threshold, discarding any portion exceeding the threshold. The electronic device then combines all the truncated historical questions in their original order within the target historical topic to obtain the third distillation content.
[0076] Understandably, this step preserves the core expression of users' past requests by truncating a limited length of historical questions, while effectively controlling the token usage of historical questions.
[0077] Step A34: Replace the attachment content in the target historical topic with filename references to obtain the fourth distillation content; It should be noted that electronic devices identify attachments uploaded by users in historical conversations from the remaining messages of the target historical topic.
[0078] Attachments are content sent by users in file format, such as documents, images, tables, code files, etc. These attachments typically contain large amounts of text or binary data. Directly inlining the complete text or all data of the attachment into the distilled topic content would consume a large amount of tokens and have low effective information density. Therefore, electronic devices do not inline the complete text of the attachment into the distillation result. Instead, they extract the filename of the attachment from the attachment's metadata and replace the attachment content with a reference identifier for that filename.
[0079] Optionally, the filename reference can be in the form of "(attachments: filename1, filename2, ...)".
[0080] The electronic device combines all the replaced messages in their original order within the target historical topic to obtain the fourth distillation content.
[0081] Understandably, this step avoids consuming a large amount of tokens from the attachment body by replacing the attachment content with filename references, while preserving the contextual indication that the user has uploaded attachments.
[0082] Step A35: Based on the first distillation content, the second distillation content, the third distillation content, and the fourth distillation content, obtain the distilled topic content.
[0083] It should be noted that after the electronic device obtains the first distillation content, the second distillation content, the third distillation content, and the fourth distillation content respectively, it splices and combines the above four parts of distillation content according to the time sequence of the original messages in the target historical topic.
[0084] Optionally, steps A31-A34 can be executed sequentially or in parallel. If executed sequentially, the four parts of the distilled content are directly concatenated according to the chronological order of the original messages in the target historical topic to obtain the distilled topic content. If executed in parallel, the four parts of the distilled content are deduplicated and then concatenated according to the chronological order of the original messages in the target historical topic to obtain the distilled topic content.
[0085] Specifically, the electronic device iterates through the original message sequence of the target historical topic. For each original message, it extracts the distilled text fragments from the corresponding distillation content based on its message type. Then, it arranges these text fragments in the chronological order of the original messages, combining them into a single distilled topic content. The distilled topic content is a simplified version of the target historical topic after structured noise reduction, and its token size is much smaller than the total size of the original messages of the target historical topic.
[0086] Optionally, after obtaining the distilled topic content, the electronic device can also add a start separator containing the topic name of the target historical topic at the beginning of the distilled topic content and an end separator at the end of the distilled topic content.
[0087] Optionally, content distillation may also include: retaining only the reply text field from thought messages in the target historical topic, or discarding the complete thought process.
[0088] Understandably, this step preserves the causal relationships and logical order of multiple rounds of dialogue in the target historical topic by piecing together the distilled content in its original order, while simultaneously compressing and reorganizing the core content of the historical topic.
[0089] For example, to help understand the implementation flow of the context loading method obtained by combining this embodiment with the above embodiments, please refer to... Figure 2 After extracting the target historical topic, content distillation is performed, mainly including: deleting tool call records, where the electronic device iterates through all messages in the target historical topic and deletes records belonging to the tool call type, resulting in the first distilled content; truncating model response information, where the agent response text returned by the large language model in the target historical topic is truncated based on a preset first character length threshold, resulting in the second distilled content, thus compressing the token consumption of the response information; truncating historical question content, where the historical question text entered by the user in the target historical topic is truncated based on a preset second character length threshold, resulting in the third distilled content, thus effectively controlling the token consumption of historical question content; and replacing attachment content, where attached files in the target historical topic are identified, and instead of retaining the attachment body, the attachment content is replaced with filename references, resulting in the fourth distilled content, preserving contextual hints while avoiding large token consumption of the attachment body. Finally, the four distilled contents (first distilled content, second distilled content, third distilled content, and fourth distilled content) are concatenated and combined according to the time order of the original messages in the target historical topic, or concatenated and combined after deduplication, to obtain the distilled topic content, which serves as supplementary contextual information sent to the large language model. This not only preserves the core logic and key information of the historical topic, but also significantly reduces the token usage.
[0090] Based on the above embodiments of this application, in another embodiment of this application, the same or similar content as the above embodiments can be referred to the above description, and will not be repeated hereafter. On this basis, when the topic marker is a topic demand marker, the topic demand marker is used to indicate at least one historical topic that the large language model needs to load to answer the question content of the current round. Step S4 includes: Step A41: Combine the content of the target historical topic with the question content of the current round to form the first prompt word; It should be noted that when the topic is marked as a topic demand mark, the topic demand mark indicates that the large language model needs to load at least one historical topic in order to answer the question in the current round.
[0091] After extracting the target historical topic, the electronic device needs to concatenate the content of the target historical topic with the question content of the current round to construct prompt words that contain both historical context information and the current user's question, so that the large language model can refer to the content of the historical topic and the current user's question at the same time during subsequent reasoning.
[0092] Concatenation refers to combining the content of the target historical topic with the questions in the current round into a text sequence according to a preset order.
[0093] Optionally, the splicing order can be: placing the content of the target historical topic before the question content of the current round, that is, presenting all the content of the historical topic first, and then presenting the current user's question, so that the large language model can understand the historical context first and then process the current question; or, placing the question content of the current round before the content of the target historical topic.
[0094] Optionally, during the concatenation process, the electronic device also adds a clear separator between the content of the target historical topic and the question content of the current round, so that the large language model can distinguish which content belongs to the historical topic and which content belongs to the current question. The electronic device uses the concatenated text sequence as the first prompt word.
[0095] Optionally, the content of the target historical topic can be all the original messages of the target historical topic without processing, or it can be the distilled topic content obtained after content distillation.
[0096] Understandably, this step combines historical topic content with the current question content into prompt words, which are then sent to the large language model later.
[0097] Step A42: Send the first prompt word to the large language model and obtain the second response content returned by the large language model for the question content of the current round.
[0098] It should be noted that after the electronic device obtains the first prompt word by concatenating the words, it sends the first prompt word as input to the large language model by calling the API provided by the large language model.
[0099] After receiving the first prompt word, the large language model performs comprehensive reasoning based on the content of the target historical topic contained in the first prompt word and the question content of the current round. That is, the large language model not only refers to the contextual information in the historical topic, but also understands the current user's question, and finally generates a response text for the question content of the current round.
[0100] This response text is the second response to the question asked in the current round. The large language model returns this second response to the electronic device via API, and the electronic device receives it.
[0101] Optionally, after obtaining the second response content, the electronic device displays the second response content as the final response content to the user.
[0102] Understandably, this step sends the first cue words containing both historical topic content and the current question content to the large language model, enabling it to generate more accurate and targeted responses based on the complete context of the historical topic when answering the current question. This addresses the limitation of the large language model in accurately answering the current question due to the lack of historical context.
[0103] In one feasible implementation, when the topic marker is a topic continuation marker, the topic continuation marker is used to indicate at least one historical topic that the large language model needs to load to answer the next question in the next round. Step S4 includes: Step B41: Cache the content of the target historical topic; It should be noted that when a topic is marked as a topic continuation marker, the topic continuation marker indicates that the large language model intends to continue using the content of one or more historical topics in the next round. Unlike the topic demand marker, the historical topics indicated by the topic continuation marker are used to answer new questions that the user will ask in the next round.
[0104] After retrieving a target historical topic, the electronic device stores the content of that topic in its temporary storage space, i.e., it performs a caching operation. Caching refers to temporarily storing data in the electronic device's memory (such as RAM or persistent storage) so that it can be quickly retrieved when needed later, without having to retrieve it again from the historical topic collection.
[0105] Optionally, the content of the target historical topic can be all the original messages of the target historical topic without processing, or it can be the distilled topic content obtained after content distillation.
[0106] When electronic devices cache data, they can also associate the topic identifier of the target historical topic with the cached content for storage, so as to identify which topic the cached content corresponds to in the future.
[0107] Optionally, electronic devices can set an expiration time for the cache, for example, automatically clearing the cache to free up storage space when the next round does not arrive within a preset time.
[0108] Understandably, this step caches the content of the target historical topic and delays the loading action indicated by the topic continuation marker from the current round to the next round, thus achieving asynchronous loading with the current round and enabling the topic continuation intent of the large language model to take effect in subsequent dialogues.
[0109] Step B42: When the content of the next question in the next round is obtained, the content of the target historical topic and the content of the next question are concatenated to form the second prompt word; It should be noted that after caching the content of the target historical topic, the electronic device continues to listen to the user's input operations in the interactive interface.
[0110] Optionally, when a user enters a new message after the current round, it constitutes the next round, and the message entered by the user in the next round becomes the content of the next question.
[0111] Optionally, after obtaining the content of the next question, the electronic device reads the content of the previously stored target historical topic from the cache, and then concatenates the content of the target historical topic with the content of the next question to construct a prompt word that contains both historical context information and the next round of user questions.
[0112] Optionally, splicing refers to combining the content of the target historical topic and the content of the next question into a text sequence in a preset order.
[0113] Optionally, the splicing order can be: placing the content of the target historical topic before the content of the next question, that is, presenting the entire content of the historical topic first, and then presenting the question of the next round of users, so that the large language model can understand the historical context first and then process the question of the next round.
[0114] Optionally, during the stitching process, the electronic device can also add a separator between the content of the target historical topic and the content of the next question, so that the large language model can distinguish which content belongs to the historical topic and which content belongs to the next round of questions.
[0115] Optionally, the electronic device uses the concatenated text sequence as a second prompt word.
[0116] Understandably, this step is performed only after the next round of questions arrives, ensuring that the content of the target historical topic is combined with the user's latest question intent, rather than with outdated questions from the current round.
[0117] Step B43: Send the second prompt word to the large language model and obtain the second response content returned by the large language model for the next question.
[0118] It should be noted that after the electronic device obtains the second prompt word, it sends the second prompt word as input to the large language model by calling the application programming interface provided by the large language model.
[0119] After receiving the second prompt word, the large language model performs comprehensive reasoning based on the content of the target historical topic contained in the second prompt word and the content of the next question in the next round. That is, the large language model not only refers to the contextual information in the historical topic, but also understands the user's new question in the next round, and finally generates a response text for the next question in the next round.
[0120] This response text constitutes the second response to the next question. The large language model returns this second response to the electronic device via an application programming interface (API), and the electronic device receives it.
[0121] Optionally, after obtaining the second response content, the electronic device may display the second response content as the final response content for the next round to the user.
[0122] Understandably, this step involves concatenating the content of the target historical topic with the content of the next question in the next round and sending it to the large language model. This enables the large language model to generate a response based on the context of the historical topic when answering the question in the next round, achieving the technical effect of the large language model actively declaring the continuation of the topic and continuing the context of the historical topic in subsequent dialogues.
[0123] In one feasible implementation, the topic tag includes a dependency identifier for each target historical topic, the dependency identifier indicating that the first target historical topic depends on the second target historical topic; prior to step S3, the method further includes: Step D31: Based on the dependency identifier, identify the first target historical topic and the second target historical topic, and arrange the second target historical topic before the first target historical topic; It should be noted that after the electronic device detects that the first response content contains a topic tag, and before performing the step of extracting the target historical topic from the historical topic set based on the topic tag, it further parses the topic tag to extract the dependency identifier of each target historical topic contained therein.
[0124] The dependency identifier is a string embedded in the topic tag by the large language model to indicate the dependency relationship between each target historical topic. This dependency identifier is used to indicate that the first target historical topic depends on the second target historical topic.
[0125] The first target historical topic is a topic that depends on other topics, while the second target historical topic is a topic that the first target historical topic depends on. That is, the content of the second target historical topic needs to be loaded and understood before the first target historical topic. Otherwise, the large language model may not be able to understand correctly when it makes inferences based on the first target historical topic due to the lack of prior context.
[0126] Dependency identifiers can use a conventional format, such as annotating each topic in the topic tag with "depends: topic identifier", indicating that the topic depends on the topic it points to.
[0127] The electronic device resolves the target historical topic pairs that have a dependency relationship based on the dependency identifier, and identifies the first target historical topic as the dependent party and the second target historical topic as the dependent party.
[0128] After identifying the first target historical topic and the second target historical topic, the electronic device arranges the target historical topics according to the order of their dependencies, placing the second target historical topic, which is the dependent party, before the first target historical topic.
[0129] Understandably, this step ensures that the historical topics sent to the large language model satisfy the causal or temporal dependency order by sorting the target historical topics according to their dependencies, thus avoiding the problem of information loss caused by the large language model processing dependent topics in the absence of preceding topics.
[0130] Step D32: The content of the second target historical topic is sent to the large language model as supplementary contextual information; It should be noted that after the electronic device arranges the second target historical topic before the first target historical topic according to the dependency relationship, it first sends the content of the second target historical topic as supplementary context information to the large language model in the order of arrangement.
[0131] Optionally, the content of the second target history topic can be the entire original message of the unprocessed second target history topic, or it can be the distilled topic content obtained after content distillation.
[0132] Sending the content of the second target historical topic to the large language model can be done by calling the application programming interface provided by the large language model, using the content of the second target historical topic as input prompt information.
[0133] Understandably, this step first sends the content of the second target historical topic that is being relied upon, so that the large language model can establish a foundation for understanding the content of the preceding topic before it comes into contact with the dependent topic.
[0134] Step D33: Obtain the first intermediate response content returned by the large language model based on the content of the second target historical topic; It should be noted that after the electronic device sends the content of the second target historical topic to the large language model, the large language model performs inference based on the received content of the second target historical topic, generates an intermediate response for that content, and returns it to the electronic device through the application programming interface.
[0135] The electronic device receives this intermediate response and uses it as the content of the first intermediate response.
[0136] Optionally, the first intermediate response content is generated by the large language model when it has only referenced the content of the second target historical topic, but has not yet referenced the content of the first target historical topic. The first intermediate response content may contain the large language model's preliminary judgment on the current round's question content based on the content of the second target historical topic, or it may contain a flag from the large language model indicating whether further loading of the first target historical topic is needed.
[0137] Optionally, after obtaining the first intermediate response content, the electronic device can parse the first intermediate response content and detect whether it contains a specific tag used to indicate whether the information is complete.
[0138] Understandably, this step involves first obtaining intermediate response content based on the dependent topic, which is then used to determine whether the dependent topic needs to be loaded.
[0139] Step D34: When the first intermediate response content does not contain all the information required to answer the question, the content of the first target historical topic and the content of the second target historical topic are sent together as contextual supplementary information to the large language model to obtain the fourth response content.
[0140] It should be noted that after the electronic device obtains the first intermediate response content, it parses the first intermediate response content to determine whether the first intermediate response content contains the complete information required to answer the question in the current round.
[0141] Optionally, determining whether the content of the first intermediate response contains complete information can be achieved by detecting whether the content of the first intermediate response contains a specific marker. For example, when the large language model determines that the content of the second target historical topic is insufficient to answer the current question, a conventional marker such as "INSUFFICIENT_INFO" can be embedded in the content of the first intermediate response. When the electronic device detects the marker, it determines that it does not contain complete information.
[0142] Optionally, the large language model can directly declare in natural language within the first intermediate response content whether the first target historical topic needs to be loaded. When the first intermediate response content does not contain the complete information required to answer the current round's question, it indicates that the large language model cannot fully answer the current question by referring only to the second target historical topic, and requires the content of the first target historical topic to generate a complete answer. In this case, the electronic device sends the content of both the first and second target historical topics as supplementary contextual information to the large language model.
[0143] Optionally, before sending, the electronic device can concatenate the content of the first target historical topic and the content of the second target historical topic according to the order determined in step D31, that is, the content of the second target historical topic first and the content of the first target historical topic last, to ensure the correct dependency order. The large language model performs inference based on the content of the two commonly received topics, generates an updated response text, and returns it to the electronic device through the application programming interface. The electronic device receives this response text as the fourth response content.
[0144] Optionally, the fourth response content can be the final response content generated in response to the question asked in the current round. Optionally, the fourth response content can also be stored as a historical dialogue message of the current round in the local storage of the electronic device for use in topic aggregation or context construction in subsequent rounds.
[0145] Understandably, this step implements an on-demand loading mechanism that determines whether to load dependent topics based on actual needs by loading the first target historical topic only when the content of the first intermediate response is incomplete. This avoids the waste of tokens caused by loading all dependent topics indiscriminately.
[0146] Based on the above embodiments of this application, in another embodiment of this application, the same or similar content as the above embodiments can be referred to the above description, and will not be repeated hereafter. Based on this, after step S2, the following is included: Step S21: When the first response content contains the topic tag, display a confirmation prompt for the target historical topic indicated by the topic tag; It should be noted that after the electronic device receives the first response content returned by the large language model, it parses the first response content and detects whether it contains topic tags.
[0147] When the first response content contains a topic tag, the electronic device extracts the topic identifier of at least one historical topic that needs to be loaded from the topic tag, and searches for the corresponding historical topic in the collected historical topic set according to the topic identifier, and identifies it as the target historical topic.
[0148] Because this application employs a dual control mechanism combining agent-driven decision-making and user confirmation, the electronic device cannot directly load the target historical topic; user authorization is required. Therefore, the electronic device displays a confirmation prompt through the user interface, asking the user whether they agree to load the content of the target historical topic indicated by the topic tag.
[0149] Optionally, the confirmation prompt may include the topic name or topic number of the target historical topic, such as displaying a pop-up message: "The smart assistant wants to load topic A. Do you agree?"
[0150] Optionally, the confirmation prompt may also include a preview of the target historical topic to help users recall the general content of the topic.
[0151] Understandably, this step, by showing the user a confirmation prompt, gives the user the final say on loading historical topics, thus giving the user control over the context loading sent to the large language model.
[0152] Step S22: In response to the rejection operation of the confirmation prompt, control the large language model to answer the question content of the current round based on the current visible context; It should be noted that after displaying the confirmation prompt, the electronic device waits for the user to make a choice through the interactive interface. The user can choose to agree to load or refuse to load.
[0153] When a user chooses to refuse loading, that is, the user has performed a refusal operation on the confirmation prompt. After the electronic device detects the refusal operation, it determines that no content from any historical topics will be loaded this time.
[0154] Since the content of the target historical topic has not been loaded, the context available to the large language model is limited to the question content of the current round and the visible context that already existed in the large language model's dialogue window before the current round.
[0155] The currently visible context refers to all the context information currently available to the large language model without loading any additional historical topic content.
[0156] Optionally, the currently visible context may contain only the question content of the current round, or it may contain previously loaded dialogue content that has not yet been cleared. After determining that it will not load historical topics, the electronic device controls the large language model to answer the question content of the current round based on the currently visible context.
[0157] Optionally, controlling the large language model to answer the question content of the current round based on the currently visible context can be achieved by sending the question content of the current round to the large language model separately (without any historical topic content), or by concatenating the currently visible context with the question content of the current round and then sending it to the large language model.
[0158] Understandably, this step controls the loading of historical topics through the user's rejection action. After the user rejects the response, the large language model only answers based on the currently available information, thus preventing historical information that the user does not agree with from entering the context.
[0159] Step S23: Obtain the third response content returned by the large language model based on the current visible context; It should be noted that after the electronic device controls the large language model to answer the question content of the current round based on the currently visible context, the large language model performs reasoning based on the currently visible context, generates a response text for the question content of the current round, and returns the response text to the electronic device through the application programming interface.
[0160] The electronic device receives the reply text and uses it as the content of a third response.
[0161] Optionally, the third response content is a reply generated by the large language model based solely on the currently visible context without loading the target historical topic.
[0162] Understandably, this step obtains the actual response content of the large language model after the user refused to load the historical topics, which is used to determine whether it is necessary to try loading the historical topics again.
[0163] Step S24: When the topic tag is included in the third response content, a reconfirmation prompt for the historical topic corresponding to the topic tag is displayed.
[0164] It should be noted that after the electronic device obtains the third response content, it parses the third response content and detects whether it contains topic tags.
[0165] When the third response content still contains topic tags, it indicates that after answering based on the current visible context, the large language model still believes that some historical topics need to be loaded to more accurately answer the question in the current round. In other words, the quality of the initial response generated by the large language model in the absence of historical topics is insufficient to meet the user's needs.
[0166] In this situation, the electronic device again displays a confirmation prompt through the user interface, which asks the user again whether they agree to load the historical topic corresponding to the topic tag in the third response content.
[0167] Optionally, the content of the confirmation prompt can be the same as or similar to the confirmation prompt shown in step S21, such as displaying the message "The smart assistant requests to load topic A again, do you agree?"
[0168] Optionally, the confirmation prompt may also include the reason for loading explained in the third response content of the large language model to help users determine whether they need to agree to loading again.
[0169] Optionally, after displaying the reconfirmation prompt for the historical topic corresponding to the topic marker, when the user performs a confirmation operation, i.e., steps S3-S4 are executed, and the final response content is obtained. When the user performs a rejection operation, after reaching a preset number of rejections, such as two or three, the user answers the question content of the current round based on the currently visible context, and the final response content is obtained.
[0170] Optionally, if the third response content does not contain a topic tag, the third response content shall be used as the final response content.
[0171] Understandably, this step, by setting up a reconfirmation prompt, gives the user a second chance to confirm when the large language model still believes that historical information is needed even without a historical topic. This avoids the problem of the large language model continuously outputting low-quality answers due to a lack of context after the user's initial rejection, while retaining the user's final control.
[0172] For example, to help understand the implementation flow of the context loading method obtained by combining this embodiment with the above embodiments, please refer to... Figure 3After obtaining the first response from the large language model based on the question content of the current round, it is determined whether the first response contains a topic tag. If the first response does not contain a topic tag, it means that the large language model can answer based on the current context, and the first response is directly output as the final response. If the first response contains a topic tag and the user performs a confirmation operation, the target historical topic is extracted from the historical topic set based on the topic tag; then, the content of the target historical topic is distilled to obtain the distilled topic content; the distilled topic content is sent to the large language model as supplementary context information to obtain the second response, which is output as the final response. If the first response contains a topic tag and the user chooses to refuse, no historical topics are loaded, and the large language model is controlled to answer only based on the currently visible context to obtain the third response, which is output as the final response. If the model still requires historical information after the user refuses, a reconfirmation prompt can be triggered. Figure 3 (Not shown in the text). Through the above three branching paths, the accuracy of on-demand topic loading is ensured, while also giving users full control over context loading, thus ensuring the accuracy and controllability of the final response content.
[0173] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the context loading method of this application. Any simple variations based on this technical concept, such as the interaction and combination of various embodiments, are all within the protection scope of this application.
[0174] This application also provides a context loading device, please refer to... Figure 4 The context loading device includes: Module 10 is used to obtain the questions asked in the current round and the collection of historical topics. The response module 20 is used to send the question content to the large language model and obtain the first response content returned by the large language model; The extraction module 30 is configured to extract a target historical topic from the historical topic set based on the topic tag in response to a confirmation operation on the topic tag when the first response content contains a topic tag, wherein the topic tag is used to indicate at least one historical topic that needs to be loaded. The supplementary module 40 is used to send the content of the target historical topic as supplementary contextual information of the question content to the large language model, and to obtain the second response content returned by the large language model, and to use the second response content as the final response content.
[0175] Optionally, the extraction module 30 is used to perform content distillation on the target historical topic to obtain distilled topic content; The distilled topic content is used as supplementary contextual information for the question content.
[0176] Optionally, the extraction module 30 is used to delete the tool call records in the target historical topic to obtain the first distillation content; The response information returned by the large language model in the target historical topic is truncated based on a preset first character length threshold to obtain the second distilled content; The historical questions in the target historical topic are truncated based on a preset second character length threshold to obtain the third distilled content; Replace the attachment content in the target historical topic with filename references to obtain the fourth distillation content; Based on the first distillation content, the second distillation content, the third distillation content, and the fourth distillation content, the topic content after distillation is obtained.
[0177] Optionally, when the topic tag is a topic demand tag, the topic demand tag is used to indicate at least one historical topic that the large language model needs to load to answer the question content of the current round. The supplementary module 40 is used to concatenate the content of the target historical topic with the question content of the current round to form a first prompt word. The first prompt word is sent to the large language model, and the second response content returned by the large language model for the question content of the current round is obtained.
[0178] Optionally, when the topic marker is a topic continuation marker, the topic continuation marker is used to indicate at least one historical topic that the large language model needs to load to answer the next question in the next round. The supplementary module 40 is used to cache the content of the target historical topic. When the content of the next question in the next round is obtained, the content of the target historical topic and the content of the next question are concatenated to form the second prompt word; The second prompt word is sent to the large language model, and the second response content returned by the large language model for the next question is obtained.
[0179] Optionally, the response module 20 is configured to display a confirmation prompt for the target historical topic indicated by the topic tag when the first response content contains the topic tag; In response to the rejection operation of the confirmation prompt, the large language model is controlled to answer the question content of the current round based on the current visible context; Obtain the third response content returned by the large language model based on the current visible context; When the topic tag is included in the third response content, a reconfirmation prompt for the historical topic corresponding to the topic tag is displayed.
[0180] Optionally, the topic tag includes a dependency identifier for each target historical topic, the dependency identifier being used to indicate that the first target historical topic depends on the second target historical topic; the extraction module 30 is used to identify the first target historical topic and the second target historical topic according to the dependency identifier, and to arrange the second target historical topic before the first target historical topic; The content of the second target historical topic is sent as supplementary contextual information to the large language model; Obtain the first intermediate response content returned by the large language model based on the content of the second target historical topic; When the first intermediate response content does not contain all the information required to answer the question, the content of the first target historical topic and the content of the second target historical topic are sent together as supplementary context information to the large language model to obtain the fourth response content.
[0181] The context loading device provided in this application, employing the context loading method in the above embodiments, can solve the technical problem of poor effectiveness of existing context loading methods in intelligent agent dialogue systems. Compared with the prior art, the beneficial effects of the context loading device provided in this application are the same as those of the context loading method provided in the above embodiments, and other technical features in the context loading device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0182] This application provides an electronic device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the context loading method in the first embodiment described above.
[0183] The following is for reference. Figure 5 It shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of this application. Figure 5 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0184] like Figure 5As shown, the electronic device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory 1002 or a program loaded from a storage device 1003 into a random access memory 1004. The random access memory 1004 also stores various programs and data required for the operation of the electronic device. The processing unit 1001, the read-only memory 1002, and the random access memory 1004 are interconnected via a bus 1005. An input / output interface 1006 is also connected to the bus. Typically, the following systems can be connected to the input / output interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. The communication device 1009 allows the electronic device to communicate wirelessly or wiredly with other devices to exchange data. Although the diagrams show electronic devices with various systems, it should be understood that it is not required to implement or have all of the systems shown. More or fewer systems may be implemented alternatively.
[0185] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from read-only memory 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0186] The electronic device provided in this application, employing the context loading method in the above embodiments, can solve the technical problem of poor effectiveness of existing context loading methods in intelligent agent dialogue systems. Compared with the prior art, the beneficial effects of the electronic device provided in this application are the same as those of the context loading method provided in the above embodiments, and other technical features of the electronic device are the same as those disclosed in the methods of the above embodiments, and will not be repeated here.
[0187] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0188] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0189] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the context loading method in the above embodiments.
[0190] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0191] The aforementioned computer-readable storage medium may be included in an electronic device or may exist independently without being assembled into an electronic device.
[0192] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0193] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0194] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0195] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described context loading method, which can solve the technical problem of poor effectiveness of existing context loading methods in intelligent agent dialogue systems. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the context loading method provided in the above embodiments, and will not be repeated here.
[0196] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the context loading method described above.
[0197] The computer program product provided in this application can solve the technical problem of poor effectiveness of existing context loading methods in intelligent agent dialogue systems. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the context loading method provided in the above embodiments, and will not be repeated here.
[0198] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A context loading method, characterized in that, The context loading method includes: Retrieve the questions asked in the current round and the collected historical topics; The question content is sent to the large language model, and the first response content returned by the large language model is obtained; When the first response content includes a topic tag, in response to the confirmation operation of the topic tag, a target historical topic is extracted from the historical topic set according to the topic tag, wherein the topic tag is used to indicate at least one historical topic that needs to be loaded. The content of the target historical topic is sent to the large language model as supplementary contextual information for the question content, and the second response content returned by the large language model is obtained. The second response content is then used as the final response content.
2. The method as described in claim 1, characterized in that, Following the step of extracting the target historical topic from the historical topic set based on the topic tag, the method further includes: The target historical topic is subjected to content distillation to obtain distilled topic content; The distilled topic content is used as supplementary contextual information for the question content.
3. The method as described in claim 2, characterized in that, The step of performing content distillation on the target historical topic to obtain the distilled topic content includes: Delete the tool call records in the target historical topic to obtain the first distillation content; The response information returned by the large language model in the target historical topic is truncated based on a preset first character length threshold to obtain the second distilled content; The historical questions in the target historical topic are truncated based on a preset second character length threshold to obtain the third distilled content; Replace the attachment content in the target historical topic with filename references to obtain the fourth distillation content; Based on the first distillation content, the second distillation content, the third distillation content, and the fourth distillation content, the topic content after distillation is obtained.
4. The method as described in claim 1, characterized in that, When the topic is marked as a topic demand marker, the topic demand marker is used to indicate at least one historical topic that the large language model needs to load to answer the question content in the current round. The step of obtaining the second response content returned by the large language model includes: The content of the target historical topic is combined with the question content of the current round to form the first prompt word; The first prompt word is sent to the large language model, and the second response content returned by the large language model for the question content of the current round is obtained.
5. The method as described in claim 1, characterized in that, When the topic marker is a topic continuation marker, the topic continuation marker is used to indicate at least one historical topic that the large language model needs to load to answer the next question in the next round. The step of obtaining the second response content returned by the large language model includes: Cache the content of the target historical topic; When the content of the next question in the next round is obtained, the content of the target historical topic and the content of the next question are concatenated to form the second prompt word; The second prompt word is sent to the large language model, and the second response content returned by the large language model for the next question is obtained.
6. The method as described in claim 1, characterized in that, Following the step of obtaining the first response content returned by the large language model, the following is included: When the first response content contains the topic tag, a confirmation prompt for the target historical topic indicated by the topic tag is displayed; In response to the rejection operation of the confirmation prompt, the large language model is controlled to answer the question content of the current round based on the current visible context; Obtain the third response content returned by the large language model based on the current visible context; When the topic tag is included in the third response content, a reconfirmation prompt for the historical topic corresponding to the topic tag is displayed.
7. The method as described in claim 1, characterized in that, The topic tag includes a dependency identifier for each target historical topic, which indicates that the first target historical topic depends on the second target historical topic. Prior to the confirmation operation on the topic tag, the method further includes: Based on the dependency identifier, identify the first target historical topic and the second target historical topic, and arrange the second target historical topic before the first target historical topic; The content of the second target historical topic is sent as supplementary contextual information to the large language model; Obtain the first intermediate response content returned by the large language model based on the content of the second target historical topic; When the first intermediate response content does not contain all the information required to answer the question, the content of the first target historical topic and the content of the second target historical topic are sent together as supplementary context information to the large language model to obtain the fourth response content.
8. A context loading device, characterized in that, The context loading device includes: The acquisition module is used to acquire the questions asked in the current round and the collection of historical topics. The response module is used to send the question content to the large language model and obtain the first response content returned by the large language model; An extraction module is configured to, in response to a confirmation operation on the topic tag, extract a target historical topic from the historical topic set based on the topic tag when the first response content contains a topic tag, wherein the topic tag is used to indicate at least one historical topic that needs to be loaded. The supplementary module is used to send the content of the target historical topic as supplementary contextual information of the question content to the large language model, and to obtain the second response content returned by the large language model, and use the second response content as the final response content.
9. An electronic device, characterized in that, The electronic device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the context loading method as described in any one of claims 1 to 7.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the steps of the context loading method as described in any one of claims 1 to 7.
