Agent construction method and device based on large model, storage medium and equipment
By employing a large-model-based agent construction method, this approach utilizes dialogue information and scene descriptions to select dialogue scenarios, generate multi-level contexts, and optimize the tool list. This addresses the problem of agents being unable to integrate user intent and preferences, thereby improving the accuracy of responses and tool recommendations.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- TIANJUDIHE (SUZHOU) TECH CO LTD
- Filing Date
- 2025-10-11
- Publication Date
- 2026-04-10
AI Technical Summary
Existing intelligent agents cannot effectively integrate user intent and behavioral preferences during the construction process, resulting in low tool hit rates, and the tool list and system prompts cannot be dynamically updated, failing to reflect personalized user preferences.
By acquiring the current dialogue information and scene description information input by the user, the system selects the matching dialogue scene, generates short-term, tool, file, and long-term memory contexts, generates system prompt words based on the scene context and candidate tool list, and optimizes the agent to reflect user preferences.
It improves the accuracy of the agent's responses and tool recommendations, and enables dynamic updates and personalized preference representation of the agent.
Smart Images

Figure CN120952041B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, in particular to an agent construction method and device based on a large model, a storage medium and equipment. BACKGROUND
[0002] An agent (AI Agent or AI Bot) refers to an entity capable of perceiving its environment and taking actions to achieve a certain goal, which can be a software program, a robot or other forms of systems. Agents are gradually becoming the main way for people to interact with large models (such as large language models).
[0003] An agent needs to generate a system prompt word according to the chat information input by a user, and then send the system prompt word and candidate tools to a large model, so as to hit the tools required by the user by using the tool calling capability of the large model, and thus call the tools to give the answers required by the user. In related technologies, when constructing an agent, a fixed tool list is usually bound in advance, the chat records of the last few rounds are obtained as a context, the fixed system prompt word is generated according to the context, and the agent is constructed according to the tool list and the system prompt word.
[0004] However, the context depends on short-term memory and has weak perception of long-term memory information, cannot accurately capture information related to the user's intention, and cannot effectively integrate the user's intention and behavior preferences; the agent is single-scene, the tool list is not classified according to the scene, resulting in low hit rate of the tools; and the tool list and the system prompt word of the agent cannot be dynamically updated, and cannot reflect the user's personalized preferences. SUMMARY
[0005] The present application provides an agent construction method and device based on a large model, a storage medium and equipment, which are used to solve the problems that an agent cannot integrate the user's intention and behavior preferences, the tool hit rate is low, the tool list and the system prompt word cannot be dynamically updated, and the user's personalized preferences cannot be reflected. The technical solution is as follows:
[0006] According to a first aspect of the present application, an agent construction method based on a large model is provided, and the method comprises:
[0007] Obtaining current conversation information input by a user and scene description information of each scene, and selecting a matched conversation scene according to the current conversation information and the scene description information;
[0008] Determining an agent corresponding to the conversation scene, and obtaining tool calling data of each tool from description information of the agent;
[0009] generate a short-term memory context according to the obtained historical dialogue information, generate a tool context according to the tool invocation data, generate a file context according to the file uploaded by the user, generate a long-term memory context according to the current dialogue information and historical dialogue information corresponding to the dialogue scenario, and combine the short-term memory context, the tool context, the file context and the long-term memory context to form a scenario context;
[0010] generate a candidate tool list according to the current dialogue information or the tool invocation data, and each tool in the candidate tool list is sorted according to the user's preference;
[0011] generate a system prompt word according to the scenario context and the candidate tool list;
[0012] optimize an agent corresponding to the dialogue scenario according to the system prompt word and the candidate tool list, and obtain an agent based on user preference and context awareness.
[0013] In a possible implementation, the selecting a matched dialogue scenario according to the scenario description information and the current dialogue information comprises:
[0014] extracting preference description information of the user on the scenario from the current dialogue information;
[0015] for each dialogue scenario, obtaining a scenario keyword in the scenario description information, and calculating a first similarity score between the current dialogue information, the preference description information and the scenario keyword;
[0016] if the first similarity score is greater than a first threshold, determining the dialogue scenario as a dialogue scenario matched with the current dialogue information.
[0017] In a possible implementation, the method further comprises:
[0018] obtaining feedback information of the user in the next round of input;
[0019] if it is determined that the dialogue scenario fails to match according to the feedback information, searching for a similar dialogue scenario associated with the dialogue scenario in a preset knowledge graph;
[0020] calculating a second similarity score between the current dialogue information and a scenario keyword of each similar dialogue scenario respectively;
[0021] performing weighted calculation on the first similarity score and each second similarity score, and determining a similar dialogue scenario corresponding to a maximum calculation result as a dialogue scenario matched with the current dialogue information.
[0022] In a possible implementation, the method further includes:
[0023] obtaining feedback information input by the user again;
[0024] if it is determined according to the feedback information that the dialogue scene matching fails again, extracting a scene keyword from the current dialogue information, and generating a new tool list according to the current dialogue information and tool invocation data of each dialogue scene;
[0025] creating a new dialogue scene according to the scene keyword and the new tool list, and determining the new dialogue scene as a dialogue scene matched with the current dialogue information.
[0026] In a possible implementation, the generating a long-term memory context according to the current dialogue information and historical dialogue information corresponding to the dialogue scene includes:
[0027] finding similar dialogue scenes associated with the dialogue scene in a preset knowledge graph;
[0028] for each similar dialogue scene, finding the latest k pieces of historical data from a latest memory vector library corresponding to the similar dialogue scene, the historical data including a scene identifier of the similar dialogue scene, a timestamp and dialogue information of a round of dialogue, vectorized data blocks, and k being a positive integer;
[0029] for the dialogue scene, if the current dialogue information does not include time information, finding the latest k pieces of historical data from a latest memory vector library corresponding to the dialogue scene; if the current dialogue information includes time information, taking the time information as an index to find the latest k pieces of historical data from a historical memory vector library corresponding to the dialogue scene, a group of historical data in the historical memory vector library being similar to dialogue content of a piece of historical data in the latest memory vector library, and the group of historical data being linked in a linked list according to time stamps of the historical data in chronological order;
[0030] eliminating historical data with a time interval from a current time greater than a second threshold value;
[0031] composing the remaining historical data into a long-term memory context.
[0032] In a possible implementation, the generating a candidate tool list according to the current dialogue information or the tool invocation data includes:
[0033] if the current dialogue information includes tool description information, screening the first n tools from a tool list with a matching degree greater than a third threshold value from the tool description information, composing the n tools into a candidate tool list of an active invocation type, and n being a positive integer;
[0034] If the tool description information is not included in the current dialogue information, the first n tools that are most matched with semantics of the current dialogue information are filtered from a tool list, historical calling rates, feedback scores and active calling rates of the n tools are obtained from the tool calling information, preference scores of the n tools are calculated according to the historical calling rates, the feedback scores and the active calling rates, the n tools are sorted in descending order of the preference scores, and a candidate tool list of the passive calling type is obtained.
[0035] In a possible implementation, after the large model answers according to the system prompt word provided by the agent and the candidate tool list, the method further includes:
[0036] If the tool called when answering belongs to the active calling type and the tool is not in the tool list corresponding to the dialogue scene, the tool is added to the tool list, and a preference score of the tool is initialized;
[0037] If the tool called when answering belongs to the passive calling type, the tool calling data is updated according to feedback information input by the user in the next round, the preference scores of the tools in the tool list are calculated according to the tool calling data, and tools with preference scores lower than a fourth threshold value are deleted from the tool list;
[0038] The preference score of the dialogue scene is calculated according to the preference scores of all the tools, and if the preference score of the dialogue scene is lower than a fifth threshold value, the dialogue scene is deleted.
[0039] According to a second aspect of the present application, a large model-based agent construction device is provided, and the device includes:
[0040] A scene selection module is configured to obtain current dialogue information input by a user and scene description information of each scene, and select a matched dialogue scene according to the current dialogue information and the scene description information.
[0041] A data acquisition module is configured to determine an agent corresponding to the dialogue scene, and acquire tool calling data of each tool from description information of the agent.
[0042] A context generation module is configured to generate a short-term memory context according to acquired historical dialogue information, generate a tool context according to the tool calling data, generate a file context according to a file uploaded by the user, generate a long-term memory context according to the current dialogue information and historical dialogue information corresponding to the dialogue scene, and combine the short-term memory context, the tool context, the file context and the long-term memory context to form a scene context.
[0043] a list generation module configured to generate a candidate tool list according to the current dialogue information or the tool invocation data, and each tool in the candidate tool list is sorted according to user preferences;
[0044] a prompt word generation module configured to generate a system prompt word according to the scene context and the candidate tool list;
[0045] an agent construction module configured to optimize an agent corresponding to the dialogue scene according to the system prompt word and the candidate tool list, to obtain an agent based on user preferences and context awareness.
[0046] According to a third aspect of the present application, a computer-readable storage medium is provided, the storage medium stores at least one instruction, the at least one instruction is loaded and executed by a processor to implement the large model-based agent construction method as described above.
[0047] According to a fourth aspect of the present application, a computer device is provided, the computer device comprises the large model-based agent construction device described above.
[0048] The technical scheme provided by the present application has at least the following beneficial effects:
[0049] By inputting the current dialogue information and the scene description information, a matching dialogue scene can be selected, and then the scene context is generated based on the dialogue scene. The candidate tool list is generated based on the user's preferences. Then, the system prompt word is generated according to the scene context and the candidate tool list. Finally, the agent is dynamically optimized according to the system prompt word and the candidate tool list, and the agent based on the user's preferences and context awareness is obtained. Therefore, the user's intention and preferences can be more accurately identified, and the answer can be given according to the user's intention and preferences, thereby improving the accuracy of the answer.
[0050] If the current dialogue information contains tool description information, the first n tools with a matching degree greater than a third threshold value with the tool description information are selected from the tool list, and the n tools are grouped into a candidate tool list of the active invocation type. If the current dialogue information does not contain tool description information, the first n tools with the most matching semantics with 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 the preference scores, to obtain a candidate tool list of the passive invocation type. In this way, the tools that meet the user's preferences can be adaptively selected, and the accuracy of tool recommendation is improved.
[0051] By adding the tool actively invoked by the user to the tool list corresponding to the dialogue scene, or by deleting the tools with a preference score lower than the fourth threshold from the tool list, or by deleting the dialogue scenes with a preference score lower than the fifth threshold, the tool list and the dialogue scene can be dynamically optimized, so that the preference settings of the agent are updated in real time. BRIEF DESCRIPTION OF DRAWINGS
[0052] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0053] Figure 1 is a flowchart of the method for constructing an agent based on a large model provided by an embodiment of the present application;
[0054] Figure 2 is a schematic diagram of a dialogue scene provided by an embodiment of the present application;
[0055] Figure 3 is a schematic diagram of dialogue scene matching provided by an embodiment of the present application;
[0056] Figure 4 is a schematic diagram of a knowledge graph of a dialogue scene provided by an embodiment of the present application;
[0057] Figure 5 is a schematic diagram of creating a new dialogue scene provided by an embodiment of the present application;
[0058] Figure 6 is a schematic diagram of generating a file context provided by an embodiment of the present application;
[0059] Figure 7 is a schematic diagram of updating a tool list provided by an embodiment of the present application;
[0060] Figure 8 is a flowchart of constructing an agent provided by an embodiment of the present application;
[0061] Figure 9 is a structural block diagram of an agent construction device based on a large model provided by an embodiment of the present application. DETAILED DESCRIPTION
[0062] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the drawings.
[0063] As Figure 1As shown, it shows a method flowchart of the large model-based agent construction method provided by one embodiment of the present application, which can be applied to a computer device. The large model-based agent construction method can include:
[0064] In step 101, the current dialogue information input by the user and the scene description information of each scene are obtained, and a matched dialogue scene is selected according to the current dialogue information and the scene description information.
[0065] In this embodiment, the dialogue can be divided into multiple dialogue scenes according to the dialogue content of the user. The dialogue scene mentioned here can cover any topic, such as a travel scene, a business trip scene, a visit scene, a logistics scene, etc.
[0066] Figure 2 Taking two dialogue scenes as an example, when the user inputs the current dialogue information for query, the current dialogue information is classified according to the current dialogue information, if it is determined that the current dialogue information matches the dialogue scene 1, the tools in the dialogue scene 1 are called to realize the related functions; if it is determined that the current dialogue information matches the dialogue scene 2, the tools in the dialogue scene 2 are called to realize the related functions.
[0067] When classifying the scene, the scene description information of each dialogue scene can be obtained, and each scene description information is matched with the current dialogue information to find the most matched dialogue scene.
[0068] Specifically, selecting a matched dialogue scene according to the scene description information and the current dialogue information includes: extracting user preference description information for the scene from the current dialogue information; for each dialogue scene, obtaining a scene keyword in the scene description information, calculating a first similarity score between the current dialogue information, the preference description information and the scene keyword; if the first similarity score is greater than a first threshold, the dialogue scene is determined as the dialogue scene matched with the current dialogue information.
[0069] The calculation formula of the first similarity score is: first_sim(query, scenario_i)=a*sim(query, scenario_tag)+(1-a)*sim(query, user_tag). Wherein, first_sim represents the first similarity score; query represents the current dialogue information; scenario_i represents the i th dialogue scene; scenario_tag represents the scene description information, which can be a scene keyword, such as "tourism", "play", "travel", etc.; user_tag represents the preference description information, such as "self-driving", "leisure tour", etc.; a represents the weight.
[0070] After obtaining the first similarity score, the first similarity score can be compared with a first threshold value. If the first similarity score is greater than the first threshold value, it is determined that the matching is successful, and the i-th dialogue scene is determined as the dialogue scene matched with the current dialogue information. If the first similarity score is less than or equal to the first threshold value, the first similarity score of the current dialogue information and the next dialogue scene is continued to be calculated.
[0071] After obtaining the matched dialogue scene, the dialogue scene can be pushed to the user. Then, feedback information input by the user in the next round is obtained. If it is determined according to the feedback information that the dialogue scene matching fails, a similar dialogue scene associated with the dialogue scene is searched for in the preset knowledge graph. A second similarity score between the current dialogue information and the scene keywords of each similar dialogue scene is calculated respectively. The first similarity score and each second similarity score are weighted and calculated, and the similar dialogue scene corresponding to the maximum calculation result is determined as the dialogue scene matched with the current dialogue information.
[0072] As shown in FIG. 1, Figure 3 the dialogue information input by the user in the first round is “I want to go to Beijing.” According to the dialogue information, the matched dialogue scene is a tourism scene, and the user is asked “Do you want to go to Beijing for tourism?” The dialogue information input by the user in the second round is “I go to Beijing for business.” At this time, it is determined that the scene matching fails, and the second scene matching is performed.
[0073] In the second scene matching, a similar dialogue scene associated with the dialogue scene matched in the first time can be searched for in the knowledge graph. As shown in FIG. 2, Figure 4 the similar dialogue scenes associated with the tourism scene in the knowledge graph include a business trip scene, a visit scene and a logistics scene, and the similarity between the business trip scene and the tourism scene is 0.7, the similarity between the visit scene and the tourism scene is 0.5, and the similarity between the logistics scene and the tourism scene is 0.3. Then, a second similarity score between the current dialogue information and the scene keywords of each similar dialogue scene is calculated respectively. The calculation formula of the second similarity score is: second_sim (query, keywords of the similar dialogue scene). For example, the calculation formula of the second similarity score of the business trip scene is second_sim (query, business trip), the calculation formula of the second similarity score of the visit scene is second_sim (query, visit), and the calculation formula of the second similarity score of the logistics scene is second_sim (query, logistics). Finally, the first similarity score and each second similarity score are weighted and calculated, and the similar dialogue scene corresponding to the maximum calculation result is determined as the dialogue scene matched with the current dialogue information.
[0074] obtaining feedback information input by the user again; if it is determined according to the feedback information that the dialogue scene matching fails again, extracting a scene keyword from the current dialogue information, generating a new tool list according to the current dialogue information and tool calling data of each dialogue scene, and creating a new dialogue scene according to the scene keyword and the new tool list, and determining the new dialogue scene as the dialogue scene matched with the current dialogue information.
[0075] If the second scene matching fails, a new dialogue scene can be defined for the user. Specifically, a scene keyword can be extracted from the current dialogue information by using a large model, and the scene keyword can be used to name the new dialogue scene; a new tool list can be extracted from the current dialogue information or tool calling data to obtain the new dialogue scene.
[0076] As shown in FIG. 1, a scene keyword "webpage generation" is extracted from the dialogue "help me generate a webpage" as the name of a new dialogue scene, and a "H5 generation" tool is extracted to form a new tool list, and a new dialogue scene is obtained. Figure 5
[0077] In step 102, an agent corresponding to the dialogue scene is determined, and tool calling data of each tool is obtained from description information of the agent.
[0078] Each dialogue scene corresponds to an agent, and each agent corresponds to a tool list. The tools in the tool list can be called to implement related functions. For example, if the dialogue scene is a travel scene, the tool list corresponding to the dialogue scene can include, but is not limited to, a ticket reservation tool, a high-speed rail reservation tool, a hotel reservation tool, a scenic spot ticket purchase tool, and a weather query tool.
[0079] After the most matched dialogue scene is determined according to the current dialogue information, an agent corresponding to the dialogue scene can be found, and tool calling data can be obtained from description information of the agent. The tool calling data includes, but is not limited to, a historical calling rate, a feedback score, an active calling rate, and a preference score. The historical calling rate is the frequency of calling the tool. The feedback score is a score fed back by the user after the tool is called. If the called tool is accurate, a positive feedback score is obtained, and if the called tool is inaccurate, a negative feedback score is obtained. The calling type of the tool includes an active calling type and a passive calling type. The active calling type means that the user specifies the tool to be called in the dialogue information, and the passive calling type means that the tool is recommended according to the dialogue information of the user. The active calling rate is the calling frequency of the tool specified by the user in the dialogue information, and the preference score is a score calculated according to the preference of the user.
[0080] At step 103, a short-term memory context is generated according to the obtained historical dialogue information, a tool context is generated according to the tool invocation data, a file context is generated according to the user-uploaded file, a long-term memory context is generated according to the current dialogue information and the historical dialogue information corresponding to the dialogue scenario, and the short-term memory context, the tool context, the file context, and the long-term memory context are combined to form the scene context.
[0081] (1) Generating a short-term memory context
[0082] Specifically, historical dialogue information can be obtained, and a large model can be used to extract m rounds of dialogue information related to the dialogue scenario from the historical dialogue information, m being a positive integer. Here, m can be set according to actual needs. For example, if m is 20, the last 20 rounds of dialogue information related to the dialogue scenario can be extracted to form a short-term context.
[0083] (2) Generating a tool context
[0084] Specifically, tool invocation data can be obtained, and a tool context can be generated according to historical invocation rates, preference scores, and the like in the tool invocation data.
[0085] (3) Generating a file context
[0086] When a user uploads a file, a large model can be used to determine whether the current dialogue information inquires about the overall content of the file or the segment content of the file. If the current dialogue information inquires about the overall content of the file, all content of the file is taken as the file context. If the current dialogue information inquires about the segment content of the file, the relevant segment content of the file is taken as the file context.
[0087] For example, the current dialogue information inquires about the summary of the file: “Summarize the content of the file.” Or the current dialogue information inquires about the positioning of the file: “What does the third paragraph of the article talk about?” Or the current dialogue information inquires about the comparison of the file: “What is the difference between the two files?” It can be determined that the current dialogue information inquires about the overall content of the file.
[0088] In addition to the above inquiries about the overall content, other inquiries can be considered inquiries about the segment content of the file. Specifically, the current dialogue information can be semantically matched with each segment of the file, and the j most matched segments are extracted as the file context, j being a positive integer.
[0089] For example, Figure 6As shown, the user uploads the file of "Company System", one dialogue information is "What is the overview of the company management system?", and the other dialogue information is "How many days of annual leave does the company have?", the intent can be identified according to the dialogue information, if it is determined that the user asks for the overall content of the file, the entire file is taken as the file context; if it is determined that the user asks for the fragment content of the file, retrieval-augmented generation (RAG) and large language model (LLM) can be used to screen j fragments with semantic relevance, and the j fragments are taken as the file context.
[0090] (4) Generate long-term context
[0091] Each round of dialogue in the dialogue scenario is time-stamped and stored in the following format: (timestamp, scene identifier of the dialogue scenario, original dialogue information, vectorized data block).
[0092] For dialogue information with different timestamps, if the semantic similarity of two pieces of dialogue information is high, for example, the matching degree is greater than 90%, it can be considered that the dialogue content of the two pieces of dialogue information is similar, and the dialogue information with similar dialogue content needs to be covered in chronological order.
[0093] For example, dialogue information 1: (2025 / 08 / 03: user: How much is the first quarter industrial output value? Ai: 100 billion yuan), dialogue information 2: (2024 / 05 / 05: user: How much is the first quarter industrial output value? Ai: 150 billion yuan), dialogue information 2: (2022 / 07 / 14: user: How much is the first quarter industrial output value? Ai: 150 billion yuan), dialogue information 1, dialogue information 2 and dialogue information 3 have similar dialogue content, but the timestamps are different, the latest dialogue information 1 can be stored in the latest memory vector library, all similar old dialogue information 2 and dialogue information 3 can be stored in the historical memory vector library, and the latest memory and the historical memory are connected through a linked list (dialogue information 1-> dialogue information t2-> dialogue information 3), which is sorted by time, facilitating subsequent tracing.
[0094] Specifically, generating the long-term memory context according to the current dialogue information and the historical dialogue information corresponding to the dialogue scene can include: searching for similar dialogue scenes associated with the dialogue scene in a preset knowledge graph; for each similar dialogue scene, searching for the latest k historical data from a latest memory vector library corresponding to the similar dialogue scene, the historical data including a scene identifier of the similar dialogue scene, a timestamp and dialogue information of a round of dialogue, vectorized data blocks, and k being a positive integer; for the dialogue scene, if the current dialogue information does not contain time information, searching for the latest k historical data from the latest memory vector library corresponding to the dialogue scene; if the current dialogue information contains time information, searching for the latest k historical data from the historical memory vector library corresponding to the dialogue scene with the time information as an index, a group of historical data in the historical memory vector library being similar to the dialogue content of a piece of historical data in the latest memory vector library and being linked in a linked list according to the chronological order of the timestamps of the historical data; eliminating historical data with a time interval greater than a second threshold value from the current time; and grouping the remaining historical data into the long-term memory context.
[0095] For each similar dialogue scene, the latest k historical data can be screened from the latest memory vector library.
[0096] For the dialogue scene matching the current dialogue information, the time information can be obtained from the current dialogue information, if the current dialogue information does not contain the time information, the latest k historical data is directly screened from the latest memory vector library; if the current dialogue information contains the time information, the latest k historical data related to the current dialogue information is screened from the historical archive memory library based on the closest match of the time axis. For example, the current dialogue information is “How is this year's industrial output compared with 2022?” and the time information is 2022.
[0097] It should be noted that if the time interval between the current time and the matched historical data is greater than the second threshold value, it means that the hit historical data is too long from the current interval time and has no reference value, and these historical data need to be eliminated. For the remaining historical data, these historical data can be arranged into an abstract as a long-term context.
[0098] Step 104, generating a candidate tool list according to the current dialogue information or tool calling data, each tool in the candidate tool list being sorted according to the user's preference.
[0099] (1) The current dialogue information contains tool description information
[0100] If the current dialogue information contains tool description information, the first n tools with a matching degree greater than a third threshold value with the tool description information are screened from the tool list, and the n tools are grouped into a candidate tool list of the initiative calling type, n being a positive integer.
[0101] If the tool description information in the current dialogue information is highly similar to the description information of the candidate tool, for example, the similarity is greater than a threshold 90%, it can be considered that the calling type of the tool is an active calling type. At this time, the user's intention is to directly call the tool actively, and there is no need to make a preference recommendation of the tool. Specifically, the top n tools can be selected from the tool list with a matching degree greater than a third threshold value, and the candidate tool list can be obtained by sorting in descending order of matching degree.
[0102] For example, the current dialogue information is "I prefer high-speed rail travel.", and the "high-speed rail reservation tool" can be selected as the tool of the active calling type.
[0103] (2) The current dialogue information does not contain tool description information
[0104] If the current dialogue information does not contain tool description information, the top n tools most matched with the semantic information of the current dialogue information are selected from the tool list, the historical calling rate, the feedback score and the active calling rate of the n tools are obtained from the tool calling information, the preference score of the n tools is calculated according to the historical calling rate, the feedback score and the active calling rate, and the n tools are sorted in descending order of the preference score to obtain the candidate tool list of the passive calling type.
[0105] If the tool description information in the current dialogue information is not similar to the description information of the candidate tool, for example, the similarity is less than a threshold 90%, it can be considered that the calling type of the tool is a passive calling type. At this time, the most matched top n tools can be selected from the tool list of the matched dialogue scene based on semantic matching, the preference score of each tool is calculated, and the candidate tool list is obtained by sorting in descending order of the preference score.
[0106] The calculation formula of the preference score of the tool is: tool_prefer_score=history_user_rate*β+feed_back_score*γ+user_call_rate*(1-β-γ). Wherein, tool_prefer_score represents the preference score of the tool, history_user_rate represents the historical calling rate, feed_back_score represents the feedback score, user_call_rate represents the active calling rate, and β and γ represent the weights.
[0107] Optionally, if a tool is called, the default parameter value of the tool can be set to the default parameter value of the last call.
[0108] In step 105, a system prompt word is generated according to the scene context and the candidate tool list.
[0109] For example, the system prompt word is "You are an intelligent agent that solves user problems through repeated tool calls. The user's preference for tools is: high-speed rail, leisure,... The user's priority ranking of tool calls is tool 1, tool 2,...", where the priority ranking can be the ranking of preference scores.
[0110] In step 106, the intelligent agent corresponding to the dialogue scenario is optimized according to the system prompt word and the candidate tool list, to obtain an intelligent agent based on user preferences and context awareness.
[0111] As shown in Figure 7 , the intelligent agent can provide the system prompt word and the candidate tool list to the large model, so that the large model calls the tools in the candidate tool list according to the system prompt word, and pushes the generated answer to the user.
[0112] In this embodiment, the tool list and the dialogue scenario can also be dynamically adjusted.
[0113] (1) If the tool called when answering belongs to the active call type and the tool is not in the tool list corresponding to the dialogue scenario, the tool is added to the tool list, and the preference score of the tool is initialized.
[0114] As shown in Figure 8 , the user specifies the weather query tool in the current dialogue information, so the weather query tool can be added to the tool list of the dialogue scenario, and the initialized preference score can be 50 points.
[0115] (2) If the tool called when answering belongs to the passive call type, update the tool call data according to the feedback information input by the user in the next round, calculate the preference scores of the tools in the tool list according to the tool call data, and delete the tools with preference scores lower than the fourth threshold value from the tool list.
[0116] Specifically, the tool call data can be updated according to the 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" are updated; then, the preference score of the tool is calculated again according to the calculation formula of the preference score mentioned above; compare the preference score of each tool with the fourth threshold value; if there is a preference score lower than the fourth threshold value, delete the tool corresponding to the preference score.
[0117] (3) Calculate the preference score of the dialogue scenario according to the preference scores of all tools, and if the preference score of the dialogue scenario is lower than the fifth threshold value, delete the dialogue scenario.
[0118] The calculation formula of the preference score of the dialogue scenario 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.
[0119] 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.
[0120] 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.
[0121] 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.
[0122] 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.
[0123] 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:
[0124] 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.
[0125] The data acquisition module 920 is configured to determine an agent corresponding to the dialogue scenario, and acquire tool invocation data of each tool from description information of the agent.
[0126] The context generation module 930 is configured to generate short-term memory context according to the acquired historical dialogue information, generate tool context according to the tool invocation data, generate file context according to the file uploaded by the user, generate long-term memory context according to the current dialogue information and the historical dialogue information corresponding to the dialogue scenario, and combine the short-term memory context, the tool context, the file context and the long-term memory context to form scenario context.
[0127] The list generation module 940 is configured to generate a candidate tool list according to the current dialogue information or the tool invocation data, and sort each tool in the candidate tool list according to the preference of the user.
[0128] The prompt word generation module 950 is configured to generate a system prompt word according to the scenario context and the candidate tool list.
[0129] The agent construction module 960 is configured to optimize the agent corresponding to the dialogue scenario according to the system prompt word and the candidate tool list, to obtain an agent based on user preference and context awareness.
[0130] In an optional embodiment, the scenario selection module 910 is further configured to:
[0131] extract preference description information of the user on the scenario from the current dialogue information.
[0132] For each dialogue scenario, acquire a scenario keyword in the scenario description information, and calculate a first similarity score between the current dialogue information, the preference description information and the scenario keyword.
[0133] If the first similarity score is greater than a first threshold, the dialogue scenario is determined as a dialogue scenario matched with the current dialogue information.
[0134] In an optional embodiment, the scenario selection module 910 is further configured to:
[0135] acquire feedback information input by the user in the next round;
[0136] If it is determined according to the feedback information that the dialogue scenario fails to match, find a similar dialogue scenario associated with the dialogue scenario in a preset knowledge graph.
[0137] respectively calculate a second similarity score between the current dialogue information and a scenario keyword of each similar dialogue scenario;
[0138] The first similarity score is weighted with each second similarity score, and a similar dialogue scenario corresponding to a maximum calculation result is determined as the dialogue scenario matching the current dialogue information.
[0139] In an optional embodiment, the scene selection module 910 is further configured to:
[0140] obtain feedback information input by the user again;
[0141] If it is determined according to the feedback information that the dialogue scenario matching fails again, scene keywords are extracted from the current dialogue information, and a new tool list is generated according to the current dialogue information and tool invocation data of each dialogue scenario;
[0142] A new dialogue scenario is created according to the scene keywords and the new tool list, and the new dialogue scenario is determined as the dialogue scenario matching the current dialogue information.
[0143] In an optional embodiment, the context generation module 930 is further configured to:
[0144] search for similar dialogue scenarios associated with the dialogue scenario in a preset knowledge graph;
[0145] For each similar dialogue scenario, the last k pieces of historical data are searched from a latest memory vector library corresponding to the similar dialogue scenario, the historical data including a scene identifier of the similar dialogue scenario, a timestamp and dialogue information of a round of dialogue, vectorized data blocks, and k being a positive integer;
[0146] For the dialogue scenario, if the current dialogue information does not include time information, the last k pieces of historical data are searched from a latest memory vector library corresponding to the dialogue scenario; if the current dialogue information includes time information, the last k pieces of historical data are searched from a historical memory vector library corresponding to the dialogue scenario with the time information as an index, a group of historical data in the historical memory vector library being similar to dialogue content of a piece of historical data in the latest memory vector library, and the group of historical data and the piece of historical data being linked in a linked list according to time stamps of the group of historical data and the piece of historical data in chronological order;
[0147] historical data with a time interval greater than a second threshold value from the current time are removed;
[0148] the remaining historical data are combined to form a long-term memory context.
[0149] In an optional embodiment, the list generation module 940 is configured to:
[0150] If the current dialogue information includes tool description information, the first n tools with a matching degree greater than a third threshold value from the tool list are filtered, a candidate tool list of an active invocation type is formed by the n tools, and n is a positive integer;
[0151] If the tool description information is not contained in the current dialogue information, the first n tools that are most matched with semantics of the current dialogue information are filtered from the tool list, the historical calling rate, the feedback score and the active calling rate of the n tools are obtained from the tool calling information, the preference score of the n tools is calculated according to the historical calling rate, the feedback score and the active calling rate, the n tools are sorted in descending order of the preference score, and a candidate tool list of the passive calling type is obtained.
[0152] In an optional embodiment, after the large model answers according to the system prompt word and the candidate tool list provided by the agent, the device further comprises an updating module configured to:
[0153] If the tool called when answering belongs to the active calling type and the tool is not in the tool list corresponding to the dialogue scene, the tool is added to the tool list, and the preference score of the tool is initialized;
[0154] If the tool called when answering belongs to the passive calling type, the tool calling data is updated according to the feedback information input by the user in the next round, the preference score of each tool in the tool list is calculated according to the tool calling data, and the tool with the preference score lower than the fourth threshold value is deleted from the tool list;
[0155] The preference score of the dialogue scene is calculated according to the preference scores of all the tools, and if the preference score of the dialogue scene is lower than the fifth threshold value, the dialogue scene is deleted.
[0156] In summary, the agent construction device based on a large model provided by the embodiments of the present application can select a matched dialogue scene through the current dialogue information and the scene description information input by the user, generate a scene context based on the dialogue scene, generate a candidate tool list based on the preference of the user, then generate a system prompt word based on the scene context and the candidate tool list, and finally dynamically optimize the agent according to the system prompt word and the candidate tool list to obtain an agent based on the preference and context awareness of the user, so as to more accurately identify the intention and preference of the user and answer according to the intention and preference of the user, thereby improving the accuracy of the answer.
[0157] If the tool description information is contained in the current dialogue information, the first n tools with a matching degree greater than a third threshold value with the tool description information are filtered from the tool list, and the n tools are grouped into a candidate tool list of the active calling type; if the tool description information is not contained in the current dialogue information, the first n tools that are most matched with semantics of the current dialogue information are filtered from the tool list, the preference score of the n tools is calculated, and the n tools are sorted in descending order of the preference score to obtain a candidate tool list of the passive calling type, so that the tool that meets the preference of the user can be adaptively selected, and the accuracy of the tool recommendation is improved.
[0158] By adding the tool actively invoked by the user to the tool list corresponding to the dialogue scene, or by deleting the tools with a preference score lower than the fourth threshold from the tool list, or by deleting the dialogue scenes with a preference score lower than the fifth threshold, the tool list and the dialogue scene can be dynamically optimized, so as to update the preference settings of the agent in real time.
[0159] One embodiment of the present application provides a computer readable storage medium, the storage medium storing at least one instruction, the at least one instruction being loaded and executed by a processor to implement the large model-based agent construction method as described above.
[0160] One embodiment of the present application provides a computer device, the computer device comprising the large model-based agent construction apparatus.
[0161] It should be noted that the large model-based agent construction apparatus provided in the above embodiments is only used as an example for the division of the above functional modules when constructing the large model-based agent. In actual applications, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the large model-based agent construction apparatus is divided into different functional modules to complete all or part of the functions described above. In addition, the large model-based agent construction apparatus and the large model-based agent construction method provided in the above embodiments belong to the same concept, and the specific implementation process is described in the method embodiments, which will not be repeated here.
[0162] Those skilled in the art can understand that all or part of the steps of the above embodiments can be completed by hardware, or by programs instructing related hardware to complete, and the programs can be stored in a computer readable storage medium. The storage medium mentioned above can be a read-only memory, a magnetic disk or an optical disk.
[0163] The above description does not limit the embodiments of the present application. Any adjustment, equivalent replacement, improvement, etc. made within the spirit and principles of the embodiments of the present application shall be included in the protection scope of the embodiments of the present application.
Claims
1. A large model-based agent construction method, characterized in that, The method comprises: obtaining current dialogue information input by a user and scene description information of respective scenes, and selecting a matched dialogue scene according to the current dialogue information and the scene description information; determining an agent corresponding to the dialogue scene, and obtaining tool calling data of respective tools from description information of the agent; generating a short-term memory context according to historical dialogue information corresponding to the dialogue scene, generating a tool context according to the tool calling data, generating a file context according to a file uploaded by the user, and generating a long-term memory context according to the current dialogue information and the historical dialogue information corresponding to the dialogue scene, and composing a scene context from the short-term memory context, the tool context, the file context and the long-term memory context; generating a candidate tool list according to the current dialogue information or the tool calling data, wherein respective tools in the candidate tool list are sorted according to user preferences; generating a system prompt word according to the scene context and the candidate tool list; optimizing the agent corresponding to the dialogue scene according to the system prompt word and the candidate tool list, to obtain an agent based on user preferences and context awareness.
2. The large model-based agent construction method according to claim 1, characterized in that, The method further comprises: extracting preference description information of a user for a scene from the current dialogue information; for each dialogue scene, obtaining a scene keyword in the scene description information, and calculating a first similarity score between the current dialogue information, the preference description information and the scene keyword; if the first similarity score is greater than a first threshold value, the dialogue scene is determined as a dialogue scene matched with the current dialogue information.
3. The large model-based agent construction method according to claim 2, characterized in that, The method further comprises: obtaining feedback information input by the user in a next round; if it is determined that the dialogue scene fails to match according to the feedback information, finding a similar dialogue scene associated with the dialogue scene in a preset knowledge graph; calculating a second similarity score between the current dialogue information and a scene keyword of each similar dialogue scene; performing weighted calculation on the first similarity score and each second similarity score, and determining a similar dialogue scene corresponding to a maximum calculation result as a dialogue scene matched with the current dialogue information.
4. The large model-based agent construction method according to claim 3, characterized in that, The method further comprises: obtaining feedback information input by the user again; if it is determined that the dialogue scene fails to match again according to the feedback information, extracting a scene keyword from the current dialogue information, and generating a new tool list according to the current dialogue information and tool calling data of respective dialogue scenes; creating a new dialogue scene according to the scene keyword and the new tool list, and determining the new dialogue scene as a dialogue scene matched with the current dialogue information.
5. The large model-based agent construction method according to claim 1, wherein, The method further comprises: finding similar dialogue scenes associated with the dialogue scene in a preset knowledge graph; For each similar dialogue scenario, find the latest k historical data from the latest memory vector library corresponding to the similar dialogue scenario, the historical data including the scene identifier of the similar dialogue scenario, the timestamp and dialogue information of one round of dialogue, vectorized data block, and k is a positive integer; For the dialogue scenario, if the current dialogue information does not contain time information, find the latest k historical data from the latest memory vector library corresponding to the dialogue scenario; if the current dialogue information contains time information, find the latest k historical data from the historical memory vector library corresponding to the dialogue scenario with the time information as the index, a group of historical data in the historical memory vector library is similar to the dialogue content of a piece of historical data in the latest memory vector library, and the historical data are linked in the order of the timestamps; Eliminate historical data with a time interval greater than a second threshold from the current time; Group the remaining historical data into long-term memory context.
6. The large model based agent construction method according to claim 1, wherein, The method further comprises: If the current dialogue information contains tool description information, filter the first n tools from the tool list with a matching degree greater than a third threshold with the tool description information, group the n tools into a candidate tool list of active calling type, and n is a positive integer; If the current dialogue information does not contain tool description information, filter the first n tools from the tool list with the most matching semantics with the current dialogue information, obtain the historical calling rate, feedback score and active calling rate of the n tools from the tool calling data, calculate the preference score of the n tools according to the historical calling rate, feedback score and active calling rate, sort the n tools in descending order of preference score to obtain a candidate tool list of passive calling type.
7. The large model-based agent construction method according to claim 6, characterized in that, After the large model answers according to the system prompt word and the candidate tool list provided by the agent, the method further comprises: If the tool called when answering belongs to the active calling type and the tool is not in the tool list corresponding to the dialogue scenario, add the tool to the tool list and initialize the preference score of the tool; If the tool called when answering belongs to the passive calling type, update the tool calling data according to the feedback information input by the user in the next round, calculate the preference score of each tool in the tool list according to the tool calling data, and delete the tools with a preference score lower than a fourth threshold from the tool list; Calculate the preference score of the dialogue scenario according to the preference scores of all tools, and delete the dialogue scenario if the preference score of the dialogue scenario is lower than a fifth threshold.
8. A large model-based agent construction apparatus, characterized by, The device comprises: A scene selection module configured to obtain current dialogue information input by a user and scene description information of each scene, and select a matched dialogue scenario according to the current dialogue information and the scene description information; A data acquisition module configured to determine an agent corresponding to the dialogue scenario, and obtain tool calling data of each tool from description information of the agent; The context generation module is configured to generate a short-term memory context according to the obtained historical dialogue information corresponding to the dialogue scenario, generate a tool context according to the tool invocation data, generate a file context according to the file uploaded by the user, generate a long-term memory context according to the current dialogue information and the historical dialogue information corresponding to the dialogue scenario, and combine the short-term memory context, the tool context, the file context and the long-term memory context to form a scene context. The list generation module is configured to generate a candidate tool list according to the current dialogue information or the tool invocation data, and each tool in the candidate tool list is sorted according to user preferences. The prompt word generation module is configured to generate a system prompt word according to the scene context and the candidate tool list. The agent construction module is configured to optimize an agent corresponding to the dialogue scenario according to the system prompt word 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, and the at least one instruction is loaded and executed by the processor to implement the large model-based agent construction method according to any one of claims 1 to 7.
10. A computer device, comprising: The computer device comprises the large model-based agent construction apparatus according to claim 8.
Citation Information
Patent Citations
Intelligent agent architecture based on multi-modal large model
CN120046645A
Question answering processing method and system, device and storage medium
WO2025146589A1