Task execution method and device based on API call and electronic equipment
By receiving natural language instructions, semantic parsing, and API call path mapping sets, a task execution plan is generated, which solves the problem of insufficient flexibility and scalability of language models in multi-tool collaborative task execution in existing technologies, and realizes accurate and reliable execution of complex tasks.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- TSINGHUA UNIVERSITY
- Filing Date
- 2026-02-02
- Publication Date
- 2026-06-05
AI Technical Summary
When faced with complex tasks that require continuous invocation of multiple tools and have logical connections between steps, existing technologies lack the flexibility and scalability of language models, making it difficult to achieve stable and reliable automated task execution.
By receiving natural language instructions, performing semantic parsing to obtain task intent, using a pre-built tool library to retrieve candidate APIs, generating a task execution plan, and dynamically adjusting the execution plan based on API return information, combined with a call path mapping set and task splitting mechanism, multi-tool collaborative task execution is achieved.
It enables accurate and reliable completion of complex tasks, improves the adaptability and calling ability of the language model to real-world tool libraries, enhances the accuracy, stability and controllability of task execution, and has good scalability.
Smart Images

Figure CN122154671A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence technology, and in particular to a task execution method, apparatus, and electronic device based on API calls. Background Technology
[0002] In recent years, with the rapid development of large-scale pre-trained language models, their capabilities in text understanding, generation, and reasoning have made significant progress. To overcome the limitations of these models in terms of training data timeliness, knowledge breadth, and physical manipulation capabilities, the industry has begun exploring technical approaches that combine language models with external tools, such as Application Programming Interfaces (APIs). By accessing and calling these external tools, language models can obtain real-time information, perform specialized calculations, or trigger actual business processes, thereby accomplishing complex tasks that traditional pure text models struggle to handle, greatly expanding their application scenarios and practical value.
[0003] However, there are still a series of key challenges in improving the usability of language model tools. Existing methods often perform poorly when faced with complex tasks that require continuous invocation of multiple tools with logical connections between steps. Models can usually only execute single, isolated tool calls, or heavily rely on pre-defined manual rules for task decomposition and scheduling, resulting in poor flexibility, limited scalability, and difficulty in achieving stable, reliable, and end-to-end automated task execution.
[0004] Therefore, finding a precise, reliable, and automated method to complete complex tasks involving multi-tool collaboration has become a current research hotspot. Summary of the Invention
[0005] This invention provides a task execution method, apparatus, and electronic device based on API calls, which enables the accurate, reliable, and automatic completion of complex tasks involving multi-tool collaboration by calling APIs.
[0006] This invention provides a task execution method based on API calls. The method includes: receiving a target natural language instruction, wherein the target natural language instruction represents an instruction to complete a target task; performing semantic parsing on the target natural language instruction to obtain a task intent matching the target task; retrieving multiple candidate application programming interfaces (APIs) corresponding to the task intent from a pre-built tool library based on the task intent; performing task planning on the target task based on the task intent and the multiple candidate APIs to generate a task execution plan, wherein the task execution plan includes at least a call sequence of the candidate APIs; progressively calling the candidate APIs according to the task execution plan, and dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate APIs, until the target task is completed.
[0007] According to a task execution method based on API calls provided by the present invention, before the step of performing task planning on the target task based on the task intent and multiple candidate application programming interfaces (APIs) to generate a task execution plan, the method further includes: obtaining a pre-constructed call path mapping set, wherein the call path mapping set includes the correspondence between different natural language instructions and different call paths, and the call path is used to characterize the path in which multiple APIs are called in a preset order; obtaining a target call path matching the target natural language instruction based on the target natural language instruction and the call path mapping set; the step of performing task planning on the target task based on the task intent and multiple candidate APIs to generate a task execution plan includes: performing task planning on the target task based on the task intent, multiple candidate APIs, and the target call path to generate a task execution plan.
[0008] According to a task execution method based on API calls provided by the present invention, the call path mapping set is constructed in the following manner: obtaining multiple application programming interface (API) combinations, wherein the API combinations are used to represent any combination of multiple APIs in the tool library; for each API combination, generating natural language instructions to call the API combination based on a generative large language model, and generating call paths for each API in the API combination that match the natural language instructions; constructing the call path mapping set based on the correspondence between the natural language instructions and the call paths.
[0009] According to a task execution method based on API calls provided by the present invention, the tool library is constructed in the following manner: multiple application programming interfaces (APIs) in the real world are obtained, wherein the APIs include at least one or more types of APIs for weather query, data retrieval, business query, and file operation; standardized descriptions are set for the APIs to obtain APIs with standardized descriptions, wherein the standardized descriptions include one or more of the following: functional description of the API, metadata of the API, and return format of the API; the tool library is constructed based on the multiple APIs with standardized descriptions.
[0010] According to the present invention, a task execution method based on API calls includes the step of dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate application programming interface until the target task is completed. This includes: determining in real time whether the return information returned by each call to the candidate application programming interface meets preset requirements; if the return information does not match the preset requirements, readjusting the subsequent task execution plan to obtain an adjusted task execution plan; and progressively calling subsequent candidate application programming interfaces based on the adjusted task execution plan, and repeating the steps from determining the return information returned by each call to the adjusted task execution plan until the target task is completed.
[0011] According to the present invention, a task execution method based on API calls is provided, wherein the task execution plan includes multiple task execution sub-plans; the step of generating a task execution plan by planning the target task based on the task intent and multiple candidate application programming interfaces (APIs) includes: splitting the target task into sub-tasks; for any sub-task, performing task planning based on the task intent and multiple candidate APIs to generate a task execution sub-plan; the step of progressively calling the candidate APIs according to the task execution plan and dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate APIs until the target task is completed includes: progressively calling the candidate APIs according to the task execution sub-plans and dynamically adjusting the subsequent task execution sub-plans based on the return information returned by each call to the candidate APIs until the target task is completed.
[0012] According to the present invention, a task execution method based on API calls, after the step of progressively calling the candidate application programming interfaces according to the task execution plan and dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate application programming interfaces, the method further includes: integrating the return information returned by each call to the candidate application programming interfaces; and constructing an auditable execution path record based on the return information.
[0013] The present invention also provides a task execution device based on API calls, the device comprising: a receiving module for receiving a target natural language instruction, wherein the target natural language instruction is used to represent an instruction to complete a target task; a parsing module for performing semantic parsing on the target natural language instruction to obtain a task intent matching the target task; a retrieval module for retrieving multiple candidate application programming interfaces (APIs) corresponding to the task intent from a pre-built tool library based on the task intent; a generation module for performing task planning on the target task based on the task intent and the multiple candidate APIs to generate a task execution plan, wherein the task execution plan includes at least a call sequence of the candidate APIs; and an execution module for progressively calling the candidate APIs according to the task execution plan, and dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate APIs, until the target task is completed.
[0014] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the task execution method based on API calls as described above.
[0015] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the task execution method based on API calls as described above.
[0016] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the task execution method based on API calls as described above.
[0017] This invention provides a task execution method, apparatus, and electronic device based on API calls. The method includes: receiving a target natural language instruction, wherein the target natural language instruction represents an instruction to complete a target task; performing semantic parsing on the target natural language instruction to obtain a task intent matching the target task; retrieving multiple candidate application programming interfaces (APIs) corresponding to the task intent from a pre-built tool library based on the task intent; performing task planning on the target task based on the task intent and the multiple candidate APIs to generate a task execution plan, wherein the task execution plan includes at least a call sequence of the candidate APIs; progressively calling the candidate APIs according to the task execution plan, and dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate APIs, until the target task is completed. This achieves accurate, reliable, and automatic completion of complex tasks involving multi-tool collaboration through API calls. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0019] Figure 1 This is a flowchart illustrating the task execution method based on API calls provided by the present invention.
[0020] Figure 2 This is a schematic diagram of the process provided by the present invention for planning the target task based on the task intent and multiple candidate application programming interfaces to generate a task execution plan.
[0021] Figure 3 This is a schematic diagram of the process for constructing a call path mapping set provided by the present invention.
[0022] Figure 4 This is a schematic diagram of the structure of the task execution device based on API calls provided by the present invention.
[0023] Figure 5 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0024] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0025] Figure 1 This is a flowchart illustrating the task execution method based on API calls provided by the present invention.
[0026] The following will combine Figure 1 The process of the task execution method based on API calls provided by this invention will be described.
[0027] In an exemplary embodiment of the present invention, combined with Figure 1 As can be seen, the task execution method based on API calls may include steps 110 to 150, and each step will be described below.
[0028] In step 110, a target natural language instruction is received, wherein the target natural language instruction is used to represent the instruction to complete the target task.
[0029] In one embodiment, a target natural language instruction may be received, wherein the target natural language instruction may be an instruction used to characterize the completion of a target task. It should be noted that the target task may be a complex task requiring multiple steps to complete.
[0030] In step 120, the target natural language instruction is semantically parsed to obtain the task intent that matches the target task.
[0031] In one embodiment, deep semantic analysis can be performed on the target natural language instructions to parse out the core task intent of the target task.
[0032] In step 130, based on the task intent, multiple candidate application programming interfaces corresponding to the task intent are retrieved from a pre-built tool library.
[0033] In one embodiment, candidate application programming interfaces (APIs) can be retrieved from a pre-built, standardized toolkit containing a vast number of real-world APIs, based on the parsed task intent.
[0034] In step 140, task planning is performed on the target task based on the task intent and multiple candidate application programming interfaces (APIs) to generate a task execution plan, wherein the task execution plan includes at least a sequence of calls to the candidate APIs.
[0035] In step 150, candidate application programming interfaces (APIs) are called step by step according to the task execution plan, and the subsequent task execution plan is dynamically adjusted based on the return information returned by each call to the candidate APIs, until the target task is completed.
[0036] In one embodiment, a task execution plan can be automatically generated by planning the target task based on the logical structure of the task intent and the functionality of the candidate application programming interfaces (APIs). This plan can be a logical flowchart or a sequence of steps. The task execution plan specifies the call sequence of the candidate APIs and the parameter generation rules required for each API, such as how to extract values from context or previous results.
[0037] Furthermore, candidate application programming interfaces (APIs) are invoked step-by-step according to the task execution plan, and the subsequent task execution plan is dynamically adjusted based on the return information of each API call until the target task is completed. In one example, if an API call fails or returns an exception during the process, subsequent steps can be adjusted according to preset strategies or replanning to ensure the resilience of the task chain and complete the target task.
[0038] This embodiment can understand complex natural language instructions containing conditions, order, and dependencies, and automatically decompose and plan them into a series of executable specific API operations, which solves the limitations of traditional methods that can only handle single-step instructions or rely on manually written fixed scripts.
[0039] This invention provides a task execution method based on API calls. The method includes: receiving a target natural language instruction, wherein the target natural language instruction represents an instruction to complete a target task; performing semantic parsing on the target natural language instruction to obtain a task intent matching the target task; retrieving multiple candidate application programming interfaces (APIs) corresponding to the task intent from a pre-built tool library based on the task intent; performing task planning on the target task based on the task intent and the multiple candidate APIs to generate a task execution plan, wherein the task execution plan includes at least a call sequence of the candidate APIs; progressively calling the candidate APIs according to the task execution plan, and dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate APIs, until the target task is completed. This method enables accurate, reliable, and automatic completion of complex tasks involving multi-tool collaboration through API calls.
[0040] Figure 2 This is a schematic diagram of the process provided by the present invention for planning the target task based on the task intent and multiple candidate application programming interfaces to generate a task execution plan.
[0041] The following will combine Figure 2 The process of generating a task execution plan based on the task intent and multiple candidate application programming interfaces provided by the present invention is described.
[0042] In an exemplary embodiment of the present invention, combined with Figure 2 As can be seen, the process of planning the target task based on the task intent and multiple candidate application programming interfaces to generate a task execution plan may include steps 210 to 230, which will be described in detail below.
[0043] In step 210, a pre-built call path mapping set is obtained, wherein the call path mapping set includes the correspondence between different natural language instructions and different call paths, and the call path is used to represent the path in which multiple application programming interfaces are called in a preset order.
[0044] In one embodiment, a pre-built call path mapping set can be accessed before task planning begins. This mapping set stores a large number of natural language instruction patterns and their corresponding call paths. For example, a natural language instruction pattern could be "Summarize recent [materials Y] on [topic X] and create a [format Z] report." The corresponding call path is "[Information Acquisition API] -> [Content Analysis API] -> [Format Generation API] (which is an abstract path template)."
[0045] In step 220, a target call path matching the target natural language instruction is obtained based on the target natural language instruction and the call path mapping set.
[0046] In one embodiment, the target natural language instruction can be matched with various instruction patterns in a mapping set to obtain a target invocation path that matches the target natural language instruction, thus successfully matching a target invocation path. This target invocation path specifies the common API type and approximate invocation order for completing this type of target task.
[0047] In step 230, the target task is planned based on the task intent, multiple candidate application programming interfaces, and the target call path to generate a task execution plan.
[0048] In another embodiment, the task intent clarifies what needs to be done; candidate APIs provide specific tools that are available; and the target invocation path provides a validated and efficient step-by-step template. During application, the target task can be planned based on the task intent, multiple candidate APIs, and the target invocation path to generate a task execution plan. This task execution plan not only inherits the macro-logic of the target invocation path but also specifically instantiates which candidate API should be used for each step and how the parameters are generated.
[0049] In this embodiment, it is unnecessary to perform complex reasoning and planning from scratch for each entirely new instruction. By quickly matching historical experience (target call path) from the mapping set, a proven high-level execution framework can be directly obtained, thereby significantly reducing the computation time and resource consumption required to generate a specific execution plan.
[0050] Figure 3 This is a schematic diagram of the process for constructing a call path mapping set provided by the present invention.
[0051] The following will combine Figure 3 The process of constructing the call path mapping set provided by this invention will be described.
[0052] In an exemplary embodiment of the present invention, combined with Figure 3 As can be seen, constructing the call path mapping set may include steps 310 to 330, and each step will be described below.
[0053] In step 310, multiple application programming interface (API) combinations are obtained, wherein the API combination is used to characterize any combination of multiple APIs in the tool library.
[0054] In one embodiment, sampling and composition can be performed from a pre-built, standardized toolkit. An application programming interface (API) composition can refer to an ordered or logically related set of multiple APIs arbitrarily selected from the toolkit. These compositions can be randomly combined based on the API's functional domain, such as "weather and travel," "information analysis and visualization," and "data processing and notification," or they can be constructed based on the co-occurrence frequency in historical call logs to ensure the diversity and usability of the compositions.
[0055] In step 320, for each application programming interface (API) combination, a natural language instruction to invoke the API combination is generated based on a generative large language model, and a call path for each API in the API combination that matches the natural language instruction is generated.
[0056] In one embodiment, for each API combination, a generative large language model can be used to generate instructions and paths. Taking combination A [News Retrieval API, Text Sentiment Analysis API, Chart Generation API] as an example, the functional descriptions of each API in combination A (from standardized interface descriptions in a tool library) can be input into a generative large language model, such as GPT-4 or LLaMA, prompting it to generate a user instruction that might use this set of APIs. The generated instruction might be: "Analyze the sentiment trend of recent news related to new energy vehicles and generate a sentiment distribution pie chart." Subsequently, or in an integrated prompt, the same large language model is required to deduce the specific call path based on the generated instruction and the given API combination. This path needs to detail the call order, parameter passing logic, etc.
[0057] In step 330, a call path mapping set is constructed based on the correspondence between natural language instructions and call paths.
[0058] In another embodiment, a one-to-one mapping relationship can be established between the natural language instructions generated for each API combination in the above steps and their corresponding detailed call paths. Step S320 is repeated, traversing a large number of different API combinations, to generate a massive number of such instruction-path pairs. Finally, all these instruction-path pairs are organized and stored to form a large-scale, structured, and queryable call path mapping set.
[0059] In this embodiment, by systematically sampling and creating diverse API combinations from a tool library, a wide range of task scenarios and tool interaction patterns can be covered. Based on these combinations, the generative large language model can create grammatically diverse, intent-laden natural language instructions that closely resemble real user expressions, along with logically rigorous corresponding execution paths. This ensures that the final constructed mapping set has sufficient breadth and depth to support the model's learning of complex task planning, addressing the problems of small data scale and low structure in existing technologies.
[0060] In yet another exemplary embodiment of the present invention, the tool library can be constructed in the following manner, continuing with the previously described embodiments: Obtain multiple application programming interfaces (APIs) from the real world, where the APIs include at least one or more of the following types: weather query, data retrieval, business query, and file operation. Set a normalized description for the application programming interface to obtain the application programming interface with the normalized description. The normalized description includes any one or more of the following: the functional description of the application programming interface, the meta information of the application programming interface, and the return format of the application programming interface. A tool library is built based on multiple application programming interfaces (APIs) with standardized descriptions.
[0061] In one embodiment, readily available service interfaces can be widely collected from the Internet, third-party service platforms, or internal enterprise systems. These APIs can be invoked via network protocols (such as HTTP) and cover a wide variety of functionalities. Application programming interfaces (APIs) can include at least one or more of the following types: weather queries, data retrieval, business queries, and file operations.
[0062] Furthermore, to enable machines to uniformly understand and invoke these heterogeneous APIs, each API needs to be standardized and encapsulated, generating a structured and standardized description. This description typically exists in the form of structured data and includes at least one or more of the following: a functional description of the API, metadata about the API, and the API's return format. The functional description can clearly describe the core purpose of the API using natural language and keywords; the API's metadata may include request methods, required authentication, etc., and understandably includes, but is not limited to, interface definitions, interface parameter formats, interface semantics, and behavioral descriptions. The API's return format can explicitly define the structure and meaning of the data returned after a successful call. Through this step, each original, poorly documented API is transformed into a standardized, machine-readable interface unit with a unified description specification—that is, an application programming interface (API) with a standardized description.
[0063] In another embodiment, all APIs with standardized descriptions can be registered and stored in a central repository or database, forming a tool library used by the system. This tool library supports efficient retrieval and management by function type, name keywords, input / output format, etc.
[0064] In this embodiment, the heterogeneity problem of APIs is fundamentally solved by forcibly attaching a unified, standardized description to real-world APIs from diverse sources with vastly different protocols and document formats. This enables upstream task parsing, planning, and execution modules to "understand" and "operate" all tools in a consistent manner, eliminating the need to write special adaptation code for each API and greatly reducing the system's integration complexity and maintenance costs.
[0065] In yet another exemplary embodiment of the present invention, the following description continues using the previously described embodiments as examples. Dynamically adjusting the subsequent task execution plan based on the return information from each call to the candidate application programming interface until the target task is completed can be achieved in the following manner: Based on the return information returned by each call to the candidate application programming interface, determine in real time whether the return information meets the preset requirements; If the returned information does not match the preset requirements, the subsequent task execution plan is readjusted to obtain the adjusted task execution plan; Based on the adjusted task execution plan, subsequent candidate application programming interfaces are called step by step, and the step of calling subsequent candidate application programming interfaces based on the return information returned by each call to the candidate application programming interface is repeated until the target task is completed.
[0066] In one embodiment, it can be determined in real time whether the return information returned by each call to the candidate application programming interface meets the preset requirements. The preset requirements can be determined according to the actual situation of the completed target task, and are not specifically limited in this embodiment.
[0067] Furthermore, in the event of a mismatch in the returned information, the execution plan for subsequent tasks is readjusted. During application, the system can execute based on the adjusted plan and repeat the judgment and adjustment process. If, during the execution of a new step or subsequent step, the returned information from any API again fails to meet the preset requirements, the system will repeat the steps from calling the candidate application programming interface (API) based on the returned information each time to progressively calling subsequent candidate APIs based on the adjusted task execution plan. In other words, the "judgment-adjustment-execution" loop will be repeated to generate a new adjustment plan until the task is finally completed or the termination condition is met.
[0068] Real-world API responses are inherently unpredictable (e.g., partial failures, format changes, data delays). This implementation monitors and evaluates the results of each call in real time, enabling the system to detect anomalies rather than blindly executing subsequent steps. This effectively prevents the spread of errors ("garbage in, garbage out"), minimizes the impact of localized failures, and significantly improves the final completion rate of tasks in non-ideal environments.
[0069] In yet another exemplary embodiment of the present invention, continuing with the previously described embodiments, the task execution plan may include multiple task execution sub-plans; generating a task execution plan by planning the target task based on the task intent and multiple candidate application programming interfaces can be achieved in the following ways: The target task is split into subtasks to obtain the subtasks. For any of the split target subtasks, task planning is performed on the split target subtasks based on the task intent and multiple candidate application programming interfaces to generate a task execution sub-plan. The process of progressively calling the candidate application programming interfaces (APIs) according to the task execution plan, and dynamically adjusting the subsequent task execution plan based on the return information from each call to the APIs, until the target task is completed, can be implemented in the following way: The candidate application programming interface is called step by step according to the task execution sub-plan, and the subsequent task execution sub-plan is dynamically adjusted according to the return information returned by each call to the candidate application programming interface, until the target task is completed.
[0070] In one embodiment, based on an understanding of the task intent, the target task can be broken down into logically independent and separately processable sub-tasks. For each of these sub-tasks, task planning can be performed based on the task intent and multiple candidate application programming interfaces (APIs) to generate a task execution sub-plan.
[0071] Furthermore, candidate application programming interfaces (APIs) can be invoked progressively according to the task execution sub-plan, and subsequent task execution sub-plans can be dynamically adjusted based on the return information from each API call, until the target task is completed. It should be noted that for split target subtasks without dependencies, refrigerator calls can be performed based on the corresponding task execution sub-plans to improve execution efficiency.
[0072] In this embodiment, the grand task objective is transformed into a series of collaborative sub-tasks, which improves efficiency, robustness and manageability, while providing solid architectural support for building intelligent systems capable of handling large-scale, complex automated tasks in the real world.
[0073] In yet another exemplary embodiment of the present invention, continuing with the previously described embodiments as an example, after the step of progressively invoking the candidate application programming interface according to the task execution plan and dynamically adjusting the subsequent task execution plan based on the return information returned by each invocation of the candidate application programming interface, the method may further include the following steps: Integrate the return information from each call to the candidate application programming interface; Based on the returned information, an auditable execution path record is constructed.
[0074] In one embodiment, the results of various tool calls during the multi-step execution process, such as the return information from each call to the candidate application programming interface, can be uniformly organized to generate the final output result and construct an auditable execution path record. This makes the execution process transparent and traceable, and can be used for task execution effect verification and system optimization. This execution path record can also be used for subsequent model optimization and error analysis, helping to improve the accuracy and stability of the model in planning complex tasks.
[0075] As described above, this invention provides a task execution method based on API calls. By constructing a large-scale, structured dataset of natural language instructions and tool call paths, and combining it with targeted task planning and execution mechanisms, the language model can directly generate accurate tool call sequences from natural language instructions and complete multi-step tasks. This invention significantly improves the model's adaptability and calling capability to real-world tool libraries. By covering a rich variety of tool interfaces and their calling specifications, it overcomes the problem of insufficient tool calling capability caused by the limitation of the number and type of tools in existing methods, thereby improving the overall completion rate and execution accuracy of the language model in complex task environments. Secondly, through a clear mapping mechanism and execution path planning, this invention enables the model to have higher stability and controllability in the decomposition and combined execution of multi-step tasks, effectively solving the problems of untraceable execution process and poor robustness in existing technologies, and achieving auditability and verifiability of task execution. Thirdly, by introducing a dynamic feedback and adjustment mechanism, this invention enables the model to maintain stable task execution performance when facing uncertainties in the return format or response of heterogeneous tools, thereby improving the reliability and practical application value of the system. Finally, the overall design of this technical solution possesses excellent scalability, allowing for rapid expansion of the tool library and adjustment of execution strategies based on new tools or task requirements. This significantly enhances the practicality of the language model in real-world scenarios, providing a solid technical foundation for building efficient, controllable, and intelligent task automation systems. This invention can meet the higher requirements of accuracy, robustness, and controllability in complex practical applications.
[0076] The task execution device based on API calls provided by the present invention is described below. The task execution device based on API calls described below can be referred to in correspondence with the task execution method based on API calls described above.
[0077] Figure 4 This is a schematic diagram of the structure of the task execution device based on API calls provided by the present invention.
[0078] In an exemplary embodiment of the present invention, combined with Figure 4As can be seen, the task execution device based on API calls may include a receiving module 410, a parsing module 420, a retrieval module 430, a generation module 440, and an execution module 450. Each module will be described in detail below.
[0079] The receiving module 410 can be configured to receive target natural language instructions, wherein the target natural language instructions are used to represent instructions for completing the target task; The parsing module 420 can be configured to perform semantic parsing on the target natural language instruction to obtain a task intent that matches the target task; The retrieval module 430 can be configured to retrieve multiple candidate application programming interfaces corresponding to the task intent from a pre-built tool library based on the task intent. The generation module 440 can be configured to perform task planning on the target task based on the task intent and multiple candidate application programming interfaces, and generate a task execution plan, wherein the task execution plan includes at least a sequence of calls to the candidate application programming interfaces; The execution module 450 can be configured to progressively call the candidate application programming interface according to the task execution plan, and dynamically adjust the subsequent task execution plan based on the return information returned by each call to the candidate application programming interface, until the target task is completed.
[0080] In an exemplary embodiment of the present invention, the generation module 440 may further be configured to: Obtain a pre-built call path mapping set, wherein the call path mapping set includes the correspondence between different natural language instructions and different call paths, and the call path is used to represent the path in which multiple application programming interfaces are called in a preset order; Based on the target natural language instruction and the call path mapping set, a target call path matching the target natural language instruction is obtained; The generation module 440 can perform task planning for the target task based on the task intent and multiple candidate application programming interfaces, and generate a task execution plan in the following manner: Based on the task intent, multiple candidate application programming interfaces, and the target call path, the target task is planned to generate a task execution plan.
[0081] In an exemplary embodiment of the present invention, the generation module 440 may construct the call path mapping set in the following manner: Obtain multiple application programming interface (API) combinations, wherein the API combination is used to characterize any combination of multiple APIs in the tool library; For each of the application programming interface (API) combinations, a natural language instruction to invoke the API combination is generated based on a generative large language model, and a call path for each API in the API combination that matches the natural language instruction is generated. Based on the correspondence between the natural language instructions and the calling paths, the calling path mapping set is constructed.
[0082] In an exemplary embodiment of the present invention, the retrieval module 430 may construct the tool library in the following manner: Obtain multiple application programming interfaces (APIs) from the real world, wherein the APIs include at least one or more types of APIs for weather query, data retrieval, business query, and file operation; A standardized description is set for the application programming interface (API) to obtain an API with a standardized description. The standardized description includes any one or more of the following: the functional description of the API, the metadata of the API, and the return format of the API. The tool library is constructed based on multiple application programming interfaces (APIs) that are configured with standardized descriptions.
[0083] In an exemplary embodiment of the present invention, the execution module 450 may dynamically adjust the subsequent task execution plan based on the return information returned by each call to the candidate application programming interface until the target task is completed: Based on the return information returned by each call to the candidate application programming interface, determine in real time whether the return information meets the preset requirements; If the returned information does not match the preset requirements, the subsequent task execution plan is readjusted to obtain the adjusted task execution plan; Based on the adjusted task execution plan, subsequent candidate application programming interfaces are called step by step, and the step of calling subsequent candidate application programming interfaces based on the return information returned by each call to the candidate application programming interface is repeated until the target task is completed.
[0084] In an exemplary embodiment of the present invention, the task execution plan includes multiple task execution sub-plans; the generation module 440 can generate a task execution plan by performing task planning on the target task based on the task intent and multiple candidate application programming interfaces in the following manner: The target task is split into subtasks to obtain the subtasks. For any of the split target subtasks, task planning is performed on the split target subtasks based on the task intent and multiple candidate application programming interfaces to generate a task execution sub-plan. The execution module 450 can dynamically adjust the subsequent task execution plan based on the return information returned by each call to the candidate application programming interface, until the target task is completed, in the following manner: The candidate application programming interface is called step by step according to the task execution sub-plan, and the subsequent task execution sub-plan is dynamically adjusted according to the return information returned by each call to the candidate application programming interface, until the target task is completed.
[0085] In an exemplary embodiment of the present invention, the execution module 450 may further be configured to: Integrate the return information from each call to the candidate application programming interface; Based on the returned information, an auditable execution path record is constructed.
[0086] Figure 5 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 5 As shown, the electronic device may include: a processor 510, a communications interface 520, a memory 530, and a communication bus 540, wherein the processor 510, communications interface 520, and memory 530 communicate with each other via the communication bus 540. The processor 510 can call logical instructions in the memory 530 to execute an API-based task execution method. This method includes: receiving a target natural language instruction, wherein the target natural language instruction represents an instruction to complete a target task; performing semantic parsing on the target natural language instruction to obtain a task intent matching the target task; based on the task intent, retrieving multiple candidate application programming interfaces (APIs) corresponding to the task intent from a pre-built tool library; performing task planning on the target task based on the task intent and the multiple candidate APIs to generate a task execution plan, wherein the task execution plan includes at least a call sequence of the candidate APIs; progressively calling the candidate APIs according to the task execution plan, and dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate APIs, until the target task is completed.
[0087] Furthermore, the logical instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0088] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the task execution method based on API calls provided by the above methods. The method includes: receiving a target natural language instruction, wherein the target natural language instruction is used to represent an instruction to complete a target task; performing semantic parsing on the target natural language instruction to obtain a task intent matching the target task; retrieving multiple candidate application programming interfaces (APIs) corresponding to the task intent from a pre-built tool library based on the task intent; performing task planning on the target task based on the task intent and the multiple candidate APIs to generate a task execution plan, wherein the task execution plan includes at least a call sequence of the candidate APIs; and progressively calling the candidate APIs according to the task execution plan, and dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate APIs, until the target task is completed.
[0089] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements an API call-based task execution method provided by the above methods. The method includes: receiving a target natural language instruction, wherein the target natural language instruction is used to represent an instruction to complete a target task; performing semantic parsing on the target natural language instruction to obtain a task intent matching the target task; retrieving multiple candidate application programming interfaces (APIs) corresponding to the task intent from a pre-built tool library based on the task intent; performing task planning on the target task based on the task intent and the multiple candidate APIs to generate a task execution plan, wherein the task execution plan includes at least a call sequence of the candidate APIs; progressively calling the candidate APIs according to the task execution plan, and dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate APIs, until the target task is completed.
[0090] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0091] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0092] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A task execution method based on API calls, characterized in that, The method includes: Receive target natural language instructions, wherein the target natural language instructions are used to represent instructions for completing the target task; Semantic parsing is performed on the target natural language instruction to obtain the task intent that matches the target task; Based on the task intent, multiple candidate application programming interfaces corresponding to the task intent are retrieved from a pre-built tool library; Based on the task intent and multiple candidate application programming interfaces (APIs), task planning is performed on the target task to generate a task execution plan, wherein the task execution plan includes at least a sequence of calls to the candidate APIs; The candidate application programming interfaces (APIs) are invoked step by step according to the task execution plan, and the subsequent task execution plan is dynamically adjusted based on the return information returned by each invocation of the candidate APIs, until the target task is completed.
2. The task execution method based on API calls according to claim 1, characterized in that, Before performing task planning on the target task based on the task intent and multiple candidate application programming interfaces to generate a task execution plan, the method further includes: Obtain a pre-built call path mapping set, wherein the call path mapping set includes the correspondence between different natural language instructions and different call paths, and the call path is used to represent the path in which multiple application programming interfaces are called in a preset order; Based on the target natural language instruction and the call path mapping set, a target call path matching the target natural language instruction is obtained; The step of planning the target task based on the task intent and multiple candidate application programming interfaces to generate a task execution plan includes: Based on the task intent, multiple candidate application programming interfaces, and the target call path, the target task is planned to generate a task execution plan.
3. The task execution method based on API calls according to claim 2, characterized in that, The call path mapping set is constructed in the following way: Obtain multiple application programming interface (API) combinations, wherein the API combination is used to characterize any combination of multiple APIs in the tool library; For each of the application programming interface (API) combinations, a natural language instruction to invoke the API combination is generated based on a generative large language model, and a call path for each API in the API combination that matches the natural language instruction is generated. Based on the correspondence between the natural language instructions and the calling paths, the calling path mapping set is constructed.
4. The task execution method based on API calls according to claim 1, characterized in that, The tool library was constructed in the following manner: Obtain multiple application programming interfaces (APIs) from the real world, wherein the APIs include at least one or more types of APIs for weather query, data retrieval, business query, and file operation; A standardized description is set for the application programming interface (API) to obtain an API with a standardized description. The standardized description includes any one or more of the following: the functional description of the API, the metadata of the API, and the return format of the API. The tool library is constructed based on multiple application programming interfaces (APIs) that are configured with standardized descriptions.
5. The task execution method based on API calls according to claim 1, characterized in that, The step of dynamically adjusting the subsequent task execution plan based on the return information returned by each call to the candidate application programming interface until the target task is completed includes: Based on the return information returned by each call to the candidate application programming interface, determine in real time whether the return information meets the preset requirements; If the returned information does not match the preset requirements, the subsequent task execution plan is readjusted to obtain the adjusted task execution plan; Based on the adjusted task execution plan, subsequent candidate application programming interfaces are called step by step, and the step of calling subsequent candidate application programming interfaces based on the return information returned by each call to the candidate application programming interface is repeated until the target task is completed.
6. The task execution method based on API calls according to claim 1, characterized in that, The task execution plan includes multiple task execution sub-plans; the step of generating a task execution plan by planning the target task based on the task intent and multiple candidate application programming interfaces includes: The target task is split into subtasks to obtain the subtasks. For any of the split target subtasks, task planning is performed on the split target subtasks based on the task intent and multiple candidate application programming interfaces to generate a task execution sub-plan. The step of progressively invoking the candidate application programming interfaces (APIs) according to the task execution plan, and dynamically adjusting the subsequent task execution plan based on the return information returned by each invocation of the candidate APIs, until the target task is completed, includes: The candidate application programming interface is called step by step according to the task execution sub-plan, and the subsequent task execution sub-plan is dynamically adjusted according to the return information returned by each call to the candidate application programming interface, until the target task is completed.
7. The task execution method based on API calls according to claim 1, characterized in that, After the step-by-step invocation of the candidate application programming interfaces according to the task execution plan, and the dynamic adjustment of the subsequent task execution plan based on the return information returned by each invocation of the candidate application programming interface, the method further includes: Integrate the return information from each call to the candidate application programming interface; Based on the returned information, an auditable execution path record is constructed.
8. A task execution device based on API calls, characterized in that, The device includes: A receiving module is used to receive target natural language instructions, wherein the target natural language instructions are used to represent instructions for completing the target task; The parsing module is used to perform semantic parsing on the target natural language instruction to obtain the task intent that matches the target task; The retrieval module is used to retrieve multiple candidate application programming interfaces corresponding to the task intent from a pre-built tool library based on the task intent. A generation module is used to perform task planning on the target task based on the task intent and multiple candidate application programming interfaces (APIs) and generate a task execution plan, wherein the task execution plan includes at least a call sequence of the candidate APIs; The execution module is used to progressively call the candidate application programming interfaces according to the task execution plan, and dynamically adjust the subsequent task execution plan based on the return information returned by each call to the candidate application programming interface, until the target task is completed.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, characterized in that, When the processor executes the computer program, it implements the task execution method based on API calls as described in any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the task execution method based on API calls as described in any one of claims 1 to 7.