Intelligent agent construction method and device based on large model, storage medium and equipment
By constructing an agent based on a large model, this method selects dialogue scenarios using dialogue information and scene descriptions, generates multi-level contexts, and dynamically optimizes the tool list. This solves the problem that the agent cannot integrate user intent and preferences, and improves the accuracy of responses and tool recommendations.
Patent Information
- Application Number
- CN202511447364.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-11
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2045-10-11
Smart Images

Figure CN120952041A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a method, apparatus, storage medium and device for constructing intelligent agents based on large models. Background Technology
[0002] An intelligent agent (AI agent or AI bot) is an entity capable of perceiving its environment and taking actions to achieve a certain goal. It can be a software program, a robot, or other form of system. Intelligent agents are gradually becoming the primary way for humans to interact with large models (such as large language models).
[0003] The intelligent agent needs to generate system prompts based on the chat information input by the user, and then send the system prompts and candidate tools to a large model. Leveraging the large model's tool-calling capabilities, it identifies the tool the user needs and uses that tool to provide the desired answer. In related technologies, when building an intelligent agent, a fixed list of tools is typically pre-bound, recent chat logs are used as context, fixed system prompts are generated based on the context, and the intelligent agent is constructed based on the tool list and system prompts.
[0004] However, the context relies on short-term memory and has a weak perception of information in long-term memory, making it unable to accurately capture information related to user intent and effectively integrate user intent and behavioral preferences; the agent is single-scenario, and the tool list is not categorized by scenario, resulting in a low tool hit rate; furthermore, the agent's tool list and system prompts cannot be dynamically updated, failing to reflect the user's personalized preferences. Summary of the Invention
[0005] This application provides a method, apparatus, storage medium, and device for constructing intelligent agents based on large models, to address the problems of intelligent agents failing to integrate user intent and behavioral preferences, low tool hit rate, and the inability to dynamically update tool lists and system prompts, thus failing to reflect personalized user preferences. The technical solution is as follows: According to a first aspect of this application, a method for constructing intelligent agents based on large models is provided, the method comprising: Obtain the current dialogue information and scene description information of each scene input by the user, and select the matching dialogue scene based on the current dialogue information and the scene description information; Identify the intelligent agent corresponding to the dialogue scenario, and obtain tool call data for each tool from the description information of the intelligent agent; A short-term memory context is generated based on the acquired historical dialogue information, a tool context is generated based on the tool call data, a file context is generated based on the user-uploaded file, and a long-term memory context is generated based on the current dialogue information and the historical dialogue information corresponding to the dialogue scenario. The short-term memory context, the tool context, the file context, and the long-term memory context are combined to form a scenario context. A candidate tool list is generated based on the current dialogue information or the tool call data, and the tools in the candidate tool list are sorted according to the user's preferences; Generate system prompts based on the scene context and the candidate tool list; The agent corresponding to the dialogue scenario is optimized based on the system prompts and the candidate tool list to obtain an agent based on user preferences and context awareness.
[0006] In one possible implementation, selecting a matching dialogue scenario based on the scenario description information and the current dialogue information includes: Extract user preference descriptions for the scenario from the current dialogue information; For each dialogue scenario, obtain the scenario keywords from the scenario description information, and calculate the first similarity score between the current dialogue information, the preference description information, and the scenario keywords; If the first similarity score is greater than the first threshold, then the dialogue scenario is determined to be a dialogue scenario that matches the current dialogue information.
[0007] In one possible implementation, the method further includes: Obtain the user's feedback information in the next round of input; If it is determined from the feedback information that the dialogue scenario matching fails, then a similar dialogue scenario associated with the dialogue scenario is searched in the preset knowledge graph; Calculate the second similarity score between the current dialogue information and the scene keywords of each similar dialogue scene; The first similarity score is weighted and calculated with each second similarity score, and the similar dialogue scene corresponding to the maximum calculation result is determined as the dialogue scene that matches the current dialogue information.
[0008] In one possible implementation, the method further includes: Get feedback information when the user re-enters; If the feedback information determines that the dialogue scenario fails to match again, then the scenario keywords are extracted from the current dialogue information, and a new tool list is generated based on the current dialogue information and the tool call data of each dialogue scenario. A new dialogue scenario is created based on the scenario keywords and the new tool list, and the new dialogue scenario is determined as the dialogue scenario that matches the current dialogue information.
[0009] In one possible implementation, generating a long-term memory context based on the current dialogue information and the historical dialogue information corresponding to the dialogue scenario includes: Search for similar dialogue scenarios associated with the given dialogue scenario in a pre-defined knowledge graph; For each similar dialogue scenario, the most recent k historical data are searched from the latest memory vector library corresponding to the similar dialogue scenario. The historical data includes the scenario identifier of the similar dialogue scenario, the timestamp of a round of dialogue and dialogue information, and vectorized data blocks, where k is a positive integer. For the dialogue scenario, if the current dialogue information does not contain time information, then the k most recent historical data entries are searched from the latest memory vector library corresponding to the dialogue scenario; if the current dialogue information contains time information, then the k most recent historical data entries are searched from the historical memory vector library corresponding to the dialogue scenario using the time information as an index. A group of historical data entries in the historical memory vector library has similar dialogue content to a historical data entry in the latest memory vector library, and they are linked in a linked list according to the chronological order of the timestamps of each historical data entry. Remove historical data whose time interval from the current time is greater than the second threshold; The remaining historical data is used to form a long-term memory context.
[0010] In one possible implementation, generating the candidate tool list based on the current dialogue information or the tool call data includes: If the current dialogue information contains tool description information, then the top n tools with a matching degree greater than the third threshold are selected from the tool list, and the n tools are combined into a candidate tool list of the active invocation type, where n is a positive integer; If the current dialogue information does not contain tool description information, then the top n tools that best match the semantics of the current dialogue information are selected from the tool list. The historical call rate, feedback score, and active call rate of the n tools are obtained from the tool call information. The preference score of the n tools is calculated based on the historical call rate, the feedback score, and the active call rate. The n tools are sorted in descending order of preference score to obtain a candidate tool list for passive call type.
[0011] In one possible implementation, after the large model answers based on the system prompts and candidate tool list provided by the agent, the method further includes: If the tool used when answering is of the active invocation type and the tool is not in the tool list corresponding to the dialogue scenario, then the tool is added to the tool list and the preference score of the tool is initialized; If the tool used during the answer is a passively invoked type, the tool invoke data is updated based on the user's feedback in the next round. The preference score of each tool in the tool list is calculated based on the tool invoke data, and tools with preference scores lower than the fourth threshold are removed from the tool list. The preference score of the dialogue scenario is calculated based on the preference scores of all tools. If the preference score of the dialogue scenario is lower than the fifth threshold, the dialogue scenario is deleted.
[0012] According to a second aspect of this application, a large-model-based intelligent agent construction apparatus is provided, the apparatus comprising: The scene selection module is used to obtain the current dialogue information and scene description information of each scene input by the user, and select the matching dialogue scene according to the current dialogue information and the scene description information. The data acquisition module is used to determine the intelligent agent corresponding to the dialogue scenario and obtain tool call data of each tool from the description information of the intelligent agent; The context generation module is used to generate a short-term memory context based on the acquired historical dialogue information, generate a tool context based on the tool call data, generate a file context based on the user-uploaded file, and generate a long-term memory context based on the current dialogue information and the historical dialogue information corresponding to the dialogue scenario. The short-term memory context, the tool context, the file context, and the long-term memory context are combined to form a scenario context. The list generation module is used to generate a candidate tool list based on the current dialogue information or the tool call data, wherein each tool in the candidate tool list is sorted according to the user's preferences; The prompt word generation module is used to generate system prompt words based on the scene context and the candidate tool list; The agent construction module is used to optimize the agent corresponding to the dialogue scenario based on the system prompt words and the candidate tool list to obtain an agent based on user preferences and context awareness.
[0013] According to a third aspect of this application, a computer-readable storage medium is provided, wherein at least one instruction is stored therein, the at least one instruction being loaded and executed by a processor to implement the large model-based agent construction method described above.
[0014] According to a fourth aspect of this application, a computer device is provided, the computer device including the above-described large-model-based intelligent agent construction apparatus.
[0015] The beneficial effects of the technical solution provided in this application include at least the following: By using the current dialogue information and scene description information input by the user, a matching dialogue scene can be selected, and then a scene context can be generated based on the dialogue scene. A candidate tool list is generated based on the user's preferences. Then, system prompt words are generated based on the scene context and the candidate tool list. Finally, the agent is dynamically optimized based on the system prompt words and the candidate tool list to obtain an agent based on user preferences and context awareness. This allows for more accurate identification of the user's intentions and preferences, and responses are made according to the user's intentions and preferences, thus improving the accuracy of the responses.
[0016] If the current dialogue information contains tool description information, then the top n tools with a matching degree greater than the third threshold are selected from the tool list, and these n tools are combined into a candidate tool list for the active invocation type. If the current dialogue information does not contain tool description information, then the top n tools with the best semantic match to the current dialogue information are selected from the tool list, the preference scores of the n tools are calculated, and the n tools are sorted in descending order of preference scores to obtain a candidate tool list for the passive invocation type. In this way, tools that meet user preferences can be adaptively selected, improving the accuracy of tool recommendations.
[0017] By adding tools actively invoked by the user to the tool list corresponding to the dialogue scenario, or by deleting tools with preference scores below the fourth threshold from the tool list, or by deleting dialogue scenarios with preference scores below the fifth threshold, the tool list and dialogue scenarios can be dynamically optimized, thereby updating the agent's preference settings in real time. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a flowchart of a method for constructing an intelligent agent based on a large model, provided in one embodiment of this application; Figure 2 This is a schematic diagram of a dialogue scenario provided in one embodiment of this application; Figure 3 This is a schematic diagram of dialogue scene matching provided in one embodiment of this application; Figure 4 This is a schematic diagram of a knowledge graph for a dialogue scenario provided in one embodiment of this application; Figure 5 This is a schematic diagram illustrating the creation of a new dialogue scenario provided in one embodiment of this application; Figure 6 This is a schematic diagram illustrating the generation of a file context provided in one embodiment of this application; Figure 7 This is a schematic diagram illustrating an update of the tool list provided in one embodiment of this application; Figure 8 This is a schematic diagram of the process of constructing an intelligent agent according to an embodiment of this application; Figure 9 This is a structural block diagram of a large-model-based intelligent agent construction device provided in one embodiment of this application. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0021] like Figure 1 The diagram illustrates a flowchart of a method for constructing an intelligent agent based on a large model, according to an embodiment of this application. This method can be applied to computer devices. The method may include: Step 101: Obtain the current dialogue information and scene description information of each scene input by the user, and select the matching dialogue scene based on the current dialogue information and scene description information.
[0022] In this embodiment, the dialogue can be divided into multiple dialogue scenarios based on the user's dialogue content. The dialogue scenarios mentioned here can cover any topic, such as tourism scenarios, business trip scenarios, family visit scenarios, logistics scenarios, etc.
[0023] Figure 2 Taking two dialogue scenarios as an example, when a user enters the current dialogue information to make a query, the system will classify the scenario based on the current dialogue information. If it is determined that the current dialogue information matches dialogue scenario 1, the tool in dialogue scenario 1 will be called to implement the relevant function; if it is determined that the current dialogue information matches dialogue scenario 2, the tool in dialogue scenario 2 will be called to implement the relevant function.
[0024] When classifying scenarios, scene description information for each dialogue scenario can be obtained, and each scene description information can be semantically matched with the current dialogue information to find the most matching dialogue scenario.
[0025] Specifically, the process involves selecting a matching dialogue scenario based on the scenario description information and the current dialogue information, including: extracting the user's preference description information for the scenario from the current dialogue information; for each dialogue scenario, obtaining the scenario keywords from the scenario description information, and calculating the first similarity score between the current dialogue information, the preference description information, and the scenario keywords; if the first similarity score is greater than a first threshold, then the dialogue scenario is determined as the dialogue scenario that matches the current dialogue information.
[0026] The formula for calculating the first similarity score is: first_sim(query, scenario_i) = α * sim(query, scenario_tag) + (1-α) * sim(query, user_tag). Where first_sim represents the first similarity score; query represents the current dialogue information; scenario_i represents the i-th dialogue scenario; scenario_tag represents scenario description information, which can be scenario keywords such as "tourism," "play," "travel," etc.; user_tag represents preference description information, such as "self-driving," "leisure travel," etc.; and α represents the weight.
[0027] After obtaining the first similarity score, the first similarity score can be compared with the first threshold. If the first similarity score is greater than the first threshold, the match is determined to be successful, and the i-th dialogue scene is determined as the dialogue scene that matches the current dialogue information. If the first similarity score is less than or equal to the first threshold, the first similarity score between the current dialogue information and the next dialogue scene is calculated.
[0028] After obtaining a matching dialogue scenario, the scenario can be pushed to the user. Then, the user's feedback information in the next round of input is obtained. If the feedback information indicates that the dialogue scenario matching fails, similar dialogue scenarios associated with the current dialogue scenario are searched in a preset knowledge graph. The second similarity score between the current dialogue information and the scenario keywords of each similar dialogue scenario is calculated. The first similarity score and each second similarity score are weighted and calculated, and the similar dialogue scenario corresponding to the highest calculation result is determined as the dialogue scenario that matches the current dialogue information.
[0029] like Figure 3 As shown, the user's dialogue information in the first round is "I want to go to Beijing." Based on this dialogue information, the matched dialogue scenario is a tourism scenario, so the user is asked "Do you want to go to Beijing for tourism?". The user's dialogue information in the second round is "I'm going to Beijing for a business trip." At this point, it is determined that the scenario matching has failed, and a second scenario matching is performed.
[0030] During the second scene matching, similar dialogue scenes associated with the first matched dialogue scene can be searched in the knowledge graph. For example... Figure 4 As shown, in the knowledge graph, similar dialogue scenarios associated with the tourism scenario include business trip scenarios, family visit scenarios, and logistics scenarios. The similarity between business trip scenarios and tourism scenarios is 0.7, the similarity between family visit scenarios and tourism scenarios is 0.5, and the similarity between logistics scenarios and tourism scenarios is 0.3. Then, a second similarity score is calculated between the current dialogue information and the scenario keywords of each similar dialogue scenario. The formula for calculating the second similarity score is: second_sim(query, keywords of similar dialogue scenarios). For example, the formula for calculating the second similarity score with the business trip scenario is second_sim(query, business trip), the formula for calculating the second similarity score with the family visit scenario is second_sim(query, family visit), and the formula for calculating the second similarity score with the logistics scenario is second_sim(query, logistics). Finally, the first similarity score and each second similarity score are weighted and calculated, and the similar dialogue scenario corresponding to the highest calculation result is determined as the dialogue scenario matching the current dialogue information.
[0031] Obtain feedback information from the user's re-entry; if the feedback information indicates that the dialogue scenario fails to match again, extract scenario keywords from the current dialogue information, generate a new tool list based on the current dialogue information and tool call data for each dialogue scenario; create a new dialogue scenario based on the scenario keywords and the new tool list, and identify the new dialogue scenario as the one that matches the current dialogue information.
[0032] If the second scene matching fails, a new dialogue scene can be defined for the user. Specifically, a large model can be used to extract scene keywords from the current dialogue information, and these scene keywords can be used to name the new dialogue scene; a new tool list can be extracted from the current dialogue information or tool call data to obtain the new dialogue scene.
[0033] like Figure 5 As shown, "webpage generation" is extracted from the "help me generate a webpage" dialogue and used as the name of the new dialogue scene. The "H5 generation" tools are extracted to form a new tool list, resulting in a new dialogue scene.
[0034] Step 102: Determine the agent corresponding to the dialogue scenario and obtain the tool call data of each tool from the description information of the agent.
[0035] Each dialogue scenario corresponds to an agent, and each agent corresponds to a tool list, which can call upon tools in the tool list to achieve relevant functions. For example, if the dialogue scenario is a travel scenario, its corresponding tool list may include, but is not limited to: flight booking tools, high-speed rail booking tools, hotel booking tools, attraction ticket purchasing tools, and weather query tools.
[0036] After determining the most matching dialogue scenario based on the current dialogue information, the corresponding agent can be found, and tool invocation data can be obtained from the agent's description information. This tool invocation data includes, but is not limited to: historical invocation rate, feedback score, proactive invocation rate, and preference score. The historical invocation rate is the frequency with which the tool is invoked. The feedback score is the rating given by the user after the tool is invoked; a positive feedback score is given if the invoked tool is accurate, and a negative feedback score is given if the invoked tool is incorrect. Tool invocation types include proactive and reactive invocation types. Proactive invocation refers to the user specifying the tool to be invoked in the dialogue information, while reactive invocation refers to tools recommended based on the user's dialogue information. The proactive invocation rate is the frequency with which the tool specified by the user in the dialogue information is invoked, and the preference score is a rating calculated based on the user's preferences.
[0037] Step 103: Generate a short-term memory context based on the acquired historical dialogue information, a tool context based on the tool call data, a file context based on the user-uploaded file, and a long-term memory context based on the current dialogue information and the historical dialogue information corresponding to the dialogue scenario. Combine the short-term memory context, tool context, file context, and long-term memory context to form a scenario context.
[0038] (1) Generate short-term memory context Specifically, historical dialogue information can be obtained, and a large model can be used to extract the most recent m rounds of dialogue information related to the dialogue scenario, where m is a positive integer. Here, m can be set according to actual needs. For example, if m is 20, then the most recent 20 rounds of dialogue information related to the dialogue scenario can be extracted to form a short-term context.
[0039] (2) Generate tool context Specifically, tool call data can be obtained, and tool context can be generated based on historical call rates, preference ratings, and other data in the tool call data.
[0040] (3) Generate file context When a user uploads a file, a large model can be used to determine whether the current dialogue is asking for the entire content of the file or a fragment of the file. If it is asking for the entire content of the file, then all the content of the file is used as the file context; if it is asking for a fragment of the file, then the relevant fragment of the file is used as the file context.
[0041] For example, if the current dialog message asks for a document summary: "Summarize the document content"; or if the current dialog message asks for document location: "What does the third paragraph of this article talk about"; or if the current dialog message asks for document comparison: "Differences between the two documents", then it can be determined that the current dialog message is asking for the overall content of the document.
[0042] All other queries besides the overall content of the above query can be considered as queries about fragments of the file content. Specifically, the current dialogue information can be semantically matched with each fragment in the file, and the j most matching fragments can be extracted as the file context, where j is a positive integer.
[0043] like Figure 6 As shown, a user uploaded a document titled "Company Policy". One dialogue message is "What is an overview of the company's management policy?", and another is "How many days of annual leave does the company offer?". Intent can be identified based on the dialogue messages. If it's determined that the user is asking about the entire document, the entire document is used as the document context. If it's determined that the user is asking about a fragment of the document, Retrieval-augmented Generation (RAG) and Large Language Model (LLM) can be used to filter out j semantically relevant fragments, and these j fragments are used as the document context.
[0044] (4) Generate long-term context Each round of dialogue in the dialogue scenario is timestamped and stored in the following format: (timestamp, scene identifier of the dialogue scenario, original dialogue information, vectorized data block).
[0045] For dialogue messages with different timestamps, if the two dialogue messages are highly similar in meaning, for example, with a matching degree greater than 90%, then the dialogue content of these two dialogue messages can be considered similar, and the dialogue messages with similar content need to be covered in chronological order.
[0046] For example, dialogue information 1: (2025 / 08 / 03: User: What was the industrial output value in the first quarter? Ai: 10 billion yuan), dialogue information 2: (2024 / 05 / 05: User: What was the industrial output value in the first quarter? Ai: 15 billion yuan), dialogue information 3: (2022 / 07 / 14: User: What was the industrial output value in the first quarter? Ai: 15 billion yuan). Dialogue information 1, dialogue information 2, and dialogue information 3 have similar dialogue content but different timestamps. The latest dialogue information 1 can be stored in the latest memory vector library, and all similar old dialogue information 2 and dialogue information 3 can be stored in the historical memory vector library. Then, the latest memory and historical memory can be connected by a linked list (dialogue information 1 -> dialogue information 2 -> dialogue information 3), sorted by time, for easy subsequent tracing.
[0047] Specifically, generating a long-term memory context based on the current dialogue information and the historical dialogue information corresponding to the dialogue scenario can include: searching for similar dialogue scenarios associated with the current dialogue scenario in a pre-defined knowledge graph; for each similar dialogue scenario, searching for the k most recent historical data entries from the latest memory vector library corresponding to the similar dialogue scenario, where the historical data includes the scenario identifier of the similar dialogue scenario, the timestamp of one round of dialogue and dialogue information, and vectorized data blocks, where k is a positive integer; for each dialogue scenario, if the current dialogue information does not contain time information, then searching for the k most recent historical data entries from the latest memory vector library corresponding to the dialogue scenario; if the current dialogue information contains time information, then using the time information as an index, searching for the k most recent historical data entries from the historical memory vector library corresponding to the dialogue scenario, where a set of historical data entries in the historical memory vector library has similar dialogue content to a single historical data entry in the latest memory vector library, and the historical data entries are linked in a linked list according to the chronological order of their timestamps; removing historical data entries whose time interval with the current time is greater than a second threshold; and forming the remaining historical data into a long-term memory context.
[0048] For each similar dialogue scenario, the k most recent historical data can be filtered from the latest memory vector library.
[0049] For a dialogue scenario that matches the current dialogue information, time information can be obtained from the current dialogue information. If the current dialogue information does not contain time information, the k most recent historical data entries are directly selected from the latest memory vector library. If the current dialogue information contains time information, the k most recent historical data entries related to the current dialogue information are selected from the historical archive memory library based on the closest match on the timeline. For example, the current dialogue information is "How does this year's industrial output compare to 2022?", and the time information is 2022.
[0050] It should be noted that if the time interval between the current time and the matched historical data exceeds the second threshold, it indicates that the historical data is too far removed from the current data and has no reference value; therefore, this historical data needs to be discarded. The remaining historical data can be compiled into a summary and used as long-term context.
[0051] Step 104: Generate a candidate tool list based on the current dialogue information or tool call data. The tools in the candidate tool list are sorted according to the user's preferences.
[0052] (1) The current dialogue information contains tool description information. If the current dialogue information contains tool description information, then select the top n tools from the tool list whose matching degree with the tool description information is greater than the third threshold, and form a candidate tool list of the active invocation type from the n tools, where n is a positive integer.
[0053] If the tool description in the current dialogue is highly similar to the description of a candidate tool (e.g., similarity greater than a threshold of 90%), then the tool invocation type can be considered an active invocation type. In this case, the user's intention is to actively and directly invoke the tool, and no tool preference recommendation is needed. Specifically, the top n tools can be selected directly from the list of tools whose matching degree with the tool description is greater than the third threshold, and sorted in descending order of matching degree to obtain the candidate tool list.
[0054] For example, if the current dialogue message is "I prefer high-speed rail travel," then the "high-speed rail booking tool" can be used as a tool that is actively invoked.
[0055] (2) The current dialogue information does not contain tool description information. If the current dialogue information does not contain tool description information, then select the top n tools that best match the semantics of the current dialogue information from the tool list. Obtain the historical call rate, feedback score, and active call rate of the n tools from the tool call information. Calculate the preference score of the n tools based on the historical call rate, feedback score, and active call rate. Sort the n tools in descending order of preference score to obtain a candidate tool list for passive call type.
[0056] If the tool description information in the current dialogue is dissimilar to the description information of the candidate tools (e.g., the similarity is less than 90%), then the tool invocation type can be considered to be passive invocation. In this case, based on semantic matching, the top n most matching tools can be selected from the list of tools matching the dialogue scenario. A preference score can be calculated for each tool, and the tools can be sorted in descending order of preference scores to obtain the candidate tool list.
[0057] The formula for calculating the tool's preference score is: tool_prefer_score = history_user_rate * β + feedback_back_score * γ + user_call_rate * (1 - β - γ). Where tool_prefer_score represents the tool's preference score, history_user_rate represents the historical call rate, feedback_back_score represents the feedback score, user_call_rate represents the proactive call rate, and β and γ represent the weights.
[0058] Optionally, if a tool has been called before, its default parameter values can be set to the default parameter values from the last call.
[0059] Step 105: Generate system prompts based on the scene context and the candidate tool list.
[0060] For example, the system prompt might read, "You are an intelligent agent that solves user problems through repeated tool calls. User preferences for tools are: high-speed rail, leisure, ... The user's priority order for tool calls is tool 1, tool 2, ...", where the priority order can be based on preference ratings.
[0061] Step 106: Optimize the agent corresponding to the dialogue scenario based on the system prompts and the candidate tool list to obtain an agent based on user preferences and context awareness.
[0062] like Figure 7 As shown, the agent can provide the system prompts and a list of candidate tools to the large model, so that the large model can call the tools in the list of candidate tools based on the system prompts and push the generated answer to the user.
[0063] In this embodiment, the tool list and dialogue scenarios can also be dynamically adjusted.
[0064] (1) If the tool called when answering is of the active call type and the tool is not in the tool list corresponding to the dialogue scenario, then add the tool to the tool list and initialize the tool's preference score.
[0065] like Figure 8 As shown, if a user specifies a weather query tool in the current dialogue information, the weather query tool can be added to the tool list of the dialogue scene, and the initial preference score can be 50 points.
[0066] (2) If the tool called during the answer is a passive call type, update the tool call data according to the user's feedback information in the next round, calculate the preference score of each tool in the tool list according to the tool call data, and delete the tool whose preference score is lower than the fourth threshold from the tool list.
[0067] Specifically, the tool call data can be updated based on feedback information. For example, the historical call rate, feedback score, active call rate, and default parameter assignment (initialized preference score) of the "weather query tool" can be updated. Then, the preference score of the tool can be recalculated according to the preference score calculation formula mentioned above. The preference score of each tool can be compared with the fourth threshold. If there is a preference score lower than the fourth threshold, the tool corresponding to that preference score can be deleted.
[0068] (3) Calculate the preference score of the dialogue scene based on the preference scores of all tools. If the preference score of the dialogue scene is lower than the fifth threshold, then delete the dialogue scene.
[0069] The formula for calculating preference scores in dialogue scenarios is: Where scenario_prefer_score represents the preference score for the dialogue scenario, tool_prefer_score represents the preference score for the tool, and u represents the total number of tools in the tool list.
[0070] Specifically, the preference score for each dialogue scenario can be compared with the fifth threshold. If a preference score is found to be lower than the fifth threshold, the dialogue scenario corresponding to that preference score will be deleted.
[0071] In summary, the large-model-based agent construction method provided in this application can select a matching dialogue scenario based on the current dialogue information and scenario description information input by the user, and then generate a scenario context based on the dialogue scenario; generate a candidate tool list based on the user's preferences; then generate system prompt words based on the scenario context and the candidate tool list; finally, dynamically optimize the agent based on the system prompt words and the candidate tool list to obtain an agent based on user preferences and context awareness, thereby more accurately identifying the user's intentions and preferences, and answering questions based on the user's intentions and preferences, thus improving the accuracy of the answers.
[0072] If the current dialogue information contains tool description information, then the top n tools with a matching degree greater than the third threshold are selected from the tool list, and these n tools are combined into a candidate tool list for the active invocation type. If the current dialogue information does not contain tool description information, then the top n tools with the best semantic match to the current dialogue information are selected from the tool list, the preference scores of the n tools are calculated, and the n tools are sorted in descending order of preference scores to obtain a candidate tool list for the passive invocation type. In this way, tools that meet user preferences can be adaptively selected, improving the accuracy of tool recommendations.
[0073] By adding tools actively invoked by the user to the tool list corresponding to the dialogue scenario, or by deleting tools with preference scores below the fourth threshold from the tool list, or by deleting dialogue scenarios with preference scores below the fifth threshold, the tool list and dialogue scenarios can be dynamically optimized, thereby updating the agent's preference settings in real time.
[0074] like Figure 9 The diagram illustrates a structural block diagram of a large-model-based intelligent agent construction device according to an embodiment of this application. This large-model-based intelligent agent construction device can be applied to a computer device. The device includes: The scene selection module 910 is used to obtain the current dialogue information and scene description information of each scene input by the user, and select the matching dialogue scene according to the current dialogue information and scene description information. The data acquisition module 920 is used to determine the intelligent agent corresponding to the dialogue scenario and obtain tool call data of each tool from the description information of the intelligent agent; The context generation module 930 is used to generate a short-term memory context based on the acquired historical dialogue information, a tool context based on the tool call data, a file context based on the user-uploaded file, and a long-term memory context based on the current dialogue information and the historical dialogue information corresponding to the dialogue scenario. The short-term memory context, tool context, file context and long-term memory context are combined to form a scenario context. The list generation module 940 is used to generate a list of candidate tools based on the current dialogue information or tool call data. The tools in the candidate tool list are sorted according to the user's preferences. The prompt word generation module 950 is used to generate system prompt words based on the scene context and the candidate tool list; The agent building module 960 is used to optimize the agent corresponding to the dialogue scenario based on the system prompt words and the candidate tool list, so as to obtain an agent based on user preferences and context awareness.
[0075] In an optional embodiment, the scene selection module 910 is further configured to: Extract user preference descriptions for the scenario from the current dialogue information; For each dialogue scenario, obtain the scenario keywords from the scenario description information, and calculate the first similarity score between the current dialogue information, preference description information and scenario keywords; If the first similarity score is greater than the first threshold, then the dialogue scenario is determined to be the dialogue scenario that matches the current dialogue information.
[0076] In an optional embodiment, the scene selection module 910 is further configured to: Obtain feedback information from the user's input in the next round; If the feedback information determines that the dialogue scenario matching failed, then search for similar dialogue scenarios associated with the dialogue scenario in the preset knowledge graph. Calculate the second similarity score between the current dialogue information and the scene keywords of each similar dialogue scene; The first similarity score is weighted and calculated with each second similarity score. The dialogue scene corresponding to the largest similarity score is determined as the dialogue scene that matches the current dialogue information.
[0077] In an optional embodiment, the scene selection module 910 is further configured to: Get feedback information when the user re-enters; If the feedback information determines that the dialogue scenario fails to match again, then extract the scenario keywords from the current dialogue information and generate a new tool list based on the current dialogue information and the tool call data of each dialogue scenario. Create new dialogue scenarios based on scenario keywords and a list of new tools, and identify the new dialogue scenarios as those that match the current dialogue information.
[0078] In an optional embodiment, the context generation module 930 is further configured to: Search for similar dialogue scenarios related to the dialogue scenario in the pre-defined knowledge graph; For each similar dialogue scenario, search for the k most recent historical data from the latest memory vector library corresponding to the similar dialogue scenario. The historical data includes the scenario identifier of the similar dialogue scenario, the timestamp of one round of dialogue and dialogue information, and vectorized data blocks, where k is a positive integer. For dialogue scenarios, if the current dialogue information does not contain time information, then the k most recent historical data are searched from the latest memory vector library corresponding to the dialogue scenario; if the current dialogue information contains time information, then the k most recent historical data are searched from the historical memory vector library corresponding to the dialogue scenario, using the time information as an index. A set of historical data in the historical memory vector library has similar dialogue content to a historical data in the latest memory vector library, and they are linked in a linked list according to the order of the timestamps of each historical data. Remove historical data whose time interval from the current time is greater than the second threshold; The remaining historical data is used to form a long-term memory context.
[0079] In an optional embodiment, the list generation module 940 is used for: If the current dialogue information contains tool description information, then select the top n tools from the tool list whose matching degree with the tool description information is greater than the third threshold, and form a candidate tool list of the active invocation type from the n tools, where n is a positive integer; If the current dialogue information does not contain tool description information, then select the top n tools that best match the semantics of the current dialogue information from the tool list. Obtain the historical call rate, feedback score, and active call rate of the n tools from the tool call information. Calculate the preference score of the n tools based on the historical call rate, feedback score, and active call rate. Sort the n tools in descending order of preference score to obtain a candidate tool list for passive call type.
[0080] In an optional embodiment, after the large model responds based on the system prompts and candidate tool list provided by the agent, the device further includes an update module for: If the tool used when answering is an actively invoked type and the tool is not in the tool list corresponding to the dialogue scenario, then add the tool to the tool list and initialize the tool's preference score; If the tool used during the answer is a passively invoked type, the tool invoke data is updated based on the user's feedback in the next round. The preference score of each tool in the tool list is calculated based on the tool invoke data, and tools with preference scores below the fourth threshold are removed from the tool list. The preference score for the dialogue scenario is calculated based on the preference scores of all tools. If the preference score of the dialogue scenario is lower than the fifth threshold, the dialogue scenario is deleted.
[0081] In summary, the large-model-based agent construction device provided in this application can select a matching dialogue scenario based on the current dialogue information and scenario description information input by the user, and then generate a scenario context based on the dialogue scenario; generate a candidate tool list based on the user's preferences; then generate system prompt words based on the scenario context and the candidate tool list; finally, dynamically optimize the agent based on the system prompt words and the candidate tool list to obtain an agent based on user preferences and context awareness, thereby more accurately identifying the user's intentions and preferences, and answering questions based on the user's intentions and preferences, thus improving the accuracy of the answers.
[0082] If the current dialogue information contains tool description information, then the top n tools with a matching degree greater than the third threshold are selected from the tool list, and these n tools are combined into a candidate tool list for the active invocation type. If the current dialogue information does not contain tool description information, then the top n tools with the best semantic match to the current dialogue information are selected from the tool list, the preference scores of the n tools are calculated, and the n tools are sorted in descending order of preference scores to obtain a candidate tool list for the passive invocation type. In this way, tools that meet user preferences can be adaptively selected, improving the accuracy of tool recommendations.
[0083] By adding tools actively invoked by the user to the tool list corresponding to the dialogue scenario, or by deleting tools with preference scores below the fourth threshold from the tool list, or by deleting dialogue scenarios with preference scores below the fifth threshold, the tool list and dialogue scenarios can be dynamically optimized, thereby updating the agent's preference settings in real time.
[0084] One embodiment of this application provides a computer-readable storage medium storing at least one instruction, which is loaded and executed by a processor to implement the large model-based agent construction method described above.
[0085] One embodiment of this application provides a computer device, which includes any of the above-described intelligent agent construction devices based on large models.
[0086] It should be noted that the above embodiments of the large-model-based agent construction device are only illustrated by the division of the functional modules described above when constructing large-model-based agents. In practical applications, the functions described above can be assigned to different functional modules as needed, that is, the internal structure of the large-model-based agent construction device can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the large-model-based agent construction device and the large-model-based agent construction method embodiments provided above belong to the same concept, and their specific implementation process is detailed in the method embodiments, which will not be repeated here.
[0087] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0088] The above description is not intended to limit the embodiments of this application. Any adjustments, equivalent substitutions, improvements, etc., made within the spirit and principles of the embodiments of this application should be included within the protection scope of the embodiments of this application.
Claims
1. A method for constructing intelligent agents based on large models, characterized in that, The method includes: Obtain the current dialogue information and scene description information of each scene input by the user, and select the matching dialogue scene based on the current dialogue information and the scene description information; Identify the intelligent agent corresponding to the dialogue scenario, and obtain tool call data for each tool from the description information of the intelligent agent; A short-term memory context is generated based on the acquired historical dialogue information, a tool context is generated based on the tool call data, a file context is generated based on the user-uploaded file, and a long-term memory context is generated based on the current dialogue information and the historical dialogue information corresponding to the dialogue scenario. The short-term memory context, the tool context, the file context, and the long-term memory context are combined to form a scenario context. A candidate tool list is generated based on the current dialogue information or the tool call data, and the tools in the candidate tool list are sorted according to the user's preferences; Generate system prompts based on the scene context and the candidate tool list; The agent corresponding to the dialogue scenario is optimized based on the system prompts and the candidate tool list to obtain an agent based on user preferences and context awareness.
2. The method for constructing an intelligent agent based on a large model according to claim 1, characterized in that, The step of selecting a matching dialogue scenario based on the scenario description information and the current dialogue information includes: Extract user preference descriptions for the scenario from the current dialogue information; For each dialogue scenario, obtain the scenario keywords from the scenario description information, and calculate the first similarity score between the current dialogue information, the preference description information and the scenario keywords; If the first similarity score is greater than the first threshold, then the dialogue scenario is determined to be a dialogue scenario that matches the current dialogue information.
3. The method for constructing an intelligent agent based on a large model according to claim 2, characterized in that, The method further includes: Obtain the user's feedback information in the next round of input; If it is determined from the feedback information that the dialogue scenario matching fails, then a similar dialogue scenario associated with the dialogue scenario is searched in the preset knowledge graph; Calculate the second similarity score between the current dialogue information and the scene keywords of each similar dialogue scene; The first similarity score is weighted and calculated with each second similarity score, and the similar dialogue scene corresponding to the maximum calculation result is determined as the dialogue scene that matches the current dialogue information.
4. The method for constructing an intelligent agent based on a large model according to claim 3, characterized in that, The method further includes: Get feedback information when the user re-enters; If the feedback information determines that the dialogue scenario fails to match again, then the scenario keywords are extracted from the current dialogue information, and a new tool list is generated based on the current dialogue information and the tool call data of each dialogue scenario. A new dialogue scenario is created based on the scenario keywords and the new tool list, and the new dialogue scenario is determined as the dialogue scenario that matches the current dialogue information.
5. The method for constructing an intelligent agent based on a large model according to claim 1, characterized in that, The step of generating a long-term memory context based on the current dialogue information and the historical dialogue information corresponding to the dialogue scenario includes: Search for similar dialogue scenarios associated with the given dialogue scenario in a pre-defined knowledge graph; For each similar dialogue scenario, the most recent k historical data are searched from the latest memory vector library corresponding to the similar dialogue scenario. The historical data includes the scenario identifier of the similar dialogue scenario, the timestamp of a round of dialogue and dialogue information, and vectorized data blocks, where k is a positive integer. For the dialogue scenario, if the current dialogue information does not contain time information, then the k most recent historical data entries are searched from the latest memory vector library corresponding to the dialogue scenario; if the current dialogue information contains time information, then the k most recent historical data entries are searched from the historical memory vector library corresponding to the dialogue scenario using the time information as an index. A group of historical data entries in the historical memory vector library has similar dialogue content to a historical data entry in the latest memory vector library, and they are linked in a linked list according to the chronological order of the timestamps of each historical data entry. Remove historical data whose time interval from the current time is greater than the second threshold; The remaining historical data is used to form a long-term memory context.
6. The method for constructing an intelligent agent based on a large model according to claim 1, characterized in that, The step of generating a candidate tool list based on the current dialogue information or the tool call data includes: If the current dialogue information contains tool description information, then the top n tools with a matching degree greater than the third threshold are selected from the tool list, and the n tools are combined into a candidate tool list of the active invocation type, where n is a positive integer; If the current dialogue information does not contain tool description information, then the top n tools that best match the semantics of the current dialogue information are selected from the tool list. The historical call rate, feedback score, and active call rate of the n tools are obtained from the tool call information. The preference score of the n tools is calculated based on the historical call rate, the feedback score, and the active call rate. The n tools are sorted in descending order of preference score to obtain a candidate tool list for passive call type.
7. The method for constructing an intelligent agent based on a large model according to claim 6, characterized in that, After the large model responds based on the system prompts and candidate tool list provided by the agent, the method further includes: If the tool used when answering is of the active invocation type and the tool is not in the tool list corresponding to the dialogue scenario, then the tool is added to the tool list and the preference score of the tool is initialized; If the tool used during the answer is a passively invoked type, the tool invoke data is updated based on the user's feedback in the next round. The preference score of each tool in the tool list is calculated based on the tool invoke data, and tools with preference scores lower than the fourth threshold are removed from the tool list. The preference score of the dialogue scenario is calculated based on the preference scores of all tools. If the preference score of the dialogue scenario is lower than the fifth threshold, the dialogue scenario is deleted.
8. A device for constructing intelligent agents based on a large model, characterized in that, The device includes: The scene selection module is used to obtain the current dialogue information and scene description information of each scene input by the user, and select the matching dialogue scene according to the current dialogue information and the scene description information. The data acquisition module is used to determine the intelligent agent corresponding to the dialogue scenario and obtain tool call data of each tool from the description information of the intelligent agent; The context generation module is used to generate a short-term memory context based on the acquired historical dialogue information, generate a tool context based on the tool call data, generate a file context based on the user-uploaded file, and generate a long-term memory context based on the current dialogue information and the historical dialogue information corresponding to the dialogue scenario. The short-term memory context, the tool context, the file context, and the long-term memory context are combined to form a scenario context. The list generation module is used to generate a candidate tool list based on the current dialogue information or the tool call data, wherein each tool in the candidate tool list is sorted according to the user's preferences; The prompt word generation module is used to generate system prompt words based on the scene context and the candidate tool list; The agent construction module is used to optimize the agent corresponding to the dialogue scenario based on the system prompt words and the candidate tool list to obtain an agent based on user preferences and context awareness.
9. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction, which is loaded and executed by a processor to implement the large model-based agent construction method as described in any one of claims 1 to 7.
10. A computer device, characterized in that, The computer device includes: the intelligent agent construction apparatus based on a large model as described in claim 8.
Citation Information
Patent Citations
Visual language navigation method based on historical context information enhancement
CN118010026A
Intelligent agent architecture based on multi-modal large model
CN120046645A
Multi-modal intelligent dialogue method and system based on AI language model
CN120744063A
Question answering processing method and system, device and storage medium
WO2025146589A1
Cited By
Tool calling method and system, electronic equipment, storage medium and program product
CN121412003A
Intelligent agent interaction method and device, equipment, medium and product
CN121809534A