Model prompt content generation method and device

By generating a functional relationship diagram of external tools and determining the optimal step execution path, the problem of tool call mismatch in the question-answering system is solved, and the accuracy of answers and resource utilization efficiency are improved.

CN120611029AActive Publication Date: 2025-09-09INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202511099918.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-06
Publication Date
2025-09-09
Estimated Expiration
2045-08-06

AI Technical Summary

Technical Problem

In the existing technology, when facing multiple external tools, question-answering systems based on large models are prone to repeated calls or function mismatches, resulting in waste of computing resources and inaccurate answers.

Method used

By generating a functional relationship diagram of external tools, the optimal step execution path is determined based on the semantic analysis results of the user's question text, and prompt content is generated to guide the question-answering model to call external tools in an orderly manner, ensuring that the logic matches user needs.

Benefits of technology

It improves the accuracy of the question-answering system's responses, avoids invalid operations, and improves the utilization efficiency of computing resources and the satisfaction of user needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120611029A_ABST
    Figure CN120611029A_ABST
Patent Text Reader

Abstract

The invention discloses a model prompt content generation method and device, and relates to the technical field of model processing, and the method comprises the steps: generating an external tool function relation graph according to the function description of a plurality of external tools, clearly sorting the logic relation between the tools through the graph, and effectively breaking the disordered state of the scattered calling of the tools. After a user question text is received, the user question text is split into a plurality of steps according to an execution sequence, and complex questions are converted into tasks which can be processed step by step; and combing the cooperation logic among the tools based on the external tool function relation graph, and determining an optimal step execution path by combining the plurality of split steps. Therefore, the target question and answer model can generate the prompt content according to the optimal step execution path, so that the model schematically calls an external tool according to the prompt content and gradually generates the reply corresponding to the user question text, invalid operation caused by lack of clear call logic of the model is avoided, the reply generation accuracy of the model is improved, and the user experience is improved. And the user requirements are met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of model processing technology, and in particular to a method and device for generating model prompt content. Background Art

[0002] In the field of AI question-answering, large-model question-answering systems have been widely adopted in various target applications. Expanding model capabilities through external tools has become a key approach to improving question-answering effectiveness. Currently, interface technologies such as the Model Context Protocol (MCP) enable the connection between target question-answering models and external tools, allowing the models to call on these tools to acquire domain knowledge and execute tasks.

[0003] However, as the number of external tools increases, the functional logical relationship between tools becomes complex, which makes it easy for the model to repeatedly call a certain external tool or assign tasks that do not match the functions of the external tool when generating a response. This not only wastes computing resources but also fails to accurately provide responses that meet user needs.

[0004] Therefore, how to improve the accuracy of the model's answers has become an urgent problem to be solved. Summary of the Invention

[0005] The present application provides a method and device for generating model prompt content, so as to at least solve the problem of low accuracy of model answers in related technologies.

[0006] In a first aspect, the present application provides a method for generating model prompt content, comprising: Acquire multiple external tools corresponding to the target question-answering model in the target application; the multiple external tools are connected to the target question-answering model based on a model context protocol interface; Generate an external tool function relationship graph based on the function descriptions corresponding to the plurality of external tools; the external tool function relationship graph is an undirected graph; the external tool function relationship graph includes logical relationships between function nodes corresponding to the plurality of external tools; Receive a user question text, and based on the semantic analysis result corresponding to the user question text, obtain multiple steps for answering the user question text; Based on the relationship diagram between the multiple steps and the external tool functions, the optimal step execution path is determined, and prompt content for prompting the target question-answering model is generated according to the optimal step execution path; the optimal step execution path includes the multiple steps and their corresponding functional nodes.

[0007] In a second aspect, the present application provides a method for generating model prompt content, comprising: An acquisition unit, configured to acquire a plurality of external tools corresponding to a target question-answering model in a target application; the plurality of external tools being connected to the target question-answering model based on a model context protocol interface; A generating unit is configured to generate an external tool function relationship graph according to the function descriptions corresponding to the plurality of external tools; the external tool function relationship graph is an undirected graph; the external tool function relationship graph includes logical relationships between function nodes corresponding to the plurality of external tools; a processing unit, configured to receive a user question text and, based on a semantic parsing result corresponding to the user question text, obtain a plurality of steps for answering the user question text; A determination unit is used to determine the optimal step execution path based on the multiple steps and the external tool function relationship diagram, and generate prompt content for prompting the target question-answering model according to the optimal step execution path; the optimal step execution path includes the multiple steps and their corresponding functional nodes.

[0008] In a third aspect, the present application also provides an electronic device, comprising: a memory for storing a computer program; and a processor for implementing the steps of any of the above-mentioned methods for generating model prompt content when executing the computer program.

[0009] In a fourth aspect, the present application further provides a computer-readable storage medium, in which a computer program is stored, wherein when the computer program is executed by a processor, the steps of any of the above-mentioned methods for generating model prompt content are implemented.

[0010] In a fifth aspect, the present application also provides a computer program product, including a computer program, which, when executed by a processor, implements the steps of any of the above-mentioned methods for generating model prompt content or the steps of any of the above-mentioned methods for generating model prompt content.

[0011] This application generates a functional relationship diagram of external tools through the functional descriptions of multiple external tools, and uses this diagram to clearly sort out the logical associations between the tools, effectively breaking the disordered state of scattered tool calls. After receiving the user's question text, according to the semantic analysis results corresponding to the user's question text, and in accordance with the multiple steps of answering the user's question text, the complex problem is converted into a task that can be processed step by step; then, based on the external tool functional relationship diagram, the collaboration logic between the tools is sorted out, and the optimal step execution path is determined based on the multiple steps split out. Thus, the target question-answering model can generate prompt content based on the optimal step execution path, and then the model can call the external tool in a planned manner according to the prompt content, and gradually generate a reply corresponding to the user's question text, avoiding invalid operations caused by the lack of clear calling logic, and improving the accuracy of the model-generated replies to meet user needs. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0013] In order to more clearly illustrate the embodiments of the present disclosure or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0014] Figure 1 A flowchart of a method for generating model prompt content provided in an embodiment of the present application; Figure 2 A schematic diagram of the functional relationship of external tools in a method for generating model prompt content provided in an embodiment of the present application; Figure 3 A flowchart of a method for generating model prompt content provided in an embodiment of the present application; Figure 4 A schematic diagram of the execution path of steps in a method for generating model prompt content provided in an embodiment of the present application; Figure 5 A schematic diagram of a path generation process of a method for generating model prompt content provided in an embodiment of the present application; Figure 6 A flowchart of a method for generating model prompt content provided in an embodiment of the present application; Figure 7 A flowchart of a method for generating model prompt content provided in an embodiment of the present application; Figure 8 A schematic diagram of the structure of a device for generating model prompt content provided in an embodiment of the present application. DETAILED DESCRIPTION

[0015] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0016] It should be noted that, in the description of this application, the terms "comprises," "includes," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. The terms "first," "second," etc., in this application are used to distinguish similar objects, and are not used to describe a particular order or sequence.

[0017] In order to enable those skilled in the art to better understand the present application, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.

[0018] In some embodiments, as Figure 1 As shown, a method for generating model prompt content is provided, comprising the following steps S11-S14: S11. Obtain multiple external tools corresponding to the target question-answering model in the target application.

[0019] Among them, multiple external tools are connected to the target question-answering model based on the model context protocol interface.

[0020] In some embodiments, the target application can be any application equipped with a corresponding question-and-answer model. For example, a smart travel application can provide users with smart travel-related services (such as route planning, traffic condition query, and travel tool recommendations) through the use of a built-in question-and-answer model. Another example is a disease consultation application that provides users with disease consultation-related services (such as disease symptom answers) through the use of a built-in question-and-answer model.

[0021] User needs are often complex, and to better provide relevant services to users, a single model cannot independently meet these needs. Therefore, the target question-answering model within the target application will be connected to a variety of external tools to assist the target question-answering model in answering user questions. For example, smart travel applications need to handle travel planning, merchant search, and discount information retrieval, and they typically connect to map navigation APIs, merchant information libraries, and discount event query tools.

[0022] It's important to note that the multiple external tools corresponding to the target question-answering model connect to the target question-answering model through the Model Context Protocol (MCP). The MCP is an open-source, standard protocol interface that serves as a universal interface for interaction between external tools and the target question-answering model. Through this interface, the target question-answering model can safely and efficiently invoke the functions of the external tools, and the external tools can accurately return processing results to the model, ensuring collaborative operation between the two.

[0023] S12: Generate an external tool function relationship diagram based on the function descriptions corresponding to the multiple external tools.

[0024] The external tool function relationship diagram is an undirected graph; the external tool function relationship diagram includes the logical relationships between function nodes corresponding to multiple external tools.

[0025] Specifically, the functional descriptions of multiple external tools corresponding to the target question-answering model are obtained. Based on the functional relevance or data dependency relationships among the tools, an external tool functional relationship graph is generated. In the external tool functional relationship graph, nodes represent external tools, and edges represent the logical relationships between tools. Furthermore, the external tool functional relationship graph is an undirected graph, meaning it has no direction and only reflects associations, not a strict call order.

[0026] For example, when the target application is a smart travel application, its corresponding target question-answering model may include functional nodes corresponding to the following tools: (1) Get the city code based on the city name.

[0027] (2) Get the weather for the past week based on the city code.

[0028] (3) Get attractions based on city name.

[0029] (4) Check the ticket price based on the attraction name.

[0030] (5) Travel itinerary planning.

[0031] (6) Obtain the latest news of a city based on its name.

[0032] Then, based on the functional descriptions of the above 6 nodes and the logical relationships between them, the following is generated: Figure 2 The functional relationship diagram of the external tools shown includes the above-mentioned 6 functional nodes and their corresponding functional descriptions, as well as edges connected according to the logical relationship between the tools.

[0033] In the embodiment of the present application, based on the functional descriptions corresponding to the multiple external tools, the specific implementation steps of generating the external tool functional relationship diagram can be refined into the following steps 1 and 2: Step 1: traverse multiple external tools and extract the functional description information corresponding to each external tool.

[0034] Specifically, by traversing all external tools connected to the target question-answering model in the target application, core function-related information is extracted from each external tool to obtain a functional description of the external tool.

[0035] At the same time, you can also obtain the types and descriptions of the input parameters required by external tools (such as the city name as a string input parameter) and the types and descriptions of the output return values ​​(such as the return value as a list containing the name and address of a scenic spot). Furthermore, by standardizing the functions, parameters, and return value information of collection tools, we can uniformly describe the tool's capability boundaries and data interaction characteristics, providing a basis for determining whether there are functional correlations or logical dependencies between tools, and avoiding inaccurate tool relationship analysis due to missing information.

[0036] Step 2: Generate an external tool function relationship diagram based on the function description information corresponding to each external tool.

[0037] Furthermore, after extracting the functional description information of each tool through step one, the functional description information of each tool can be input into the external tool functional relationship diagram generation model. Through model analysis and calculation, the logical relationship between the external tools can be determined and structured and presented in the form of an undirected graph.

[0038] Each external tool is regarded as a functional node in the graph; if the functional description information of two tools has semantic relevance or data interaction is possible, an edge is added between the corresponding nodes to mark the logical association, forming a complete tool relationship network.

[0039] By pre-sorting out the functional relevance and potential collaboration logic between tools, we can avoid real-time analysis of tool relationships when answering user questions, thereby reducing computing resource usage. On the other hand, the diagram provides an intuitive basis for subsequent matching of user demand steps with tool call paths, ensuring that the tool call logic complies with the functional association rules and improving the efficiency of solving complex needs.

[0040] S13: Receive a user question text, and based on the semantic analysis result corresponding to the user question text, obtain multiple steps for answering the user question text.

[0041] After the user inputs the question text into the target application, the target question-answering model can first obtain multiple steps for answering the user's question text based on the semantic analysis results corresponding to the user's question text.

[0042] Specifically, the target question-answering model can use natural language processing technology to first perform semantic analysis on the user's question text to clarify the user's needs and the multiple steps required to achieve the needs.

[0043] On this basis, we follow the logical order of each step to obtain multiple steps for answering the user's question. For example, if the user's question is: "Help me plan a three-day trip to City A," the target question-answering model can infer that the semantic parsing result corresponding to the current question is: "I need to obtain information about City A's weather, attractions, transportation, and attraction costs, and then generate an itinerary." Then, according to the response ideas provided by the above semantic parsing results, the multiple steps for answering the user's question are as follows: (1) Obtain the city code of City A.

[0044] (2) Get the weather data of City A for the past three days.

[0045] (3) Obtain tourist attraction information in City A.

[0046] (4) Obtain traffic information for City A.

[0047] (5) Summarize the retrieved information and generate a 3-day travel plan for City A.

[0048] Furthermore, by breaking down the complex and abstract questions raised by users into multiple steps with a clear execution order, user needs can be converted into multiple steps that can be understood and processed by the target question-answering model and external tools, providing clear task guidance for subsequent matching of corresponding tools based on the external tool function relationship diagram and planning of execution paths, avoiding tool call deviations caused by ambiguous requirements.

[0049] S14. Based on the relationship diagram between multiple steps and external tool functions, determine the optimal step execution path, and generate prompt content for prompting the target question-answering model based on the optimal step execution path.

[0050] The optimal step execution path includes multiple steps and their corresponding functional nodes.

[0051] Specifically, in combination with the external tool function relationship diagram, multiple adapted tools are determined according to the matching degree between multiple steps and each functional node in the external tool function relationship diagram, and the optimal step execution path is generated according to the logical relationship between the multiple tools.

[0052] Furthermore, the optimal step execution path generated based on the optimal step execution path includes multiple steps and their corresponding functional nodes, and the prompt content corresponding to the target question-answering model is generated to prompt the target question-answering model to generate a clear and accurate answer according to the prompt content.

[0053] For example, in combination with the examples shown in steps S12 and S13 above, the generated optimal step execution path may be: The function node corresponding to the first step, "obtaining the city code of City A", is: obtaining the city code according to the city name.

[0054] The function node corresponding to the second step, "Get the weather of City A in the past three days" is: Get the weather in the past week based on the city code.

[0055] The function node corresponding to the third step, "obtaining scenic spot information of City A" is: obtaining scenic spots according to the city name.

[0056] The function node corresponding to the fourth step, "Get ticket price information for attractions in City A", is: query ticket prices based on the attraction name.

[0057] The functional node corresponding to the fifth step, "summarize the queried information to generate a 3-day travel plan for City A" is: travel itinerary planning.

[0058] In the above optimal step execution path, each step is connected in sequence according to the execution order, and the function node corresponding to each step has a logical association in the external tool function relationship diagram generated in S12.

[0059] Based on this optimal step execution path, a model prompt can be generated. Combining this optimal step execution path, the generated prompt can be: "First, call the 'Get City Code Based on City Name' tool to obtain the city code of City A; then call the 'Get Weather in the Last Week Based on City Code' tool to obtain the weather in City A for the past three days; then call the 'Get Attractions Based on City Name' tool to obtain attraction information in City A; then call the 'Query Ticket Price Based on Attraction Name' tool to obtain the ticket prices for the aforementioned attractions; finally, call the 'Travel Itinerary Planner' tool to generate a three-day travel plan for City A based on the weather, attraction, and ticket price information." By combining the steps with the external tool function relationship diagram to determine the optimal step execution path, it is possible to ensure that the selected external tool calling logic is compatible with the execution order required by the user, thereby improving the accuracy and efficiency of tool calling; and the prompt content generated based on the optimal path can clearly guide the target question-and-answer model to call the external tool as planned, avoiding invalid operations caused by the lack of clear calling logic, and ensuring the efficient realization of user needs.

[0060] This application generates a functional relationship diagram of external tools through the functional descriptions of multiple external tools, and uses this diagram to clearly sort out the logical associations between the tools, effectively breaking the disordered state of scattered tool calls. After receiving the user's question text, according to the semantic analysis results corresponding to the user's question text, and in accordance with the multiple steps of answering the user's question text, the complex problem is converted into a task that can be processed step by step; then, based on the external tool functional relationship diagram, the collaboration logic between the tools is sorted out, and the optimal step execution path is determined based on the multiple steps split out. Thus, the target question-answering model can generate prompt content based on the optimal step execution path, and then the model can call the external tool in a planned manner according to the prompt content, and gradually generate a reply corresponding to the user's question text, avoiding invalid operations caused by the lack of clear calling logic, and improving the accuracy of the model-generated replies to meet user needs.

[0061] As an extension and refinement of the above embodiment, Figure 3 This is a flow chart of a method for generating model prompt content provided by an embodiment of the present disclosure, such as Figure 3 As shown, a method for generating model prompt content provided by an embodiment of the present disclosure includes: S31. Generate a step execution path diagram based on multiple steps.

[0062] The step execution path graph is a directed graph; the step execution path graph includes the logical relationships between step nodes corresponding to multiple steps.

[0063] In this step, based on the multiple steps obtained in S13 above, the steps are converted into a directed graph in the order of execution, that is, a step execution path graph. Each step corresponds to a step node in the graph, and the dependency relationship between the steps is marked with a directional edge (directed edge) to emphasize the order between the step executions. For example, based on the multiple steps used to answer the user's question text in step S13, a corresponding step execution path graph is generated, referring to Figure 4 As shown, there are three step execution paths that can be executed in parallel: Article 1: Obtain transportation information for City A - Summarize the retrieved information to generate a 3-day travel plan for City A.

[0064] Article 2: Obtain information about scenic spots in City A - Summarize the retrieved information to generate a 3-day travel plan for City A.

[0065] Article 3: Obtain the city code of City A - Obtain the weather of City A in the past three days - Summarize the queried information to generate a three-day travel plan for City A.

[0066] Furthermore, the execution sequence relationship between steps is intuitively presented through the step execution path diagram, avoiding confusion in the step sequence and providing a structured basis for subsequent precise matching of external tools and positioning the start and end range of the path.

[0067] S32. Obtain a step node set in the step execution path graph.

[0068] The step node set includes step nodes that have a matching relationship with the function nodes in the external tool function relationship diagram.

[0069] Then, from the step execution path diagram, step nodes that match the function nodes in the external tool function relationship diagram are screened to form a step node set. This eliminates steps that cannot be implemented by the external tool, reduces ineffective calculations in subsequent path planning, and avoids wasted tool call resources. Furthermore, since "Obtaining traffic information for City A" in the first path generated in S31 above has no matching function node, this step can be disregarded when subsequently generating the optimal step execution path.

[0070] Specifically, the detailed steps of obtaining the step node set in the step execution path graph may include the following: Step 1: Calculate the semantic relevance between each step in the step execution path diagram and each external tool function in the external tool function relationship diagram to obtain a semantic relevance value.

[0071] In some embodiments, natural language processing technology can be used to perform a semantic-level similarity quantification analysis on each step node in the step execution path diagram (such as obtaining the weather in City A for the past three days) and each function node in the external tool function relationship diagram (such as obtaining the weather in the past week based on the city code) to output a specific semantic relevance value.

[0072] Furthermore, the step description corresponding to each step node and the functional description corresponding to the tool node can be converted into vector representations first; the matching degree between the vectors can be calculated through a vector similarity algorithm (such as cosine similarity and Euclidean distance) to generate a semantic correlation value, and then the matching relationship between the step node and the tool's functional node can be determined based on the size of the semantic correlation value.

[0073] Step 2: Generate a set of step nodes based on semantic related values.

[0074] Specifically, a preset threshold for the semantic relevance value can be pre-set to include step nodes that meet the matching conditions into the step node set. For example, if the semantic relevance value threshold is set to 0.6, for each step node in the step execution path diagram, if the semantic relevance value between the step node and at least one function node of the external tool is greater than or equal to 0.6, then the step node is determined to have a valid matching relationship with the function node and is included in the step node set; if the semantic relevance value between the step node and all tool function nodes is less than the threshold, then it is determined that the step can be solved by the target question-answering model itself, or that the step has not matched the corresponding tool and cannot be solved at present, and is not included in the set.

[0075] For example, according to the above Figure 2 and Figure 4 After semantic matching, the step nodes and function nodes shown in the figure can be obtained as follows: "Get the city code of City A" matches "Get the city code based on the city name"; "Get the scenic spot information of City A" matches "Get the scenic spot based on the city name"; "Get the weather in the past three days of City A" matches "Get the weather in the past week based on the city code"; "Summarize the queried information to generate a three-day travel plan for City A" matches "Travel itinerary planning".

[0076] Furthermore, the step nodes are concentrated to include four step nodes: obtaining the city code of City A, obtaining the scenic spot information of City A, obtaining the weather of City A in the past three days, and summarizing the retrieved information to generate a three-day travel plan for City A.

[0077] S33. Determine the start and end step nodes of the target path based on the step node set and the step execution path graph.

[0078] Specifically, the starting and ending points of the target path are located based on the step node set and the step execution path graph. By traversing the step node set along the directed edges of the step execution path graph, the earliest executed step node in the set is determined as the starting step node of the target path; the latest executed step node in the set is determined as the ending step node of the target path, thus generating the starting and ending step nodes of the target path.

[0079] S34. Generate an optimal step execution path based on the target path start and end step nodes, step node set and external tool function relationship diagram.

[0080] Furthermore, after determining the start and end step nodes of the target path, the functional nodes that match the start and end step nodes of the target path and the multiple steps in the step node set can be determined in the external tool functional relationship diagram. Then, based on the matching results between the external tool functional relationship diagram and the start and end step nodes of the target path and the step node set, the optimal step execution path can be obtained.

[0081] This step ensures that the path starts from the starting step node and ends at the ending step node, covering the entire core process; the path should include as many steps as possible in the step node set, and the function nodes that match the step node set should be screened in the tool relationship diagram. The tool calling order should be determined based on the logical association between the nodes.

[0082] By generating a directed step execution path diagram, the logical relationship of each step after the user's question is broken down can be clearly presented, avoiding confusion in the order of step execution; obtaining a step node set that matches the external tool function can accurately locate the core steps that require tool support and reduce the interference of irrelevant steps on path planning; combining the step node set and the path diagram to determine the start and end step nodes of the target path can clarify the path boundaries and ensure that the planning scope is focused on the core process; finally, the optimal step execution path is generated based on the start and end nodes, step node set and tool function relationship diagram, which can guide the target question and answer model to call the tool according to the optimal logic, avoid invalid operations caused by disordered tool calls, improve the efficiency and accuracy of response generation, and ensure the efficient realization of user needs.

[0083] As an extension and refinement of the above embodiment, in the above step S33, when determining the start and end step nodes of the target path based on the step node set and the step execution path graph, it is necessary to further determine the start and end step nodes of the target path using a corresponding method based on whether there is a path branch in the step execution path graph. When there is no path branch in the step execution path graph, the following steps a1 to a4 are specifically included: Step a1: When there is no path branch in the step execution path graph, obtain the first step execution path.

[0084] The first step execution path is the path containing the most nodes in the step node set in the step execution path graph.

[0085] If the step execution path graph is a single linear structure (no branches, such as Step 1 - Step 2 - Step 3 - Step 4), the continuous path containing the largest number of nodes in the step node set (tool-supported steps) is selected from the graph and defined as the first step execution path. For example, if the step node set consists of Step 2 and Step 3, then "Step 1 - Step 2 - Step 3 - Step 4" containing these two nodes is the first step execution path (since there are no other branches, this path is the only path with the largest number of nodes).

[0086] In branchless scenarios, the filtering rule with the most nodes ensures that the first step execution path covers the core steps in the step node set, providing a complete logical chain foundation for subsequent determination of the start and end nodes, avoiding the omission of key steps due to path truncation being too short. Clearly defining the boundaries of the path in branchless scenarios ensures that the subsequent tool call path is coherent from the start to the end point, strictly matching the step execution order to avoid path breakage.

[0087] Step a2: Execute the start and end steps of the path based on the first step to obtain the start and end step nodes of the target path.

[0088] This step uses the first step execution path determined by a1 as the basis. The first step node of this path is defined as the starting step node of the target path, and the last step node is defined as the ending step node of the target path. For example, if the first step execution path is "Step 1 - Step 2 - Step 3 - Step 4", the starting point is "Step 1" and the ending point is "Step 4".

[0089] Clarify the boundaries of the path in a branchless scenario to ensure that subsequent tool call paths are coherent from the start point to the end point, strictly matching the step execution order to avoid path breaks.

[0090] Step a3: When the number of the target path start and end step nodes is equal to one pair, determine the target start and end function nodes that match the target path start and end step nodes from the external tool function relationship diagram.

[0091] When the target path's start and end step nodes are a unique pair (e.g., start point: step A, end point: step B), the semantic relevance calculation is used to find the functional nodes that match the start step and end step respectively in the external tool functional relationship diagram and define them as the target start and end functional nodes.

[0092] Establish a direct mapping between the step start and end nodes and the tool function nodes to ensure that the starting and ending points of the tool call path are consistent with the step logic.

[0093] Step a4: Combine the target start and end function nodes and the step node set, and generate the optimal step execution path based on the external tool function relationship diagram.

[0094] The optimal step execution path obtained in this step starts from the target starting point function node and ends at the target ending point function node; the function nodes in the path match the steps in the step node set one by one (for example, step C corresponds to tool C, and step D corresponds to tool D); the logical associations between the function nodes (such as data flow and functional complementarity) conform to the step execution order.

[0095] In a single branch scenario, the embodiment of the present application generates an optimal path that conforms to the step execution logic and the tool collaboration relationship by matching steps and tools, ensuring that tool calls accurately cover all core steps and improving path execution efficiency.

[0096] When there is a target path branch in the step execution path diagram, the following steps are specifically included: Step b1: When there is a target path branch in the step execution path graph, for each path branch, obtain the second step execution path corresponding to the path branch.

[0097] Among them, the target path branch is a path branch including at least two step nodes in the step node set; the second step execution path is a path branch including the largest number of step nodes in the step node set.

[0098] When there are branches in the step execution path diagram, each branch is analyzed separately. For example, refer to Figure 4 As shown, there is a path branch in the step execution path diagram. Since the "obtaining traffic information of city A" in the first path does not match the corresponding function node when matching the step nodes and function nodes, there is only one step node in the step node set in the first path. At this time, the reference significance of the path branch is small. Therefore, when determining the second step execution path, the first path can be ignored, and only the second and third paths are analyzed subsequently.

[0099] Furthermore, according to the fact that the second step execution path is the path with the largest number of step nodes in the step node set among the path branches, the following two second step execution paths can be obtained: 1) Get information about attractions in City A—Summarize the retrieved information and generate a 3-day travel plan for City A.

[0100] 2) Get the city code of City A - Get the weather in City A for the past three days - Summarize the retrieved information to generate a three-day travel plan for City A.

[0101] Through this step, in a multi-branch scenario, by screening each branch and the path with the largest number of step nodes in the step node set, we ensure that the core steps of each branch are included in the second step execution path, avoiding the omission of some key steps due to the existence of branches, and providing a basis for subsequent comparison of branch priorities.

[0102] Step b2: Based on the path start and end steps of the multiple second step execution paths, obtain multiple target path start and end step nodes.

[0103] This step is based on the multiple second step execution paths obtained in step b1, and extracts the starting step node and the ending step node of each second step execution path respectively to form multiple pairs of target path starting and ending step nodes.

[0104] Combined with the two second-step execution paths obtained in step b1 above, the starting and ending nodes of the target path are obtained as follows: Starting point - obtaining scenic spot information for City A, End point - summarizing the retrieved information to generate a 3-day travel plan for City A. Starting point - obtaining the city code for City A, End point - summarizing the retrieved information to generate a 3-day travel plan for City A.

[0105] Step b3: When the number of the target path start and end step nodes is greater than one pair, multiple target start and end function nodes matching the multiple target path start and end step nodes are determined from the external tool function relationship diagram.

[0106] When the target path has multiple pairs of start and end step nodes (such as two pairs), semantic relevance is calculated to match corresponding function nodes in the external tool function relationship graph for each pair of start and end step nodes to obtain multiple pairs of target start and end function nodes.

[0107] Further, in combination with the embodiment of the above-mentioned step b2, the starting and ending nodes of the step are: starting point - obtaining scenic spot information of City A, which matches the function node "query ticket prices based on scenic spot name, obtain scenic spots based on city name"; end point - summarizing the queried information to generate a 3-day travel plan for City A, which matches the "travel itinerary planning".

[0108] Furthermore, referring to the second step of performing the path matching for each branch, the function node of the corresponding tool is matched to ensure that the tool paths of different branches have clear function starting points and function ending points.

[0109] Step b4: combining multiple target start and end function nodes and step node sets, and determining multiple third step execution paths based on the external tool function relationship diagram.

[0110] In this step, the positions of multiple target start and end function nodes are first determined in the external tool function relationship diagram, and then the descriptions of each step in the step node set are matched with the function nodes in the external tool function relationship diagram, that is, the starting point and end point of the step are clearly defined in the external tool function relationship diagram, and at the same time, the positions of the function nodes that match other step nodes in the step node set in the external tool function relationship diagram are determined. Then, according to the positions of the multiple target start and end function nodes and the positions of other function nodes that need to be deployed in the step node set, multiple third step execution paths are determined, combined with Figure 2 Refer to the diagram of the external tool functions shown in Figure 5 As shown, the gray nodes are function nodes that successfully match the step nodes. Then, based on multiple target start and end function nodes and the step node set, the following three function paths can be generated: (1) Obtain attractions based on city names—travel itinerary planning.

[0111] (2) Get attractions based on city name - check ticket prices based on attraction name - travel itinerary planning.

[0112] (3) Obtain the city code based on the city name - obtain the weather information for the past week based on the city code - travel itinerary planning.

[0113] Furthermore, based on these three functional paths, multiple third step execution paths are generated by combining the step node set, as follows: (1) Obtaining the scenic spot information of City A - Summarizing the queried information to generate a 3-day travel plan for City A.

[0114] (2) Obtain information about scenic spots in City A—Summarize the retrieved information to generate a 3-day travel plan for City A.

[0115] (3) Obtain the city code based on the city name - obtain the weather of City A in the past three days - summarize the queried information to generate a three-day travel plan for City A.

[0116] Provide candidate solutions for subsequent screening of the best path.

[0117] Step b5: Obtain the number of target step nodes corresponding to multiple third step execution paths.

[0118] The target step node quantity is the number of nodes where the third step execution path matches the step nodes in the step node set.

[0119] Count the number of step nodes that match the step node set in each third step execution path (that is, the number of core steps covered by the path).

[0120] Provides quantitative indicators for screening the best path and measures the degree to which the path meets core requirements by the number of covered steps.

[0121] Step b6: The third step execution path with the largest number of target step nodes is taken as the optimal step execution path.

[0122] Compare the number of target step nodes in multiple third-step execution paths and select the path with the largest number as the optimal path. If the number of target step nodes is the same, further filtering can be performed based on tool call costs (such as resource consumption). For example, if branch 1 covers 3 steps and branch 2 covers 2, branch 1 is the optimal path.

[0123] In a multi-branch scenario, the optimal path is selected by covering the most steps, ensuring that the best path can meet the core steps of user needs to the greatest extent and improve the effectiveness of the path.

[0124] As an extension and refinement of the above embodiment, refer to Figure 6 As shown, in the above b6, if there are multiple third step execution paths with the same number of target step nodes, the steps of determining the best step execution path include the following: S61. When there are multiple third-step execution paths with the same number of target step nodes, obtain corresponding resource consumption evaluation results for the third-step execution paths with the same number of target step nodes.

[0125] When the number of target step nodes covered by multiple third-step execution paths is the same (for example, they can all match 3 steps in the step node set), the resource consumption of each path needs to be further evaluated.

[0126] Resource consumption evaluation dimensions include, but are not limited to, tool call token consumption (the number of characters used to pass data when calling an API), GPU compute time (the time it takes for the tool to process data), API response latency (the time it takes for the tool to return results), and network bandwidth usage (data transmission traffic consumption). These dimensions are quantitatively scored using a pre-set evaluation model to generate resource consumption evaluation results for each path (e.g., a comprehensive score, where lower scores indicate lower consumption).

[0127] Step A: For the third step execution path with the same number of target step nodes, obtain resource consumption scores corresponding to multiple external tools in the third step execution path.

[0128] When multiple third-step execution paths have the same number of target step nodes, a quantitative resource consumption assessment is required for each external tool involved in each path. Resource consumption scoring dimensions include, but are not limited to, token consumption per tool call, interface response time, and GPU computing resource usage. Using a pre-defined scoring model (e.g., normalizing and weighting data across dimensions), a resource consumption score of 0-10 is generated for each external tool (lower scores indicate lower consumption).

[0129] For example, path A involves the "city code query tool" and the "weather query tool", with resource consumption scores of 2 and 3 points respectively; path B involves the "city information comprehensive query tool" (which can complete code and weather queries at the same time), with a resource consumption score of 4 points.

[0130] It should be noted that when the current user asks the first question in this round of Q&A, that is, when the target Q&A model generates an answer for the first time, since all MCP tools have no historical call consumption data for this round, an initial resource consumption quantitative assessment is required to obtain the corresponding resource consumption score for each tool.

[0131] After the target question-and-answer model completes the first question and answer, a quantitative assessment of the cycle resource consumption can be performed according to a preset cycle (such as each round of user question and answer, or a fixed time interval). That is, the corresponding tool resource consumption score is corrected based on the actual resource data consumed by the historically called tools to reduce the deviation between the assessment and actual execution.

[0132] Specifically, the initial resource consumption quantitative evaluation and the periodic resource consumption quantitative evaluation can be performed based on the STDIO method.

[0133] Initial assessments rely on the local deployment features of the tools (which provide access to source code and underlying information). AI tools can be used to parse the MCP tool source code and assess algorithm complexity. This involves scoring external operations such as disk access (e.g., file reading and writing) and network requests contained in the code to obtain an initial resource consumption score for each tool. This score can then be used to select tools with lower resource consumption.

[0134] After the target question-answering model completes its first question-answering session, it enters the periodic evaluation phase, where the score is revised based on the actual resource data of historical calls. The specific steps are as follows: After each round of Q&A, the actual resource consumption data of all MCP tool calls during that cycle is collected, including: time consumption (the total time from tool call to return result); disk IO consumption (the total amount of data read and written by the tool to the local disk); and network consumption (the total traffic of the tool uploading / downloading data).

[0135] Sort all tools from low to high based on time consumption, disk IO, and network consumption, and obtain the ranking value of each tool in each dimension (denoted as t, d, and i). Calculate the total ranking score using the preset weight formula: R=10t+5d+i (time consumption has the highest weight because it directly affects user experience). Substitute the total ranking score into the exponentially weighted moving average algorithm and combine it with the score of the historical period (with a smoothing coefficient of 0.5) to generate a smoothed score to avoid drastic changes in ranking caused by a single fluctuation. Re-sort by smoothed score, and correct the tool resource consumption score and call priority to make the evaluation results gradually closer to the actual consumption.

[0136] Furthermore, the initial resource consumption quantitative evaluation and the periodic resource consumption quantitative evaluation can also be performed based on the SSE method.

[0137] Because the MCP tool is deployed remotely in the SSE mode, the system cannot obtain underlying information such as source code and disk reading and writing. The initial assessment must rely on preset rules or manual input. Specifically, it includes: All MCP tools are assigned a unified initial resource consumption score (e.g., a default value of 5) as a temporary reference. Users are allowed to manually adjust the initial scores of some tools based on their actual tool usage experience (e.g., if a remote query tool is known to respond slowly, its score can be set to 8). Tools are ranked based on these scores (default or manually adjusted) as the priority for initial calls, and will be dynamically adjusted through periodic evaluations.

[0138] After the target question-answering model completes its first question-answering session, it enters the periodic evaluation phase, where the score is revised based on the actual resource data of historical calls. The specific steps are as follows: The actual resource data invoked by the MCP tool during the collection cycle is limited by the remote deployment feature. Only the two types of data mentioned in the STDIO method above, namely time consumption and network consumption, can be obtained. Dimension sorting and weighted calculation are also available. The total score is calculated using the simplified formula: R=10t+i. The total ranking score is substituted into the exponentially weighted moving average algorithm (EMA, smoothing coefficient 0.5), integrating the current period data with historical evaluation results to avoid drastic fluctuations in the ranking. The smoothed scores are then re-sorted, and the tool resource consumption scores are corrected to gradually align the evaluation results with the actual consumption of remote calls, thereby improving the rationality of subsequent tool calls.

[0139] Step B: Obtain a resource consumption evaluation result corresponding to the execution path of the third step according to the resource consumption scores corresponding to the multiple external tools corresponding to the execution path of the third step.

[0140] The resource consumption scores of the individual external tools obtained are superimposed to obtain the resource consumption evaluation result corresponding to the execution path of the third step, that is, the total resource consumption score.

[0141] It should be noted that when calculating the total resource consumption score, a weighted sum of the importance of different tools can be used to calculate the total resource consumption score for a single third-step execution path. For example, if the total tool score for path A is 2 + 3 = 5, and the total tool score for path B is 4, the resource consumption assessment result for path A is 5, and for path B is 4.

[0142] S62. Determine the optimal step execution path based on the resource consumption evaluation result.

[0143] Then, based on the resource consumption evaluation results obtained above, the path with the lowest resource consumption among the third step execution paths with the same number of target step nodes is selected as the optimal step execution path. For example, if the resource consumption evaluation score of path A is 30 (low consumption) and the score of path B is 50 (high consumption), path A is selected as the optimal path.

[0144] Prioritize solutions with lower resource consumption among functionally equivalent paths to reduce token waste and computational delays during tool invocation, improve system operation efficiency, and reduce the operation and maintenance costs of the target application (such as computing power and network costs).

[0145] As an extension and refinement of the above embodiment, refer to Figure 7 As shown, the method for generating model prompt content provided in the embodiment of the present application also includes the following steps: S71. Receive an update instruction from an external tool for the target question-answering model.

[0146] In some cases, as user needs diversify and scenarios expand, existing external tools may not be able to cover new functional requirements. By adding new external tools, we can supplement the target question-answering model's capabilities in specific areas (such as adding professional data queries and specific task processing), allowing the model to handle more types of user questions.

[0147] It is also possible that some of the original external tools may have problems with high calling costs (such as taking too long, consuming a lot of resources) or redundant functions. By deleting such tools, unnecessary resource usage can be reduced, the overall tool calling efficiency can be improved, and the response speed of the model can be avoided from being affected by inefficient tools.

[0148] S72: When the update instruction is to add a new external tool, a new external tool function relationship diagram is generated based on the functions corresponding to the multiple external tools.

[0149] Furthermore, when the update instruction is to add a new external tool, the newly added external tool must be included in the overall external tool collection. Afterwards, the functional description information of each tool, including the newly added tool, is re-extracted. Based on this information, the logical relationships between all tools are re-analyzed, ultimately generating a new external tool functional relationship diagram that includes the functional nodes corresponding to the newly added tool and related relationships.

[0150] S73: When the update instruction is to delete the external tool, obtain the identifier of the tool to be deleted, delete the corresponding external tool from the external tool function relationship diagram based on the identifier of the tool to be deleted, and generate a new external tool function relationship diagram.

[0151] Furthermore, when the update instruction is to delete an external tool, the tool identifier of the external tool to be deleted is first extracted from the instruction. Based on this identifier, the corresponding external tool function node is found in the existing external tool function relationship graph. This node and all logical associations between it and other nodes are removed from the graph, thereby generating a new external tool function relationship graph after the deletion operation.

[0152] Through the above steps, after receiving an update instruction, the corresponding operations are executed according to the instruction type. When adding a new tool, the relationship diagram is regenerated to incorporate the new tool's functions and associated logic. When deleting a tool, the corresponding nodes and associations are removed to prevent invalid information from being retained. This ensures that the external tool function relationship diagram remains accurate and valid, providing a reliable basis for subsequent step execution path planning based on this diagram, reducing path planning errors or invalid tool calls caused by lagging tool information, thereby improving the tool call efficiency and answer accuracy of the target question-answering model.

[0153] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method.

[0154] In some embodiments, reference Figure 8 As shown, an embodiment of the present application further provides a device 800 for generating model prompt content, comprising: An acquisition unit 810 is configured to acquire a plurality of external tools corresponding to a target question-answering model in a target application; the plurality of external tools are connected to the target question-answering model based on a model context protocol interface; A generating unit 820 is configured to generate an external tool function relationship graph according to the function descriptions corresponding to the plurality of external tools; the external tool function relationship graph is an undirected graph; the external tool function relationship graph includes logical relationships between function nodes corresponding to the plurality of external tools; The processing unit 830 is configured to receive a user question text and, based on a semantic parsing result corresponding to the user question text, obtain a plurality of steps for answering the user question text; The determination unit 840 is used to determine the optimal step execution path based on the multiple steps and the external tool function relationship diagram, and generate prompt content for prompting the target question-answering model according to the optimal step execution path; the optimal step execution path includes the multiple steps and their corresponding function nodes.

[0155] As an optional implementation of the embodiment of the present disclosure, the determination unit 840 is specifically used to generate a step execution path diagram based on the multiple steps; the step execution path diagram is a directed graph; the step execution path diagram includes the logical relationship between the step nodes corresponding to the multiple steps; obtain the step node set in the step execution path diagram; the step node set includes the step nodes that have a matching relationship with the function nodes in the external tool function relationship diagram; determine the start and end step nodes of the target path based on the step node set and the step execution path diagram; generate the optimal step execution path based on the start and end step nodes of the target path, the step node set and the external tool function relationship diagram.

[0156] As an optional implementation of the embodiment of the present disclosure, the determination unit 840 is specifically used to obtain a first step execution path when there is no path branch in the step execution path graph; the first step execution path is the path containing the most nodes in the step node set in the step execution path graph; based on the start and end steps of the first step execution path, obtain the start and end step nodes of the target path.

[0157] As an optional implementation of the embodiment of the present disclosure, the determination unit 840 is specifically used to obtain the second step execution path corresponding to the target path branch for each target path branch when there is a target path branch in the step execution path diagram; the target path branch is a path branch including at least two step nodes in the step node set; the second step execution path is the path branch containing the largest number of step nodes in the step node set; based on the path start and end steps of multiple second step execution paths, obtain multiple target path start and end step nodes.

[0158] As an optional implementation of the embodiment of the present disclosure, the determination unit 840 is specifically used to determine the target start and end function nodes that match the start and end step nodes of the target path from the external tool function relationship diagram when the number of the start and end step nodes of the target path is equal to a pair; and generate the optimal step execution path based on the external tool function relationship diagram in combination with the target start and end function nodes and the step node set.

[0159] As an optional implementation of the embodiment of the present disclosure, the determination unit 840 is specifically used to determine, from the external tool function relationship diagram, a plurality of target start and end function nodes that match the plurality of target path start and end step nodes when the number of the target path start and end step nodes is greater than one pair; determine a plurality of third step execution paths based on the external tool function relationship diagram in combination with the plurality of target start and end function nodes and the step node set; obtain the number of target step nodes corresponding to the plurality of third step execution paths; the target step node number is the number of nodes that match the third step execution path with the step nodes in the step node set; and use the third step execution path with the largest number of target step nodes as the optimal step execution path.

[0160] As an optional implementation of the embodiment of the present disclosure, the determination unit 840 is also used to obtain corresponding resource consumption evaluation results for the third step execution paths with the same number of target step nodes when there are multiple third step execution paths with the same number of target step nodes; and determine the optimal step execution path based on the resource consumption evaluation results.

[0161] As an optional implementation of the embodiment of the present disclosure, the determination unit 840 is also used to obtain, for the third step execution path with the same number of target step nodes, resource consumption scores corresponding to multiple external tools in the third step execution path; and obtain resource consumption evaluation results corresponding to the third step execution path based on the resource consumption scores corresponding to the multiple external tools corresponding to the third step execution path.

[0162] As an optional implementation of the embodiment of the present disclosure, the determination unit 840 is further used to calculate the semantic relevance between each step in the step execution path diagram and each external tool function in the external tool function relationship diagram to obtain a semantic relevance value; and generate the step node set based on the semantic relevance value.

[0163] As an optional implementation of the embodiment of the present disclosure, the generating unit 820 is further configured to traverse the plurality of external tools, extract functional description information corresponding to each external tool, and generate the external tool functional relationship diagram based on the functional description information corresponding to each external tool.

[0164] As an optional implementation of the embodiment of the present disclosure, the processing unit 830 is also used to receive an update instruction for the external tool for the target question and answer model; when the update instruction is to add a new external tool, a new external tool function relationship diagram is regenerated based on the functions corresponding to the multiple external tools; when the update instruction is to delete the external tool, the tool identifier to be deleted is obtained, and the corresponding external tool is deleted from the external tool function relationship diagram based on the tool identifier to be deleted, and a new external tool function relationship diagram is generated.

[0165] For the description of the features in the embodiment corresponding to the device for generating model prompt content, please refer to the relevant description of the embodiment corresponding to the method for generating model prompt content, which will not be repeated here.

[0166] An embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any of the above-mentioned embodiments of the method for generating model prompt content.

[0167] An embodiment of the present application also provides a computer-readable storage medium, which stores a computer program, wherein the computer program is configured to execute the steps of any of the above-mentioned embodiments of the method for generating model prompt content or the steps of any of the above-mentioned methods for generating model prompt content when running.

[0168] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.

[0169] An embodiment of the present application further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the steps in any of the above-mentioned embodiments of the method for generating model prompt content or the steps in any of the above-mentioned methods for generating model prompt content.

[0170] An embodiment of the present application also provides another computer program product, including a non-volatile computer-readable storage medium, the non-volatile computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, implementing the steps in any of the above-mentioned embodiments of the method for generating model prompt content or the steps in any of the above-mentioned methods for generating model prompt content.

[0171] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0172] The above is a detailed introduction to a method and device for generating model prompt content provided by this application. This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to this application, and these improvements and modifications also fall within the scope of protection of the claims of this application.

Claims

1. A method for generating model prompt content, characterized in that: include: Obtain multiple external tools corresponding to the target question-answering model in the target application; The multiple external tools are connected to the target question-answering model based on a model context protocol interface; Generate an external tool function relationship graph based on the function descriptions corresponding to the plurality of external tools; the external tool function relationship graph is an undirected graph; the external tool function relationship graph includes logical relationships between function nodes corresponding to the plurality of external tools; Receive a user question text, and based on the semantic analysis result corresponding to the user question text, obtain multiple steps for answering the user question text; Based on the relationship diagram between the multiple steps and the external tool functions, the optimal step execution path is determined, and prompt content for prompting the target question-answering model is generated according to the optimal step execution path; the optimal step execution path includes the multiple steps and their corresponding functional nodes.

2. The method according to claim 1, characterized in that The determining of the optimal step execution path based on the relationship diagram between the multiple steps and the external tool functions includes: Generate a step execution path graph based on the multiple steps; the step execution path graph is a directed graph; the step execution path graph includes logical relationships between step nodes corresponding to the multiple steps; Acquire a step node set in the step execution path diagram; the step node set includes the step nodes that have a matching relationship with the function nodes in the external tool function relationship diagram; Determine the starting and ending step nodes of the target path according to the step node set and the step execution path graph; The optimal step execution path is generated based on the target path start and end step nodes, the step node set and the external tool function relationship diagram.

3. The method according to claim 2, characterized in that Determining the start and end step nodes of the target path according to the step node set and the step execution path graph includes: When there is no path branch in the step execution path graph, obtaining a first step execution path; the first step execution path is the path containing the most nodes in the step node set in the step execution path graph; Based on the start and end steps of the first step execution path, the start and end step nodes of the target path are obtained.

4. The method according to claim 2, characterized in that Determining the start and end step nodes of the target path according to the step node set and the step execution path graph includes: When a target path branch exists in the step execution path graph, for each target path branch, obtaining a second step execution path corresponding to the target path branch; the target path branch is a path branch including at least two step nodes in the step node set; the second step execution path is a path in the path branch that includes the largest number of step nodes in the step node set; Based on the path start and end steps of a plurality of the second step execution paths, a plurality of the target path start and end step nodes are obtained.

5. The method according to claim 2, characterized in that The generating the optimal step execution path based on the target path start and end step nodes, the step node set, and the external tool function relationship diagram includes: When the number of the target path start and end step nodes is equal to one pair, determining the target start and end function nodes that match the target path start and end step nodes from the external tool function relationship graph; The optimal step execution path is generated based on the external tool function relationship diagram in combination with the target start and end function nodes and the step node set.

6. The method according to claim 2, characterized in that The generating the optimal step execution path based on the target path start and end step nodes, the step node set, and the external tool function relationship diagram includes: When the number of the target path start and end step nodes is greater than one pair, determining a plurality of target start and end function nodes matching the plurality of target path start and end step nodes from the external tool function relationship graph; Determining a plurality of third step execution paths based on the external tool function relationship diagram in combination with the plurality of target start and end function nodes and the step node set; Obtaining a plurality of target step node numbers corresponding to the third step execution paths; the target step node number is the number of nodes where the third step execution paths match the step nodes in the step node set; The third step execution path with the largest number of target step nodes is used as the optimal step execution path.

7. The method according to claim 6, characterized in that The method further comprises: When there are multiple third step execution paths with the same number of target step nodes, obtaining corresponding resource consumption evaluation results for the third step execution paths with the same number of target step nodes; The optimal step execution path is determined according to the resource consumption evaluation result.

8. The method according to claim 7, characterized in that Obtaining the corresponding resource consumption evaluation result for the third step execution path having the same number of target step nodes includes: For the third step execution path having the same number of target step nodes, obtaining resource consumption scores corresponding to the corresponding external tools in the third step execution path; According to the resource consumption scores corresponding to the multiple external tools corresponding to the execution path of the third step, a resource consumption evaluation result corresponding to the execution path of the third step is obtained.

9. The method according to claim 2, characterized in that The step node set in the step execution path graph is obtained, including: Calculating semantic relevance between each step in the step execution path diagram and each external tool function in the external tool function relationship diagram to obtain a semantic relevance value; The step node set is generated based on the semantic related value.

10. The method according to claim 1, characterized in that Generating a functional relationship diagram of the external tools according to the functional descriptions corresponding to the plurality of external tools includes: Traversing the plurality of external tools, and extracting function description information corresponding to each external tool; The external tool function relationship diagram is generated based on the function description information corresponding to each external tool.

11. The method according to claim 1, wherein The method further comprises: Receive update instructions from the external tool for the target question answering model; When the update instruction is to add a new external tool, a new external tool function relationship diagram is generated based on the functions corresponding to the multiple external tools; When the update instruction is to delete an external tool, the identifier of the tool to be deleted is obtained, and the corresponding external tool is deleted from the external tool function relationship diagram based on the identifier of the tool to be deleted, so as to generate a new external tool function relationship diagram.

12. A device for generating model prompt content, characterized in that: include: An acquisition unit, configured to acquire multiple external tools corresponding to a target question-answering model in a target application; The multiple external tools are connected to the target question-answering model based on a model context protocol interface; A generating unit is configured to generate an external tool function relationship graph according to the function descriptions corresponding to the plurality of external tools; the external tool function relationship graph is an undirected graph; the external tool function relationship graph includes logical relationships between function nodes corresponding to the plurality of external tools; a processing unit, configured to receive a user question text and, based on a semantic parsing result corresponding to the user question text, obtain a plurality of steps for answering the user question text; A determination unit is used to determine the optimal step execution path based on the multiple steps and the external tool function relationship diagram, and generate prompt content for prompting the target question-answering model according to the optimal step execution path; the optimal step execution path includes the multiple steps and their corresponding functional nodes.

13. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the method for generating model prompt content according to any one of claims 1 to 11 when executing the computer program.

14. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the method for generating model prompt content according to any one of claims 1 to 11 is implemented.

15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the method for generating model prompt content according to any one of claims 1 to 11 is implemented.

Citation Information

Patent Citations

  • Intelligent customer service question answering method and device, computer equipment and storage medium

    CN119338009A

  • Intelligent agent-based data processing method and device, electronic equipment and storage medium

    CN119940552A

  • Tool calling execution method and device for large model

    CN120011053A

  • Task planning method and device for large language model, storage medium and equipment

    CN120179816A