Large model task calling execution method and device based on knowledge graph
By building a knowledge graph and function registry, analyzing API information and dependencies, and generating and executing call chains, the problem that the large-model function calling mechanism is difficult to support multi-step call chains is solved, and efficient and stable function call management is achieved.
Patent Information
- Application Number
- CN202411434124.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-15
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2044-10-15
AI Technical Summary
The existing large-model function calling mechanism is difficult to support multi-step function calling chains, resulting in call failures, especially when there is a function dependency relationship.
By building a function registry and execution agent based on knowledge graph, obtaining API information to build a target knowledge graph, analyzing function dependencies, generating and executing call chains, ensuring the accuracy of function call order and dependencies.
It significantly improves the transparency and maintenance efficiency of dependencies, reduces development risks, improves system stability and call efficiency, supports dynamic registration and real-time adjustment, and ensures the accuracy and adaptability of call generation.
Smart Images

Figure CN118963869B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a method and device for calling and executing a large model task based on a knowledge graph. Background Art
[0002] The Large Language Model (LLM) function call mechanism is usually designed for a single function call, that is, the model generates a function and its parameters in one interaction. When a task requires multiple function calls or there are function dependencies, the native function call mechanism cannot directly support multi-step function call chains, resulting in call failures. Summary of the invention
[0003] The present disclosure provides a large model task calling and execution method and device based on knowledge graph to at least solve the above technical problems existing in the prior art.
[0004] According to a first aspect of the present application, a method for calling and executing a large model task based on a knowledge graph is provided, the method comprising:
[0005] Obtain API information, and construct a target knowledge graph using function information in the API information as nodes and call dependencies between functions as edges;
[0006] Construct a function registry based on the target knowledge graph; the function registry is used to manage API function information and calls;
[0007] Establishing an execution agent based on the target knowledge graph and the function registry; the execution agent is used to parse the function call generated by the large model;
[0008] Input the acquired target requirements and user requests into the large model for understanding and generating function calls;
[0009] The execution agent determines the target function and function call dependency based on the function call to generate a call chain, and executes the call chain to obtain a parsing result.
[0010] In one possible implementation, the target knowledge graph is constructed with the function information in the API information as nodes and the call dependency relationships between functions as edges, including:
[0011] Parsing the API document in the API information to obtain initial function information; the initial function information includes an initial function description and initial call dependency relationships between functions;
[0012] Importing the initial function information into a graph database to obtain an initial knowledge graph;
[0013] Using static code analysis method to find the source definition of the function in the initial knowledge graph and its source call dependency;
[0014] Inputting the source definition of the function into the large model to generate a test case;
[0015] Using the test case to test whether the function depends on other functions when executed, so as to verify whether the initial call dependency of the function is correct, and obtain the test result;
[0016] Adjusting the initial call dependency in the initial knowledge graph based on the test result;
[0017] The initial knowledge graph is updated using the adjusted call dependency to obtain a target knowledge graph.
[0018] In one possible implementation, the function information includes a function name, a function object, parameters, parameter types, and a function description; and constructing a function registry based on the target knowledge graph includes:
[0019] Constructing a function registry structure; the function registry structure is provided with a function object;
[0020] Loading the function information and the calling dependency relationship between functions in the target knowledge graph into the function registry structure to obtain a function registry;
[0021] When loading, the function name is mapped to a function object, and parameters, parameter types and function description are stored.
[0022] In one possible implementation, the step of inputting the acquired target requirements and user requests into the large model for understanding and generating function calls includes:
[0023] Generate a Promp text based on the description information of each function; the description information of each function includes function interface description, parameter format, example call, function purpose and input and output parameters;
[0024] The large model determines the target function according to the target requirements, user requests and Promp text, and generates a function call.
[0025] In one possible implementation, the execution agent determines the target function and the function call dependency relationship based on the function call to generate a call chain, including:
[0026] Parsing the function call to extract the target function name and parameters in the function call;
[0027] Verify whether the function name and parameters in the function call match the function and parameters in the function registry;
[0028] During matching, the target knowledge graph is queried based on the target function name and parameters to obtain the calling dependency of the target function and generate a calling chain; the calling chain reflects the function calling order.
[0029] In one possible implementation, querying the target knowledge graph to obtain the call dependency of the target function includes:
[0030] Querying all pre-dependent functions of the target function in the target knowledge graph;
[0031] Sort all the pre-dependent functions in order to form a call chain;
[0032] Detect whether there is a circular dependency in the call chain, and report an error and stop execution if there is;
[0033] Also includes:
[0034] Adjust call dependencies based on function execution results or context changes.
[0035] In one possible implementation, the call chain includes multiple ones; executing the call chain to obtain a parsing result includes at least one of the following:
[0036] Sorting the plurality of call chains, and executing the call chain that is ranked first to obtain a parsing result;
[0037] Execute the multiple call chains in sequence to obtain the parsing result of each call chain.
[0038] In one possible implementation, executing the call chain to obtain a parsing result includes:
[0039] Extract the execution result of each function; the execution result includes successful output and error output, and integrates all steps of the call chain to form a complete execution log;
[0040] Organize function calls, input parameters, execution results, and error messages into context data structures;
[0041] Formatting the data structure to obtain context data;
[0042] The context data is input into the large model to obtain the parsing result.
[0043] In one possible implementation, after receiving the function call, the executing agent further includes:
[0044] Verify whether the function name and parameters in the function call match the function and parameters in the function registry;
[0045] If they match, the target function and function call dependencies are determined to generate a call chain; otherwise, the error information is fed back to the large model.
[0046] In one possible implementation, it further includes:
[0047] Verify whether the functions and calling dependencies between functions in the target knowledge graph are completely created, and supplement them if the creation is not completed;
[0048] Verify whether the calling dependencies between functions in the target knowledge graph are correct, and make adjustments when exceptions occur to update the target knowledge graph.
[0049] According to a second aspect of the present application, a large model task calling and executing device based on a knowledge graph is provided, comprising:
[0050] An acquisition module is used to acquire API information, and construct a target knowledge graph using function information in the API information as nodes and call dependencies between functions as edges;
[0051] A construction module, used to construct a function registry based on the target knowledge graph; the function registry is used to manage API function information and calls;
[0052] A building module is used to build an execution agent based on the target knowledge graph and the function registry; the execution agent is used to parse the function call generated by the large model;
[0053] The parsing module is used to input the acquired target requirements and user requests into the large model for understanding and generating function calls;
[0054] An execution module is used for the execution agent to determine the target function and function call dependency based on the function call to generate a call chain, and execute the call chain to obtain a parsing result.
[0055] According to a third aspect of the present application, an electronic device is provided, including:
[0056] at least one processor; and
[0057] a memory communicatively connected to the at least one processor; wherein,
[0058] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method described in the present application.
[0059] According to a fourth aspect of the present application, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the method described in the present application.
[0060] According to a fifth aspect of the present application, a computer program product is provided, comprising a computer program or instructions, which implement the method described in the present application when executed by a processor.
[0061] By using the technical solution of this application, the transparency and maintenance efficiency of dependencies are improved by building a knowledge graph, which significantly reduces development risks and improves system stability. The centralized management and calling of API functions are realized through the function registry and execution agent, which supports dynamic registration and real-time adjustment of dependencies, avoids code redundancy and complex management, improves calling efficiency and system flexibility, and reduces maintenance workload. Finally, the combination of execution agent and large model ensures the accuracy and adaptability of call generation, significantly improving the processing capability and response speed of complex tasks.
[0062] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] By reading the detailed description below with reference to the accompanying drawings, the above and other purposes, features and advantages of the exemplary embodiments of the present application will become readily understood. In the accompanying drawings, several embodiments of the present application are shown in an exemplary and non-limiting manner, wherein:
[0064] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts.
[0065] FIG1 shows a schematic diagram of a first implementation flow of a large model task calling and executing method based on a knowledge graph in an embodiment of the present application;
[0066] FIG2 shows a schematic diagram of the structure of a large model task calling and executing device based on a knowledge graph in an embodiment of the present application;
[0067] FIG. 3 shows a schematic diagram of the structure of another electronic device in an embodiment of the present application. DETAILED DESCRIPTION
[0068] In order to make the purpose, features, and advantages of the present application more obvious and easy to understand, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0069] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0070] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0071] In the following description, the terms "first\second" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0072] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0073] It should be understood that in the various embodiments of the present application, the size of the serial number of each implementation process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0074] FIG1 shows a schematic diagram of a first implementation flow of a large model task call execution method based on a knowledge graph in an embodiment of the present application. As shown in FIG1 , the method includes:
[0075] S (Step) 101: Obtain API information, and construct a target knowledge graph using function information in the API information as nodes and call dependencies between functions as edges;
[0076] It is understandable that in this application, API information is obtained through the API system, wherein the API information can be an API document; this application extracts function information in the document by parsing the API document; wherein the function information includes function description, parameters, return value, and dependency clues between functions. It should be noted that the function information also includes parameters, for example, y=x+z, where y is a function, and x and z are parameters. Therefore, the nodes in this application include function nodes and parameter nodes, wherein the target knowledge graph includes function nodes and parameter nodes, function nodes include attributes such as function name, description, input parameters, and output results, and parameter nodes include attributes such as parameter name, type, and constraints. The target knowledge graph includes call dependencies and parameter relationships between functions, wherein the call dependency relationship represents the dependency between functions, and the parameter relationship represents the connection between function nodes and parameter nodes.
[0077] Exemplarily, after obtaining the API information, which includes the names, descriptions, input parameters, output results, dependencies, and other information of all API functions, the API information is structured and saved in formats such as JSON and YAML, and then a graph database is selected to import the API information into the graph database to generate nodes and relationships. The graph database may use a graph database such as Neo4j, which is not limited in this application.
[0078] S102: Building a function registry based on the target knowledge graph; the function registry is used to manage API function information and calls;
[0079] In this application, centralized management and calling of all API functions are achieved by building a function registry. It should be noted that the function registry includes function name, function object, input parameter type and description, etc. It is understandable that when the executing agent makes a function call, it is necessary to first determine whether the target function exists in the function registry. If it exists, the next step is performed to reduce useless execution operations.
[0080] S103: Establishing an execution agent based on the target knowledge graph and the function registry; the execution agent is used to parse the function call generated by the large model;
[0081] Specifically, in this application, an execution agent is established based on the target knowledge graph and function registry, that is, the execution agent can identify whether the target function exists in the function registry, and can call the calling dependency of the target function in the target knowledge graph.
[0082] S104: Input the acquired target requirements and user requests into the large model for understanding and generating function calls;
[0083] It is understandable that the target demand can be the number of function calls required by the user, and the large model can generate the corresponding number of function calls according to the user request. The large model provided in this application can intelligently parse user requests, generate accurate function calls, and ensure the accuracy and adaptability of call generation.
[0084] S105: The execution agent determines the target function and function call dependency based on the function call to generate a call chain, and executes the call chain to obtain a parsing result.
[0085] The execution agent in this application parses function calls, obtains the target function and function call dependencies, generates a call chain, and finally executes the call chain to obtain the parsing result.
[0086] The large model task call execution method based on the knowledge graph provided in the present application is to construct the target knowledge graph with the function information in the obtained API information as the node and the call dependency relationship between functions as the edge, and then construct the function registry according to the function in the target knowledge graph and the call dependency relationship between functions, and establish the corresponding execution agent on the basis of the target knowledge graph and the function registry, which can call the call dependency relationship between functions from the target knowledge graph when there is a function in the function registry; so that after the large model parses the user demand to obtain the function call, the execution agent determines the target function and the function call dependency relationship based on the function call to generate a call chain, and executes the call chain to obtain the parsing result. The present application improves the transparency and maintenance efficiency of the dependency relationship by constructing the knowledge graph, significantly reduces the development risk, and improves the system stability. The centralized management and call of API functions are realized through the function registry and the execution agent, supporting dynamic registration and real-time adjustment of dependencies, avoiding code redundancy and complex management, improving the call efficiency and system flexibility, and reducing the maintenance workload. Finally, the execution agent and the large model are combined to ensure the accuracy and adaptability of the call generation, and significantly improve the processing capacity and response speed of complex tasks.
[0087] In some embodiments, the target knowledge graph is constructed using the function information in the API information as nodes and the call dependency relationships between functions as edges, including:
[0088] Parsing the API document in the API information to obtain initial function information; the initial function information includes an initial function description and initial call dependency relationships between functions;
[0089] Importing the initial function information into a graph database to obtain an initial knowledge graph;
[0090] Using static code analysis method to find the source definition of the function in the initial knowledge graph and its source call dependency;
[0091] Inputting the source definition of the function into the large model to generate a test case;
[0092] Using the test case to test whether the function depends on other functions when executed, so as to verify whether the initial call dependency of the function is correct, and obtain the test result;
[0093] Adjusting the initial call dependency in the initial knowledge graph based on the test result;
[0094] The initial knowledge graph is updated using the adjusted call dependency to obtain a target knowledge graph.
[0095] Specifically, in this application, existing API document parsing tools can be used to read the initial function relationships in the API document, including functions, function annotations, parameter descriptions, and call dependency descriptions; it should be noted that this application can also use a large model to assist in parsing API documents. The large model can more accurately identify call dependencies, parse complex descriptions, or supplement potential dependencies.
[0096] After obtaining the initial function information, import it into the graph database to obtain the initial knowledge graph, and then analyze the source code of the function in the initial knowledge graph through static code analysis to find the function definition and its calling situation, and then identify complex functions or framework calls through a large language model, identify the actual calling relationship between functions, and supplement the information in the document; wherein, the static code analysis method in this application can use an abstract syntax tree. Generate a test case based on the source definition of the function through a large language model. The test case is used to verify whether the calling dependency between the identified functions is correct or to verify whether the execution of the function depends on other functions. Specifically, in this application, the generated test case is converted into real executable code, and verified through a test framework to obtain the test results. Adjust the dependencies in the knowledge graph according to the test results to ensure that it reflects the actual situation, and then integrate the information of document parsing, source code analysis, and test verification to form a complete dependency list. Update the initial knowledge graph based on the dependency list, and rebuild the function nodes and dependencies.
[0097] In some embodiments, after constructing the target knowledge graph, the following steps are further included:
[0098] Verify whether the functions and calling dependencies between functions in the target knowledge graph are completely created, and supplement them if the creation is not completed;
[0099] Verify whether the calling dependencies between functions in the target knowledge graph are correct, and make adjustments when exceptions occur to update the target knowledge graph.
[0100] It is understandable that after the target knowledge graph is built, it is also necessary to perform an integrity check on the target knowledge graph to ensure that all functions and relationships have been created correctly; as well as a consistency check to verify the dependencies of the functions and avoid problems such as circular dependencies.
[0101] This application systematically manages the dependencies between API functions by building a knowledge graph, and verifies the accuracy of dependencies by combining API document parsing, source code static analysis, and large model test case generation, and supports real-time updates. This improves the transparency and maintenance efficiency of dependencies, significantly reduces development risks, and improves system stability.
[0102] In some embodiments, the function information includes a function name, a function object, parameters, parameter types, and a function description; and constructing a function registry based on the target knowledge graph includes:
[0103] Constructing a function registry structure; the function registry structure is provided with a function object;
[0104] Loading the function information and the calling dependency relationship between functions in the target knowledge graph into the function registry structure to obtain a function registry;
[0105] When loading, the function name is mapped to a function object, and parameters, parameter types and function description are stored.
[0106] Specifically, the function information in this application includes function name, function object, parameters, parameter type and function description, etc., and may also include other function-related information, which will not be repeated in this application.
[0107] First, define the function registry structure, specifically using Python's dictionary or JSON format to map function names to function objects and store other related information, such as parameter types and function descriptions. Then, when the API system starts, initialize the function registry and load all API function information. You can put the registry data into a configuration file (such as JSON, YAML) and load it when the system starts, or hard-code it directly in the program to get the function registry.
[0108] It should be noted that the function registry provided by this application also supports dynamic registration of new functions, which allows new functions to be added to the registry at runtime.
[0109] The function registry provided by this application realizes the centralized management and calling of all API functions, can efficiently manage the calling logic and dependencies of API functions, and ensure the correctness and maintainability of function calls. It should be noted that the function registry only manages the functions and function relationship descriptions, and cannot be called directly.
[0110] In some embodiments, the step of inputting the acquired target requirements and user requests into a large model for understanding and generating function calls includes:
[0111] Generate a Promp text based on the description information of each function; the description information of each function includes function interface description, parameter format, example call, function purpose and input and output parameters;
[0112] The large model determines the target function according to the target requirements, user requests and Promp text, and generates a function call.
[0113] It should be noted that this application first configures a large model with code generation and function call functions, and optimizes the function call function of the large model.
[0114] First, select a large model, which can be OpenAI's GPT-4, etc., to ensure that the model has the ability to understand API documents and code structures. This application is not limited here. Configure the calling parameters of the large model. The calling model includes API keys, control of generation diversity (such as temperature), maximum output length, etc., to ensure that the model generates accurate and concise function calls Function Call. In this application, the Promp text generated with function interface descriptions, parameter formats, example calls, etc. is also input into the large model to provide sufficient context information to the large model to help the model generate calls that meet the target requirements and user demand expectations. Describe the purpose of each function, input and output parameter definitions and other information in detail in the Promp text, extract them from API documents, knowledge graphs or function registries, and help LLM generate correct calls. The example calls and input and output parameter definitions in this application can help the model understand the task, provide examples of multiple requests and corresponding function calls Function Call, and enhance the generation ability of the model. In addition, the large model also sets the output format, which can be JSON, to ensure that the function call Function Call generated by the model has a clear structure and is easy to parse, which is convenient for subsequent execution and verification.
[0115] In some embodiments, the execution agent determines the target function and the function call dependency relationship based on the function call to generate a call chain, including:
[0116] Parsing the function call to extract the target function name and parameters in the function call;
[0117] Verify whether the function name and parameters in the function call match the function and parameters in the function registry;
[0118] During matching, the target knowledge graph is queried based on the target function name and parameters to obtain the calling dependency of the target function and generate a calling chain; the calling chain reflects the function calling order.
[0119] It is understandable that in this application, the large model and the execution agent are seamlessly connected, the execution agent receives the function call generated by the large model, and executes the function call to complete the task. Specifically, the execution agent parses the function name and parameters from the structured data function call output by the large model to prepare for subsequent parameter verification and dependency parsing. Then first verify in the function registry whether the target function and parameters exist. If they exist, query the knowledge graph, obtain the dependency relationship of the target function, and generate a call chain. After the execution agent receives the function call, the application must first verify the function call Function Call generated by the large model LLM to ensure that the function name and parameters correctly match the definition in the registry, and promptly feedback the error information. When the function call Function Call format is incorrect or lacks key fields, the parser reports an error and returns a friendly error message to prevent abnormalities in subsequent steps.
[0120] In addition, the executing agent adjusts parameters as needed during the execution process, such as obtaining default values or modifying inputs through the knowledge graph to optimize the function call effect. In this way, through testing and optimization, the accuracy of LLM-generated function calls Function Call is improved to ensure the overall response quality and stability of the system. After generating a large model, this application can also simulate a variety of user request scenarios to test the Function Call generation performance of LLM to ensure that the calls generated in different situations are correct and reasonable. Collect test results and user feedback, continuously adjust Prompt and model parameters, improve generation effects, and solve common error patterns. Debug the interaction of function calls between the large model and the executing agent to ensure that the function call FunctionCall can be correctly parsed and executed, perform special tests on edge cases, and improve system robustness.
[0121] The large model provided by this application can also ensure that the system has security protection when calling external APIs or performing sensitive operations to prevent accidental or malicious calls. The large model provided by this application is equipped with a function call whitelist, which sets a whitelist of functions allowed to be called, limited to explicitly approved functions and interfaces, to prevent unauthorized calls. The large model provided by this application can also add permission verification to function calls involving sensitive operations, and record logs for each call for auditing and security monitoring. The large model provided by this application can also check the function calls generated by the large model LLM through a content filtering mechanism to prevent injection attacks, data leakage and other security risks.
[0122] In some embodiments, querying the target knowledge graph to obtain the call dependency of the target function includes:
[0123] Querying all pre-dependent functions of the target function in the target knowledge graph;
[0124] Sort all the pre-dependent functions in order to form a call chain;
[0125] Detect whether there is a circular dependency in the call chain, and report an error and stop execution if there is;
[0126] Also includes:
[0127] Adjust call dependencies based on function execution results or context changes.
[0128] Specifically, in the present application, the execution agent is provided with a function call parser, a dependency parser, a parameter validator, a function executor and a result processor.
[0129] Among them, the function call parser is used to parse the function call Function Call generated by the large model LLM, as follows:
[0130] Extract the function name and parameters from it to prepare for subsequent parameter verification and dependency resolution.
[0131] Parse the structured data of the function call: extract the function name and parameters to match the definition in the registry and ensure that the called function exists.
[0132] Function name and parameter extraction: The function name extracted from the function call is used to match the function definition in the registry, and the parameters are passed to the parameter validator for validation.
[0133] Error handling: When the function call format is incorrect or key fields are missing, the parser reports an error and returns a friendly error message to prevent exceptions in subsequent steps.
[0134] The dependency parser of the execution agent of this application is used to query the knowledge graph to determine the dependency relationship of the target function, generate a complete call chain, and ensure that the functions are executed in the correct order. Specifically, it includes:
[0135] Dependency query: Query all the predecessor dependency functions of the target function in the knowledge graph, and use recursive query to ensure completeness.
[0136] Call chain generation: Arrange dependent functions in order to form a call chain, ensuring that the predecessor function is executed before the successor function.
[0137] Detect circular dependencies: Detect whether there are circular dependencies in the call chain, report errors in time and stop execution when problems are found.
[0138] Dynamic dependency processing: supports adjusting dependencies at runtime and adjusting the calling order according to function execution results or context changes.
[0139] The parameter validator in the execution agent of this application is used to verify the parameters extracted from the function call to ensure that they meet the definition requirements of the function, including parameter name, type, necessity, etc.
[0140] Parameter matching and checking: Checks whether parameter names and types match the definitions in the function registry, and verifies whether all required parameters are provided.
[0141] Parameter type validation: Ensure that parameter values conform to expected types and further check the internal structure and type consistency of complex types.
[0142] Default value processing: Supplement default values for non-required parameters that are not provided to ensure that the parameters required for function execution are complete.
[0143] Parameter exception handling: If parameter validation fails, throw an error and provide detailed instructions to help the user or system adjust the input.
[0144] In this application, the function executor is used to execute the functions in the call chain in sequence, manage parameter passing, result processing and exception capture. The details are as follows:
[0145] Execute the call chain in order: Execute each function in the call chain one by one, ensuring that they are executed in the order of dependencies.
[0146] Manage parameter passing: Update the parameter dictionary after a function is executed to ensure that the output of the previous function is correctly passed to the next function.
[0147] Exception handling and retry mechanism: Capture exceptions during execution and decide to retry, skip, or terminate the call chain based on the exception type.
[0148] Execution timeout management: Set the execution timeout to prevent long-term operation from affecting system performance. In the event of a timeout, the execution will be terminated and the error will be recorded.
[0149] In some embodiments, the call chain includes multiple ones; executing the call chain to obtain a parsing result includes at least one of the following:
[0150] Sorting the plurality of call chains, and executing the call chain that is ranked first to obtain a parsing result;
[0151] Execute the multiple call chains in sequence to obtain the parsing result of each call chain.
[0152] The executing the call chain to obtain the parsing result includes:
[0153] Extract the execution result of each function; the execution result includes successful output and error output, and integrates all steps of the call chain to form a complete execution log;
[0154] Organize function calls, input parameters, execution results, and error messages into context data structures;
[0155] Formatting the data structure to obtain context data;
[0156] The context data is input into the large model to obtain the parsing result.
[0157] Specifically, in the present application, a result processor is provided in the execution agent to uniformly manage the execution results of the function, including storage, transmission, formatting and output. The details are as follows:
[0158] Result storage: Store the execution results of the function in the result dictionary for subsequent use or debugging analysis.
[0159] Formatting and output processing: Format the results into an understandable output format and optimize the display of the final results of the multi-step call chain.
[0160] Feedback to the big model: The execution results are passed to the big model, which generates natural language responses or further processes them.
[0161] It should be noted that the execution agent provided by this application can also comprehensively manage abnormal situations in the system and record the execution process through logs to provide a basis for system maintenance and optimization.
[0162] Error classification and processing: Errors are classified and processed according to their severity, and different response strategies are adopted, such as warning, retry or abort execution.
[0163] Logging: Record detailed information of each function call, including time, parameters, results, and status, to facilitate analysis and debugging.
[0164] Audit and security monitoring: Audit calls involving sensitive operations to ensure legality and security, and regularly review logs to monitor potential risks.
[0165] In this application, the execution results are finally input into the big model, which converts the results of the function execution into natural language responses that users can understand. The output of the function execution results is sorted and fed back to the user to ensure the accuracy, readability and effectiveness of the information.
[0166] Specifically, this application summarizes all the results during the function execution process and constructs them into a context for the large model LLM to generate natural language replies. Among them, the context includes key data such as the executed function, parameters, results, error information, etc. Specifically, the results of each function execution are first extracted from the result processor, including successful output and error information, and all steps of the call chain are integrated to form a complete execution log. Then organize the context structure, specifically to organize information such as function calls, input parameters, execution results, errors and exceptions into an easy-to-understand structure, avoid technical descriptions, and ensure that the content is clear. Format the context data to make it easy to understand, such as converting complex data structures into concise descriptions or tabular forms. Finally, the natural language generation capabilities of the large language model LLM are used to generate concise and accurate reply texts based on the constructed context, and handle exceptions or error feedback during execution.
[0167] It should be noted that the natural language generation capability of the large model in this application is formed through Prompt design. First, a Prompt template suitable for generating replies is designed to guide the large language model LLM to generate user-friendly replies based on the context, including task descriptions, execution results, and error descriptions. This application passes the constructed context to LLM and uses the preset Prompt to guide the model to generate structured natural language output. This application designs a variety of Prompt strategies for different types of task results (such as success, partial success, and failure) to ensure that the replies can accurately reflect the execution status. This application also post-processes the replies generated by LLM to correct grammar and optimize wording to ensure that the replies comply with grammatical specifications and are coherent.
[0168] As an embodiment, after establishing an execution agent with a knowledge graph and a function registry, the present application uses a large model to parse user needs and obtain function calls corresponding to the user needs. The execution agent searches the function registry for the target function substituted by the function based on the function call. If it exists, the calling relationship of the target function is identified from the knowledge graph to generate a call chain, execute the call chain to obtain an execution result, and input the execution result into the large model to obtain an output of the parsed result of the user need.
[0169] The large model task calling and executing method based on knowledge graph provided in this application has the following beneficial effects:
[0170] By building a knowledge graph, the dependencies between API functions are managed, and the accuracy of the dependencies is verified by combining API document parsing, source code static analysis, automatic generation of test cases, and other methods. It also supports real-time updates, improves the transparency and maintenance efficiency of the dependencies, significantly reduces development risks, and improves system stability.
[0171] Through a unified function registry and execution agent, centralized management and calling of API functions are achieved, supporting dynamic registration and real-time adjustment of dependencies, avoiding code redundancy and complex management, improving calling efficiency and system flexibility, and reducing maintenance workload.
[0172] This application combines a large language model and an execution agent, uses the large language model to intelligently parse user requests and automatically generate accurate function calls. It combines prompt optimization and multiple rounds of feedback to ensure the accuracy and adaptability of large language model call generation, significantly improving the processing capabilities of complex tasks and the response speed of the system.
[0173] As shown in FIG2 , an embodiment of the present application provides a large model task calling and executing device based on a knowledge graph, the device comprising:
[0174] An acquisition module 201 is used to acquire API information, and construct a target knowledge graph using function information in the API information as nodes and call dependencies between functions as edges;
[0175] A construction module 202 is used to construct a function registry based on the target knowledge graph; the function registry is used to manage API function information and calls;
[0176] Establishing module 203, used to establish an execution agent based on the target knowledge graph and function registry; the execution agent is used to parse the function call generated by the large model;
[0177] The parsing module 204 is used to input the acquired target requirements and user requests into the large model for understanding and generating function calls;
[0178] The execution module 205 is used for the execution agent to determine the target function and the function call dependency based on the function call to generate a call chain, and execute the call chain to obtain the parsing result.
[0179] The working principle of the large model task call execution device based on the knowledge graph provided in the present application is as follows: the acquisition module 201 acquires API information, and constructs the target knowledge graph with the function information in the API information as nodes and the call dependency relationship between functions as edges; the construction module 202 constructs a function registry based on the target knowledge graph; the function registry is used to manage API function information and calls; the establishment module 203 establishes an execution agent based on the target knowledge graph and the function registry; the execution agent is used to parse the function calls generated by the large model; the parsing module 204 inputs the acquired target requirements and user requests into the large model for understanding and generates function calls; the execution module 205 executes the agent to determine the target function and the function call dependency based on the function call to generate a call chain, and executes the call chain to obtain the parsing result.
[0180] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.
[0181] The electronic device includes at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the large model task call execution method based on the knowledge graph described in the present application. The computer instructions are used to enable the computer to execute the large model task call execution method based on the knowledge graph described in the present application.
[0182] The present application also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the knowledge graph-based large model task call execution method of the present application.
[0183] Fig. 3 shows a schematic block diagram of an example electronic device 300 that can be used to implement an embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples, and are not intended to limit the implementation of the present application described herein and / or required.
[0184] As shown in FIG3 , the device 300 includes a computing unit 301, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 302 or a computer program loaded from a storage unit 308 into a random access memory (RAM) 303. In the RAM 303, various programs and data required for the operation of the device 300 can also be stored. The computing unit 301, the ROM 302, and the RAM 303 are connected to each other via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.
[0185] A number of components in the device 300 are connected to the I / O interface 305, including: an input unit 306, such as a keyboard, a mouse, etc.; an output unit 307, such as various types of displays, speakers, etc.; a storage unit 308, such as a disk, an optical disk, etc.; and a communication unit 309, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 309 allows the device 300 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0186] The computing unit 301 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 301 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 301 performs the various methods and processes described above, such as a large model task call execution method based on a knowledge graph. For example, in some embodiments, a large model task call execution method based on a knowledge graph may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 308. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 300 via the ROM 302 and / or the communication unit 309. When the computer program is loaded into the RAM 303 and executed by the computing unit 301, one or more steps of the large model task call execution method based on the knowledge graph described above may be executed. Alternatively, in other embodiments, the computing unit 301 may be configured to execute a knowledge graph-based large model task call execution method in any other appropriate manner (for example, by means of firmware).
[0187] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0188] The program code for implementing the method of the present application can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, implements the functions / operations specified in the flow chart and / or block diagram. The program code can be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0189] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0190] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0191] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0192] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0193] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A large model task calling and execution method based on knowledge graph, characterized in that: The method comprises: Obtain API information, and construct a target knowledge graph using function information in the API information as nodes and call dependencies between functions as edges; Construct a function registry based on the target knowledge graph; the function registry is used to manage API function information and calls; Establishing an execution agent based on the target knowledge graph and the function registry; the execution agent is used to parse the function call generated by the large model; Input the acquired target requirements and user requests into the large model for understanding and generating function calls; The execution agent determines the target function and the function call dependency based on the function call to generate a call chain, and executes the call chain to obtain a parsing result; The target knowledge graph is constructed by using the function information in the API information as nodes and the calling dependency relationships between functions as edges, including: Parsing the API document in the API information to obtain initial function information; the initial function information includes an initial function description and initial call dependency relationships between functions; Importing the initial function information into a graph database to obtain an initial knowledge graph; Using static code analysis method to find the source definition of the function in the initial knowledge graph and its source call dependency; Inputting the source definition of the function into the large model to generate a test case; Using the test case to test whether the function depends on other functions when executed, so as to verify whether the initial call dependency of the function is correct, and obtain the test result; Adjusting the initial call dependency in the initial knowledge graph based on the test result; The initial knowledge graph is updated using the adjusted call dependency to obtain a target knowledge graph.
2. The method according to claim 1, characterized in that The function information includes function name, function object, parameters, parameter type and function description; the function registry is constructed based on the target knowledge graph, including: Constructing a function registry structure; the function registry structure is provided with a function object; Loading the function information and the calling dependency relationship between functions in the target knowledge graph into the function registry structure to obtain a function registry; When loading, the function name is mapped to a function object, and parameters, parameter types and function description are stored.
3. The method according to claim 2, characterized in that The target requirements and user requests are input into the large model for understanding and generating function calls, including: Generate a Promp text based on the description information of each function; the description information of each function includes function interface description, parameter format, example call, function purpose and input and output parameters; The large model determines the target function according to the target requirements, user requests and Promp text, and generates a function call.
4. The method according to claim 3, characterized in that The execution agent determines the target function based on the function call and generates a call chain based on the function call dependency, including: Parsing the function call to extract the target function name and parameters in the function call; Verify whether the function name and parameters in the function call match the function and parameters in the function registry; During matching, the target knowledge graph is queried based on the target function name and parameters to obtain the calling dependency of the target function and generate a calling chain; the calling chain reflects the function calling order.
5. The method according to claim 4, characterized in that The querying the target knowledge graph to obtain the calling dependency of the target function includes: Querying all pre-dependent functions of the target function in the target knowledge graph; Sort all the pre-dependent functions in order to form a call chain; Detect whether there is a circular dependency in the call chain, and report an error and stop execution if there is; Also includes: Adjust call dependencies based on function execution results or context changes.
6. The method according to claim 1, characterized in that The call chain includes multiple ones; executing the call chain to obtain a parsing result includes at least one of the following: Sorting the plurality of call chains, and executing the call chain that is ranked first to obtain a parsing result; Execute the multiple call chains in sequence to obtain the parsing result of each call chain.
7. The method according to claim 6, characterized in that The executing the call chain to obtain a parsing result includes: Extract the execution result of each function; the execution result includes successful output and error output, and integrates all steps of the call chain to form a complete execution log; Organize function calls, input parameters, execution results, and error messages into context data structures; Formatting the data structure to obtain context data; The context data is input into the large model to obtain the parsing result.
8. The method according to claim 1, characterized in that After building the target knowledge graph, it also includes: Verify whether the functions and calling dependencies between functions in the target knowledge graph are completely created, and supplement them if the creation is not completed; Verify whether the calling dependencies between functions in the target knowledge graph are correct, and make adjustments when exceptions occur to update the target knowledge graph.
9. A large model task calling and executing device based on knowledge graph, characterized in that: The device comprises: An acquisition module is used to acquire API information, and construct a target knowledge graph using function information in the API information as nodes and call dependencies between functions as edges; A construction module, used to construct a function registry based on the target knowledge graph; the function registry is used to manage API function information and calls; A building module is used to build an execution agent based on the target knowledge graph and the function registry; the execution agent is used to parse the function call generated by the large model; The parsing module is used to input the acquired target requirements and user requests into the large model for understanding and generating function calls; An execution module, used for the execution agent to determine the target function and the function call dependency based on the function call to generate a call chain, and execute the call chain to obtain a parsing result; The target knowledge graph is constructed by using the function information in the API information as nodes and the calling dependency relationships between functions as edges, including: Parsing the API document in the API information to obtain initial function information; the initial function information includes an initial function description and initial call dependency relationships between functions; Importing the initial function information into a graph database to obtain an initial knowledge graph; Using static code analysis method to find the source definition of the function in the initial knowledge graph and its source call dependency; Inputting the source definition of the function into the large model to generate a test case; Using the test case to test whether the function depends on other functions when executed, so as to verify whether the initial call dependency of the function is correct, and obtain the test result; Adjusting the initial call dependency in the initial knowledge graph based on the test result; The initial knowledge graph is updated using the adjusted call dependency to obtain a target knowledge graph.
Citation Information
Patent Citations
Knowledge graph construction method and knowledge graph application method
CN118069856A
System and method for long-distance calling communication assembly
CN1848774A
