Knowledge graph-based large model task calling execution method and device
By building a knowledge graph and function registry, analyzing API information and dependencies, generating and executing call chains, the problem that the large-model function calling mechanism is difficult to support multi-step call chains is solved, the system stability and efficiency are improved, and the development risks are reduced .
Patent Information
- Application Number
- CN202411434124.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-15
- Publication Date
- 2024-11-15
- 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 generate target knowledge graphs, analyzing function call dependencies, generating and executing call chains, ensuring the accuracy of call order and dependencies.
It improves system stability and call efficiency, reduces development risks, supports dynamic registration and real-time adjustment of dependencies, avoids code redundancy and complex management, and significantly improves the processing capability and response speed of complex tasks.
Smart Images

Figure CN118963869A_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 large-model tasks based on a knowledge graph. Background Art
[0002] The Large Language Model (LLM) function call mechanism is typically designed for single function calls, meaning the model generates a function and its parameters in a single interaction. When a task requires multiple function calls or involves 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 method and device for calling and executing large model tasks based on knowledge graphs 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 function registry; the execution agent is used to parse the function calls 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, constructing a target knowledge graph using function information in the API information as nodes and call dependencies between functions as edges includes:
[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 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 a 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 embodiment, 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; wherein 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] During loading, the function name is mapped to a function object, and parameters, parameter types, and function descriptions are stored.
[0022] In one possible implementation, inputting the acquired target requirements and user requests into the large model for understanding and generating function calls includes:
[0023] Generate a prompt 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 request and Promp text, and generates a function call.
[0025] In one embodiment, 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 call dependency of the target function and generate a call chain; the call chain reflects the function call order.
[0029] In one possible implementation, querying the target knowledge graph to obtain the call dependency relationship of the target function includes:
[0030] Querying all pre-dependent functions of the target function in the target knowledge graph;
[0031] Sort all 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 embodiment, the call chain includes multiple call chains; 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 embodiment, executing the call chain to obtain a parsing result includes:
[0039] Extract the results of each function execution; the execution results include successful output and error output, and integrate 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 embodiment, 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 there is a 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 embodiment, 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 complete;
[0048] Verify whether the calling dependencies between functions in the target knowledge graph are correct, and make adjustments when an exception occurs 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 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;
[0051] A construction module is used to build 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 function registry; the execution agent is used to parse the function calls 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. The instructions are executed by the at least one processor to enable the at least one processor to perform the method described in this 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] Utilizing the technical solution of this application, the transparency and maintenance efficiency of dependency relationships are improved by constructing a knowledge graph, significantly reducing development risks and improving system stability. Centralized management and invocation of API functions are achieved through a function registry and execution agent, supporting dynamic registration and real-time adjustment of dependencies. This avoids code redundancy and complex management, improves invocation efficiency and system flexibility, and reduces maintenance workload. Finally, the combination of execution agents and large models ensures the accuracy and adaptability of call generation, significantly improving the processing power 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] The above and other objects, features and advantages of the exemplary embodiments of the present application will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present application are shown in an exemplary and non-limiting manner, in which:
[0064] In the drawings, the same or corresponding reference numerals denote the same or corresponding parts.
[0065] FIG1 shows a schematic diagram of a first implementation flow of a method for calling and executing a large model task 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 call execution device based on a knowledge graph in an embodiment of the present application;
[0067] FIG3 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 this application more obvious and easy to understand, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making creative efforts shall fall within the scope of protection of this application.
[0069] In order to make the purpose, technical solutions and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this 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 describes 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 is understandable 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 commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only 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] Figure 1 shows a schematic diagram of the implementation process of the large model task call execution method based on the knowledge graph in an embodiment of the present application. As shown in Figure 1, 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 dependency relationships 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] For example, after obtaining API information, which includes the names, descriptions, input parameters, output results, and dependencies of all API functions, the API information is structured and saved in a format such as JSON or YAML. A graph database is then selected and imported into the database to generate nodes and relationships. The graph database may be a graph database such as Neo4j, but this application does not limit this.
[0078] S102: Constructing a function registry based on the target knowledge graph; the function registry is used to manage API function information and calls;
[0079] This application implements centralized management and access to all API functions by constructing a function registry. It should be noted that the function registry includes the function name, function object, input parameter types, and description. It is understood that when an agent calls a function, it first determines whether the target function exists in the function registry. If so, it only proceeds to the next step, thus reducing unnecessary execution.
[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 calls 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 requirement can be the number of function calls required by the user, and the large model can generate the corresponding number of function calls based on the user request. The large model provided in this application can intelligently parse user requests and generate accurate function calls, ensuring 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-scale model task call execution method based on the knowledge graph provided in this application is to construct a target knowledge graph with the function information in the obtained API information as nodes and the call dependency relationship between functions as edges, and then construct a function registry based on the functions and the call dependency relationship between functions in the target knowledge graph. A corresponding execution agent is established on the basis of the target knowledge graph and the function registry. The execution agent can call the call dependency relationship between functions from the target knowledge graph when the function exists in the function registry; thus, after the large model parses the user requirements and obtains 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 parsed result. This application improves the transparency and maintenance efficiency of the dependency relationship by constructing a knowledge graph, significantly reduces development risks, and improves system stability. Through the function registry and execution agent, centralized management and calling of API functions are realized, dynamic registration and real-time adjustment of dependencies are supported, code redundancy and complex management are avoided, calling efficiency and system flexibility are improved, and maintenance workload is reduced. Finally, the execution agent and the large model are combined to ensure the accuracy and adaptability of call generation, significantly improving the processing capability and response speed of complex tasks.
[0087] In some embodiments, constructing a target knowledge graph using function information in the API information as nodes and call dependencies between functions as edges includes:
[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 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 a test result;
[0093] Adjusting the initial call dependency in the initial knowledge graph based on the test results;
[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 use static code analysis to analyze the source code of the function in the initial knowledge graph to find the function definition and its calling situation, and then use the large language model to identify complex functions or framework calls, 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 whether the execution of the function depends on other functions. Specifically, the generated test case is converted into real executable code in this application, and verified by the 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 complete;
[0099] Verify whether the calling dependencies between functions in the target knowledge graph are correct, and make adjustments when an exception occurs to update the target knowledge graph.
[0100] It is understandable that after the target knowledge graph is built, it is necessary to perform a completeness 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. It verifies the accuracy of these dependencies through a combination of methods, including API documentation parsing, source code static analysis, and large-scale model generation of test cases. It also supports real-time updates. This improves the transparency and maintenance efficiency of these 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; wherein 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] During loading, the function name is mapped to a function object, and parameters, parameter types, and function descriptions 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, using a Python 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. This registry data can be placed in a configuration file (such as JSON or YAML) and loaded at system startup, or hard-coded directly into the program to create 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 enables centralized management and calling of all API functions, efficiently managing the calling logic and dependencies of API functions, and ensuring the correctness and maintainability of function calls. It should be noted that the function registry only manages functions and function relationship descriptions and cannot be called directly.
[0110] In some embodiments, inputting the acquired target requirements and user requests into a large model for understanding and generating function calls includes:
[0111] Generate a prompt 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 request 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, such as OpenAI's GPT-4, to ensure the model understands API documentation and code structure. This is not a limitation in this application. Configure the large model's call parameters, including the API key, generation diversity controls (such as temperature), and maximum output length, to ensure the model generates accurate and concise function calls. This application also feeds prompt text, containing function interface descriptions, parameter formats, and example calls, into the large model to provide sufficient context to help the model generate calls that meet target requirements and user expectations. The prompt text details each function's purpose, input and output parameter definitions, and other information. This information is extracted from API documentation, knowledge graphs, or function registries to help the LLM generate correct calls. The example calls and input and output parameter definitions in this application help the model understand the task, provide examples of various requests and corresponding function calls, and enhance the model's generation capabilities. Furthermore, the large model sets an output format, which can be JSON, to ensure the generated function calls are clearly structured and easy to parse, facilitating subsequent execution and verification.
[0115] In some embodiments, the execution agent determines a target function and function call dependency 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 call dependency of the target function and generate a call chain; the call chain reflects the function call order.
[0119] It is understandable that in this application, the large model and the execution agent are seamlessly connected, and 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 resolution. Then first verify whether the target function and parameters exist in the function registry. If they exist, the knowledge graph is queried to 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 the function call Function Call generated by LLM is improved to ensure the overall response quality and stability of the system. After generating the 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 that are 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 security risks such as injection attacks and data leakage.
[0122] In some embodiments, querying the target knowledge graph to obtain the call dependency relationship of the target function includes:
[0123] Querying all pre-dependent functions of the target function in the target knowledge graph;
[0124] Sort all 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, the execution agent in this application 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, match them with 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 in this application is used to query the knowledge graph to determine the dependencies of the target function, generate a complete call chain, and ensure that functions are executed in the correct order. Specifically, it includes:
[0135] Dependency query: Query all the predecessor dependent 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 promptly and stop execution if problems are found.
[0138] Dynamic dependency processing: supports runtime adjustment of dependencies and adjusts the calling order based on 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 the parameter names and types match the definitions in the function registry, and verifies whether all required parameters are provided.
[0141] Parameter type validation: Ensures that parameter values conform to expected types and further checks 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 information to help users or the 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 sequence: 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 function execution 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 abort 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 an error will be recorded.
[0149] In some embodiments, the call chain includes multiple call chains; 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 results of each function execution; the execution results include successful output and error output, and integrate 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 this application, the execution agent is provided with a result processor for uniformly managing the execution results of the function, including storage, transmission, formatting and output. The details are as follows:
[0158] Result storage: Store the function execution results 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 a natural language response or further processing.
[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: Records detailed information about 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 final execution results are input into the large model, which converts the function execution results into natural language responses that the user can understand. The function execution results are then organized 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 responses. 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 text 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 information such as task summary, execution results and error description. This application passes the constructed context to the 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 the LLM to correct grammar and optimize wording to ensure that the replies conform to grammatical specifications and the content is 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 requirements and obtain function calls corresponding to the user requirements. The execution agent searches for the target function that replaces the function from the function registry 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 the parsed result output of the user requirement.
[0169] The large model task call execution 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 through a combination of methods such as API document parsing, source code static analysis, and automatic generation of test cases. It also supports real-time updates, thereby improving the transparency and maintenance efficiency of the dependencies, significantly reducing development risks, and improving 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, using the large language model to intelligently parse user requests and automatically generate accurate function calls. Combined with Prompt optimization and multiple rounds of feedback, it ensures 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 call execution device based on a knowledge graph, the device comprising:
[0174] An acquisition module 201 is configured 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, for establishing an execution agent based on the target knowledge graph and function registry; the execution agent is used to parse the function calls generated by the large model;
[0177] Parsing module 204, 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 function call dependency based on the function call to generate a call chain, and execute the call chain to obtain a parsing result.
[0179] The working principle of the large model task call execution device based on the knowledge graph provided in this 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 in communication with the at least one processor; 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 this application. The computer instructions are used to cause the computer to execute the large model task call execution method based on the knowledge graph described in this 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] FIG3 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, workstations, 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 and / or required herein.
[0184] As shown in Figure 3, 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. RAM 303 may also store various programs and data required for the operation of device 300. Computing unit 301, ROM 302, and RAM 303 are interconnected via a bus 304. An input / output (I / O) interface 305 is also connected to bus 304.
[0185] Various components in device 300 are connected to I / O interface 305, including: an input unit 306, such as a keyboard, mouse, etc.; an output unit 307, such as various types of displays, speakers, etc.; a storage unit 308, such as a magnetic disk, optical disk, etc.; and a communication unit 309, such as a network card, modem, wireless communication transceiver, etc. The communication unit 309 allows device 300 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0186] The computing unit 301 can be any general-purpose and / or specialized processing component 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 specialized artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 301 performs the various methods and processes described above, such as the method for invoking and executing a large model task based on a knowledge graph. For example, in some embodiments, the method for invoking and executing a large model task based on a knowledge graph can be implemented as a computer software program tangibly embodied in a machine-readable medium, such as the storage unit 308. In some embodiments, part or all of the computer program can be loaded and / or installed onto 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 method for invoking and executing a large model task based on a knowledge graph described above can be performed. 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 (e.g., by means of firmware).
[0187] Various embodiments of the systems and techniques described above 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), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes 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 methods of the present application can be written in any combination of one or more programming languages. Such program code 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 when the program code is executed by the processor or controller, the functions / operations specified in the flow charts and / or block diagrams are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0189] In the context of this 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 apparatus. 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, apparatus, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, 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), optical fibers, 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 can 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 can 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 server are generally remote from each other and typically interact through a communication network. The client-server relationship arises through computer programs running on the respective computers and having a client-server relationship with each other. The server may be a cloud server, a server in a distributed system, or a server integrated with a blockchain.
[0193] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A large model task calling and execution method based on knowledge graph, It is 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 function call dependency based on the function call to generate a call chain, and executes the call chain to obtain a parsing result.
2. The method according to claim 1, It is characterized in that 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.
3. The method according to claim 1, It is 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.
4. The method according to claim 3, It is 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.
5. The method according to claim 4, It is 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.
6. The method according to claim 5, It is 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.
7. The method according to claim 1, It is 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.
8. The method according to claim 7, It is 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.
9. The method according to claim 2, It is 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.
10. A large model task calling and executing device based on knowledge graph, It is 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 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.
Citation Information
Patent Citations
Code analysis method and device based on knowledge graph
CN114491536A
Knowledge graph construction and query method and device, equipment, storage medium and product
CN115827487A
Knowledge graph construction method and device, equipment and storage medium
CN116860997A
Knowledge graph construction method and knowledge graph application method
CN118069856A
Method and device for accelerating AI large model output function calling
CN118485147A
Cited By
Task processing method and device based on intelligent agent and electronic equipment
CN119166834A
Task processing method and device of vehicle-mounted system, electronic equipment, medium and product
CN119336419A
Method and device for determining calling relation of generated code and storage medium
CN119917075A
Dependence graph generation method, risk assessment method, device, equipment and medium
CN120315725A
Dependency graph generation method, risk assessment method, device, equipment and medium
CN120315725B
