Tool calling method and device, electronic equipment, medium and program product

Through the automatic conversion and calling function tools of large language models, the problem of inefficient development in tool calls is solved, parameter automation processing and complex type adaptation are realized, and development efficiency is improved.

CN120295696APending Publication Date: 2025-07-11BEIJING ZITIAO NETWORK TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510437973.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-08
Publication Date
2025-07-11

AI Technical Summary

Technical Problem

In the prior art tool calls require developers to manually parse input, verify parameter structure and write duplicate code, resulting in inefficient development and error-prone, and cannot support dynamic adaptation of complex parameter types.

Method used

Calling the function tool through a large language model, automatically converting parameters according to the tool name and data description, and calling the objective function, returning the call result to achieve automatic processing of parameters.

Benefits of technology

It greatly reduces the amount of code, improves development efficiency, supports the adaptation of complex parameter types, and reduces manual processing of parameter parsing and mapping errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120295696A_ABST
    Figure CN120295696A_ABST
Patent Text Reader

Abstract

The invention discloses a tool calling method and device, electronic equipment, a medium and a program product, and relates to the technical field of computers. And converting a first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter capable of being input into a target function corresponding to the function tool, calling the target function based on the second parameter to obtain a calling result output by the function tool, and then returning the calling result to the large language model. The big language model can output the first parameter according to the input parameter structure of the target function, so that the function tool can automatically convert the first parameter into the second parameter, and the effect that a developer does not need to process parameter analysis and mapping is achieved; the code quantity is greatly reduced, the development efficiency is greatly improved, and adaptation of complex parameter types can be supported.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technologies, and in particular, to a method, apparatus, electronic device, medium, and program product for tool invocation. Background Art

[0002] In related technologies, if it is necessary to implement dynamic invocation of a tool, generally, developers need to manually parse the input, verify the parameter structure, and write repetitive code to implement the tool invocation logic. For example, a fixed interface needs to be defined for each tool, and developers need to deserialize the parameters by themselves and process the nested structure. This results in low development efficiency of the tool. When developers deserialize manually, it is extremely easy to make mistakes, and complex parameter type dynamic adaptation cannot be supported. Summary of the Invention

[0003] This Summary of the Invention section is provided to introduce concepts in a brief form, which will be described in detail in the Detailed Description section later. This Summary of the Invention section is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to be used to limit the scope of the claimed technical solution.

[0004] In a first aspect, the present disclosure provides a method for tool invocation, including: Invoking a function tool corresponding to the tool name according to the tool name of the function tool that the large language model needs to invoke, converting a first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter that can be input into the target function corresponding to the function tool, and invoking the target function based on the second parameter to obtain an invocation result output by the function tool; wherein, the data description is used to describe the input parameter structure of the target function; Returning the invocation result to the large language model so that the large language model obtains an output result based on the invocation result.

[0005] In a second aspect, the present disclosure provides a tool invocation apparatus, including: An invocation module configured to invoke a function tool corresponding to the tool name according to the tool name of the function tool that the large language model needs to invoke, convert a first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter that can be input into the target function corresponding to the function tool, and invoke the target function based on the second parameter to obtain an invocation result output by the function tool; wherein, the data description is used to describe the input parameter structure of the target function; A return module configured to return the invocation result to the large language model so that the large language model obtains an output result based on the invocation result.

[0006] In a third aspect, the present disclosure provides a computer-readable medium having a computer program stored thereon, and when the computer program is executed by a processing device, the steps of the method described in the first aspect are implemented.

[0007] In a fourth aspect, the present disclosure provides an electronic device, including: a storage device having a computer program stored thereon; a processing device configured to execute the computer program in the storage device to implement the steps of the method described in the first aspect.

[0008] In a fifth aspect, the present disclosure provides a computer program product including a computer program, and when the computer program is executed by a processor, the steps of the method described in the first aspect are implemented.

[0009] Based on the above technical solutions, by calling a function tool corresponding to a tool name according to the tool name of the function tool that needs to be called by the large language model, converting a first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter that can be input into the target function corresponding to the function tool, and based on the second parameter, calling the target function to obtain a call result output by the function tool, and then returning the call result to the large language model so that the large language model can obtain an output result based on the call result, it can be made such that the large language model can output the first parameter according to the input parameter structure of the target function corresponding to the function tool, so that the function tool can automatically convert the first parameter that conforms to the input parameter structure of the target function output by the large language model into a second parameter that can be directly input into the target function, achieving the effect that developers do not need to handle parameter parsing and mapping, greatly reducing the amount of code and greatly improving the development efficiency, and also being able to support the adaptation of complex parameter types.

[0010] Other features and advantages of the present disclosure will be described in detail in the subsequent specific implementation section. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] In combination with the drawings and with reference to the following specific implementation, the above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic, and the original components and elements are not necessarily drawn to scale. In the drawings: Figure 1 is a flowchart of a tool call method shown according to an exemplary embodiment.

[0012] Figure 2 is a flowchart of constructing a function tool shown according to an exemplary embodiment.

[0013] Figure 3It is a flowchart of a construction function tool shown according to another exemplary embodiment.

[0014] Figure 4 It is a flowchart of a tool call shown according to an exemplary embodiment.

[0015] Figure 5 It is a schematic structural diagram of a tool call device shown according to an exemplary embodiment.

[0016] Figure 6 It is a schematic structural diagram of an electronic device shown according to an exemplary embodiment. Detailed implementation manners

[0017] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although some embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Instead, these embodiments are provided to more thoroughly and completely understand the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not used to limit the protection scope of the present disclosure.

[0018] It should be understood that the various steps recited in the method embodiments of the present disclosure can be executed in a different order and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this regard.

[0019] As used herein, the term "including" and its variants are open-ended, that is, "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description.

[0020] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence relationship of the functions performed by these devices, modules or units.

[0021] It should be noted that the modifications of "one" and "plural" mentioned in the present disclosure are illustrative rather than restrictive. Those skilled in the art should understand that, unless otherwise clearly specified in the context, it should be understood as "one or more".

[0022] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only for illustrative purposes and are not used to limit the scope of these messages or information.

[0023] Figure 1 is a flowchart of a tool call method shown according to an exemplary embodiment. As Figure 1 shown, the embodiments of the present disclosure provide a tool call method, which can specifically be executed by a tool call device, and the device can be implemented in a software and / or hardware manner. As Figure 1 shown, the method may include the following steps.

[0024] In step 110, according to the tool name of the function tool that the large language model needs to call, call the function tool corresponding to the tool name, convert the first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter that can be input into the target function corresponding to the function tool, and based on the second parameter, call the target function to obtain the call result output by the function tool.

[0025] Here, whether the large language model needs to call a function tool can be determined by the large language model according to the prompt words input by the user to determine whether to call the corresponding function tool. For example, when the user asks the large language model "What is the current weather in place A?", since the data used in the previous training of the large language model does not contain the information of "the current weather in place A", at this time, the large language model can call the function tool for querying weather information to obtain the corresponding answer.

[0026] Of course, whether the large language model needs to call a function tool can also be informed by the user. For example, the user can use prompt words to inform the large language model which function tools can be called to assist in obtaining the answer.

[0027] The large language model can call the function tool corresponding to the tool name by the tool name of the function tool that needs to be called to obtain the corresponding call result through the function tool.

[0028] Among them, a function tool is a tool that encapsulates a function into a callable tool. In the embodiments of the present disclosure, the function tool is used to convert the first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter that can be input into the target function corresponding to the function tool, and based on the second parameter, call the target function to obtain the corresponding call result.

[0029] It should be noted that the first parameter output by the large language model can refer to the parameter obtained by the large language model from the prompt words. For example, the prompt words of "What is the current weather in place A?" can be converted into the first parameter of "the current weather in place A". That is to say, the first parameter output by the large language model can essentially be understood as the parameter that the large language model recognizes from the prompt words input by the user and needs to input into the function tool.

[0030] Among them, the data description corresponding to the function tool is used to describe the input parameter structure of the target function. The input parameter structure of the target function refers to the organizational form, data type, and other characteristics of the input parameters of the target function when the target function is called. For example, the number of input parameters, data types, order, and so on. Through the data description corresponding to the function tool, the large language model can be informed of the parameter structure for outputting the first parameter. It should be noted that the specific form of the data description will be described in detail in the subsequent embodiments.

[0031] For the large language model, when the large language model needs to call a specific function tool, the large language model extracts the corresponding parameters from the prompt words and outputs the extracted parameters as the first parameter according to the input parameter structure of the target function described by the data description corresponding to the function tool, so that the function tool can recognize the first parameter that conforms to the input parameter structure of the target function and automatically convert the first parameter into the second parameter that can be directly input into the target function corresponding to the function tool. For example, assuming that the input parameter structure of the target function is passed into the target function in the order of "location information, time information", the large language model extracts the time information and location information from the prompt words, and the output first parameter is the parameter structure of "location information, time information".

[0032] It should be understood that when the large language model makes a tool call, it can obtain the data description corresponding to the function tool to be called and output the corresponding first parameter according to the input parameter structure corresponding to the data description.

[0033] Exemplarily, the first parameter output by the large language model can be a parameter in the first data format, and the second parameter of the target function encapsulated by the function tool can be a parameter in the second data format. For example, the first data format can be JSON (JavaScript Object Notation, a lightweight data interchange format), and the second data format can be the data format corresponding to Go (also known as Golang, an open-source programming language). Of course, in the embodiments of the present disclosure, the specific data formats of the first parameter and the second parameter are not limited.

[0034] Since the first parameter in the first data format output by the large language model cannot be directly input into the target function encapsulated by the function tool, the function tool converts the first parameter in the first data format into the second parameter in the second data format that can be directly input into the target function.

[0035] That is to say, the function tool provided in the embodiments of the present disclosure can actually be understood as adding a conversion layer outside the target function for converting the first parameter output by the large language model based on the data description into the second parameter that can be input into the target function.

[0036] After the function tool converts the first parameter output by the large language model based on the data description into the second parameter that can be input into the target function, the function tool passes the second parameter to the target function, calls the target function, calculates the call result of the target function, and returns the call result to the large language model.

[0037] It should be understood that the call result output by the function tool may refer to the result calculated by the target function based on the second parameter.

[0038] In step 120, the call result is returned to the large language model so that the large language model can obtain the output result based on the call result.

[0039] Here, the call result obtained by the function tool is returned to the large language model, and the large language model calculates the corresponding output result according to the call result obtained by the function tool. Among them, the output result of the large language model may refer to the thinking result obtained by the large language model through the prompt and the call result.

[0040] Exemplarily, according to the call result of the function tool, a function message can be constructed, and then the function message is returned to the large language model. The large language model splices the function message into the prompt, and obtains the output result of the large language model through the spliced prompt.

[0041] Thus, by calling the function tool corresponding to the tool name according to the tool name of the function tool that the large language model needs to call, converting the first parameter output by the large language model based on the data description corresponding to the function tool into the second parameter that can be input into the target function corresponding to the function tool, and based on the second parameter, calling the target function to obtain the call result output by the function tool, and then returning the call result to the large language model so that the large language model can obtain the output result based on the call result, it can enable the large language model to output the first parameter according to the input parameter structure of the target function corresponding to the function tool, so that the function tool can automatically convert the first parameter that conforms to the input parameter structure of the target function output by the large language model into the second parameter that can be directly input into the target function, achieving the effect that developers do not need to handle parameter parsing and mapping, greatly reducing the code volume and greatly improving the development efficiency, and also being able to support the adaptation of complex parameter types.

[0042] Figure 2 It is a flowchart of constructing a function tool shown according to an exemplary embodiment. As Figure 2 shown, in some implementable embodiments, a function tool can be constructed through the following steps.

[0043] In step 201, for each input parameter in the target function, according to the parameter information of the input parameter, a field corresponding to the input parameter is constructed through reflection.

[0044] Here, the input parameters of the target function refer to the values passed to the target function when the target function is called, and the input parameters are used to perform specific operations within the target function. The parameter information of the input parameters can include the parameter name and parameter type of the input parameters. The parameter name refers to the name used to identify each input parameter in the function or method definition. Through the parameter name, not only can different input parameters be distinguished, but also the value of the parameter can be referenced within the function. The parameter type can include basic types, composite types, and custom types. The basic type can be, for example, an integer (int), a floating-point number (float), a string (str), a boolean value (bool), etc. The composite type can be, for example, a list (list), a dictionary (dict), a tuple (tuple), etc. The custom type can be, for example, an instance of a class, a struct, etc.

[0045] All input parameters of the target function can be extracted from the target function, and then for each input parameter, a corresponding field is constructed through reflection. In the case where the target function is a function written in the Go language, exemplarily, a field of a struct can be dynamically created according to the parameter name and parameter type. Each input parameter in the target function corresponds to a field in the struct.

[0046] In some embodiments, the source code of the target function can be parsed to obtain the abstract syntax tree of the target function, and then based on the abstract syntax tree, the function declaration of the target function is determined, and the parameter list in the function declaration is traversed to obtain the parameter information of each input parameter in the target function.

[0047] Among them, the function name of the target function and the relative path of the package where the target function is located can be obtained through reflection and runtime, and then by parsing all the source code under the relative path of the package where the target function is located, the abstract syntax tree (AST) of the target function is obtained.

[0048] Next, traverse the abstract syntax tree, and find the function declaration (FuncDecl) of the target function through the function name of the target function. Then, traverse the parameter list (FieldList) in the function declaration to obtain the parameter information of all input parameters (Paramms) included in the target function.

[0049] Based on this, through the abstract syntax tree, the parameter name of the function can be extracted from the function written in the Go language, thus solving the technical problem that the parameter name of the function written in the Go language cannot be directly obtained through reflection.

[0050] In step 202, an intermediate struct is constructed based on the fields corresponding to all input parameters.

[0051] Here, all the fields corresponding to the input parameters can be assembled into an intermediate structure (struct). Among them, the intermediate structure is used to represent the input parameters of the target function through fields. For Go functions, the intermediate structure can be understood as a Go struct, in which the input parameters of the target function are encapsulated through fields.

[0052] It should be understood that each field in the intermediate structure corresponds to an input parameter of the target function, and each field is used to store and manage the value of the input parameter. In Go, reflect.StructOf is used to dynamically create the intermediate structure, and fields are defined through reflect.StructField and added to the intermediate structure.

[0053] It is worth noting that when the target function is a Go function, the intermediate structure can refer to a Go struct, which represents a data structure that can be directly input into the Go function. Essentially, it maps the input parameters of the Go function to the fields in the intermediate structure.

[0054] In step 203, a data description is generated according to the intermediate structure.

[0055] Here, a data description corresponding to the function tool is generated according to the intermediate structure assembled from the fields. Among them, the data description is used to describe the input parameter structure of the target function. The data description essentially describes the data structure and constraints of the input parameters of the target function through the definition of the intermediate structure. When it is necessary to convert the first parameter to the second parameter, a corresponding intermediate structure is constructed through the data description, and then the first parameter is mapped to the corresponding second parameter through the intermediate structure.

[0056] Exemplarily, when the data format of the first parameter is JSON, the data description can be JSON Schema. That is to say, the intermediate structure can be converted into JSON Schema. JSON Schema is a language used to describe JSON data structures, and JSON Schema can be used to define information such as the type, format, and constraints of JSON data.

[0057] It should be noted that the JSONSchema corresponding to the intermediate structure can be generated by reflecting through the JSON Schema library, and this JSON Schema is used to describe the input parameter structure of the function tool.

[0058] It is worth noting that by generating the intermediate structure and data description (such as JSON Schema), automatic mapping between the first parameter output by the large language model and the second parameter of the target function can be achieved.

[0059] In step 204, based on the data description, a function tool corresponding to the objective function is constructed.

[0060] Here, after obtaining the corresponding data description, a function tool can be constructed based on the data description. Among them, in the function tool, the objective function will be injected into the structure of the function tool, so that the function tool can convert the first parameter output by the large language model into the second parameter that can be input into the objective function corresponding to the function tool, and based on the second parameter, call the objective function to obtain the call result.

[0061] In some embodiments, the attribute information of the function tool can be generated according to the function annotation information of the objective function, and the function tool corresponding to the objective function can be constructed according to the attribute information of the function tool and the data description.

[0062] Among them, the attribute information can at least include at least one of the tool name, tool description, and tool parameter name. The tool name is the unique identifier of the tool, used to distinguish different tools in the system. The tool description is a detailed description of the tool function, helping users understand the role and usage scenario of the tool. The tool description can include information such as the main function, input and output, and usage method of the tool. The tool parameter name is the identifier of the tool input parameter, used to pass specific values when calling the tool. It should be noted that the tool parameter name can refer to the user-defined parameter name. If the user does not define the tool parameter name, the parameter name in the objective function can be used as the tool parameter name by default.

[0063] Continuing with the above implementation manner, the function annotation information can be a kind of parameter information of the input parameter. Therefore, the function annotation information of the objective function can be obtained by abstract syntax tree extraction. The attribute information of the function tool can be understood as the metadata of the function tool. In the embodiments of the present disclosure, the metadata of the function tool is dynamically defined through the function annotation information, so that the metadata of the function tool can be quickly modified, improving the convenience of function tool plug-in.

[0064] It is worth noting that the constructed function tool can implement a general tool interface and can be uniformly managed and called in different frameworks or systems. Moreover, the Call method in the function tool can receive the first parameter (such as Function Call JSON parameter) of the original output of the large language model to convert the first parameter into the second parameter that can be directly input into the objective function.

[0065] Thus, through the above steps 201 to 204, by dynamically generating intermediate structures and data descriptions, not only can the automatic mapping between the first parameter of the large language model and the second parameter of the target function be achieved, but also the parameter names can be accurately extracted through the abstract syntax tree. For developers, they only need to write the corresponding business functions without having to handle complex parameter parsing and mapping, which can greatly reduce the amount of code development. Additionally, by automatically generating data descriptions, manual errors can be reduced, and complex types such as multi-layer nested structures and slices can be supported. Moreover, by defining the metadata of the function tool through function annotation messages, the convenience of plugging and unplugging the function tool can also be improved.

[0066] In some implementable embodiments, in step 110, an intermediate structure can be constructed according to the data description, and based on the intermediate structure, the first parameter output by the large language model can be deserialized to obtain the second parameter.

[0067] Here, continuing with the above embodiments, the function tool includes a data description, and the definition of this data description can refer to the relevant descriptions of the above embodiments and will not be elaborated here.

[0068] Through the data description (JSON Schema) in the function tool, an intermediate structure can be dynamically constructed, and the intermediate structure can be used to deserialize the first parameter output by the large language model to obtain the second parameter. It should be understood that the second parameter at this time is represented by the fields deserialized through the intermediate structure.

[0069] Correspondingly, in step 110, the second parameter can be sequentially mapped to the input parameters of the target function through reflection to obtain the call result output by the function tool.

[0070] Among them, since the second parameter is represented by the fields deserialized through the intermediate structure, the fields of the deserialized intermediate structure can be used as reflection to call the input parameters of the target function. When calling the input parameters of the target function, the second parameter is sequentially mapped to the input parameters of the target function so that the target function in the function tool can obtain the corresponding call result through the second parameter. For example, the field values of the intermediate structure can be sequentially mapped to the input parameters of the target function through reflection (reflect.Value.Call) to complete the call of the target function.

[0071] Thus, through the above embodiments, the function tool can achieve the function of automatically converting the first parameter output by the large language model into the second parameter that can be input into the corresponding target function of the function tool.

[0072] In some implementable embodiments, in step 110, according to the tool name of the function tool that the large language model needs to call, the function tool corresponding to the tool name is called from the tool list of the agent.

[0073] Here, the function tool is registered in the tool list of the agent (Agent). For example, following the above embodiments, after constructing the corresponding function tool through steps 201 to 204, the function tool can be registered in the tool list of the Agent so that the large language model can call the function tool in the Agent.

[0074] When the large language model determines the function tool to be called, it can call the function tool corresponding to the tool name from the tool list of the Agent through the tool name of the function tool that the large language model needs to call. Among them, the called function tool is used to convert the first parameter output by the large language model into the second parameter that can be input to the target function corresponding to the function tool, and based on the second parameter, call the target function to obtain the call result output by the function tool. The call result of the function tool is returned to the large language model in the form of a function message, and the large language model splices the function message into the prompt word, and obtains the output result of the large language model through the spliced prompt word.

[0075] Thus, the large language model can call the function tool through the Agent framework. Moreover, since the function tool registered in the Agent can automatically convert the first parameter output by the large language model into the second parameter that can be input to the target function corresponding to the function tool, the development complexity of the Agent is greatly reduced.

[0076] The following combines the attached Figure 3 and the attached Figure 4 to detail the tool call method provided by the embodiments of the present disclosure.

[0077] Figure 3 is a flowchart showing the construction of a function tool according to another exemplary embodiment. As Figure 3 shown, the function tool can be constructed through the following steps: S301, through reflection and runtime, obtain the function name of the target function and the relative path of the package where the target function is located; S302, according to the relative path, parse all the source code of the package where the target function is located to obtain the abstract syntax tree of the target function; S303, traverse the abstract syntax tree and determine the function declaration corresponding to the target function through the function name; S304. Traverse each input parameter in the parameter list of the function declaration, construct the parameter information of the input parameter into fields, and assemble the fields of all input parameters into an intermediate structure; wherein, the parameter information includes the parameter name and the parameter type. S305. Generate a data description according to the intermediate structure; wherein, if the target function is a Go function, the intermediate structure is a Go structure and the data description is a JSON Schema. S306. Generate the attribute information of the function tool according to the function comment information obtained from the function declaration. S307. Construct the function tool according to the attribute information of the function tool and the data description.

[0078] Figure 4 is a flowchart of tool calls shown according to an exemplary embodiment. As Figure 4 shown, the function tool constructed through Figure 3 is registered in the Agent, including the tool name, tool description, and tool parameter name (metadata) that provide the function tool. When the user sends a request to the Agent, the prompt word and the metadata of the function tool are concatenated, and the large language model is called. The large language model determines whether to call the function tool. When it is necessary to call the function tool, according to the output of the large language model, the corresponding function tool is called by the tool name. An intermediate structure is constructed according to the JSON Schema in the function tool, and the first parameter output by the large language model is deserialized using the intermediate structure. The fields of the deserialized intermediate structure are used as reflections to call the input parameters of the target function, and the call result of the function tool is obtained. A function message is constructed according to the call result and concatenated into the prompt word, and then returned to the step of "concatenating the prompt word and the metadata of the function tool and calling the large language model", and the loop is executed until the large language model does not need to call the function tool. When the large language model does not need to call the function tool, the large language model obtains the output result corresponding to the request through the concatenated prompt word.

[0079] Figure 5 is a schematic structural diagram of a tool call device shown according to an exemplary embodiment. As Figure 5 shown, the present disclosure embodiment provides a tool call device 500, and the tool call device 500 includes: A call module 501, configured to call the function tool corresponding to the tool name according to the tool name of the function tool that the large language model needs to call, convert the first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter that can be input to the target function corresponding to the function tool, and based on the second parameter, call the target function to obtain the call result output by the function tool; wherein, the data description is used to describe the input parameter structure of the target function. A return module 502, configured to return the call result to the large language model, so that the large language model obtains an output result based on the call result.

[0080] Optionally, the tool call device 500 further includes: A first construction module, configured to construct a field corresponding to each input parameter in the target function according to the parameter information of the input parameter through reflection; A second construction module, configured to construct an intermediate structure based on the fields corresponding to all the input parameters, where the intermediate structure is used to represent the input parameters of the target function through the fields; A generation module, configured to generate the data description according to the intermediate structure; A third construction module, configured to construct a function tool corresponding to the target function based on the data description.

[0081] Optionally, the tool call device 500 further includes: A parsing module, configured to parse the source code of the target function to obtain an abstract syntax tree of the target function; A determination module, configured to determine a function declaration of the target function based on the abstract syntax tree; A traversal module, configured to traverse a parameter list in the function declaration to obtain parameter information of each input parameter in the target function.

[0082] Optionally, the third construction module is specifically configured to: Generate attribute information of the function tool according to the function annotation information of the target function; Construct a function tool corresponding to the target function according to the attribute information of the function tool and the data description.

[0083] Optionally, the call module 501 is specifically configured to: Construct an intermediate structure according to the data description, where the intermediate structure is used to represent the input parameters of the target function through fields; Deserialize a first parameter output by the large language model based on the data description corresponding to the function tool based on the intermediate structure to obtain the second parameter.

[0084] Optionally, the call module 501 is specifically configured to: Sequentially map the second parameter to the input parameters of the target function through reflection to obtain a call result output by the function tool.

[0085] Optionally, the calling module 501 is specifically configured to: According to the tool name of the function tool that needs to be called by the large language model, call the function tool corresponding to the tool name from the tool list of the agent, where the function tool is registered in the tool list of the agent.

[0086] Regarding the tool calling device 500 in the above embodiments, the method logics executed by each functional module have been described in detail in the part about the method, and will not be elaborated here.

[0087] Next, refer to Figure 6 , which shows a schematic structural diagram of an electronic device (such as a terminal device or a server) 600 suitable for implementing the embodiments of the present disclosure. The terminal devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Tablet Computers), PMPs (Portable Multimedia Players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 6 The electronic device shown is only an example and should not impose any limitations on the functions and usage scopes of the embodiments of the present disclosure.

[0088] As Figure 6 shown, the electronic device 600 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 601, which may perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage device 608 into the random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 600 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other through a bus 604. The input / output (I / O) interface 605 is also connected to the bus 604.

[0089] Generally, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 600 to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 6 shows the electronic device 600 having various devices, it should be understood that it is not required to implement or have all the shown devices. Instead, more or fewer devices may be implemented or had.

[0090] In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present disclosure includes a computer program product that includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes program code for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 609, or installed from the storage device 608, or installed from the ROM 602. When the computer program is executed by the processing device 601, the above-described functions defined in the methods of the embodiments of the present disclosure are performed.

[0091] It should be noted that the above computer-readable medium in the present disclosure can be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection having 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), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. And in the present disclosure, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, in which computer-readable program code is carried. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, and the computer-readable signal medium can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0092] In some embodiments, the client and the server can communicate using any currently known or future-developed network protocol such as HTTP (HyperText Transfer Protocol), and can be interconnected with digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include local area networks ("LAN"), wide area networks ("WAN"), the Internet (e.g., the Internet), and end-to-end networks (e.g., ad hoc end-to-end networks), as well as any currently known or future-developed network.

[0093] The above computer-readable medium can be included in the above electronic device; it can also exist separately without being assembled into the electronic device.

[0094] The above computer-readable medium carries one or more programs. When the above one or more programs are executed by the electronic device, the electronic device is caused to: call the function tool corresponding to the tool name according to the tool name of the function tool required to be called by the large language model, convert the first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter that can be input into the target function corresponding to the function tool, and based on the second parameter, call the target function to obtain the call result output by the function tool; wherein the data description is used to describe the input parameter structure of the target function; return the call result to the large language model so that the large language model can obtain an output result based on the call result.

[0095] Computer program code for performing the operations of the present disclosure can be written in one or more programming languages or combinations thereof. The above programming languages include, but are not limited to, object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (e.g., by using an Internet service provider to connect through the Internet).

[0096] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a segment of a program, or a part of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions noted in the blocks may occur in a different order than noted in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system that performs the specified functions or operations, or by a combination of dedicated hardware and computer instructions.

[0097] The modules described in the embodiments of the present disclosure can be implemented in software or in hardware. In some cases, the name of the module does not constitute a limitation on the module itself.

[0098] The functions described above in this document can be performed at least in part by one or more hardware logic components. By way of example and not limitation, exemplary types of hardware logic components that can be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system on a chip (SOCs), complex programmable logic devices (CPLDs), and the like.

[0099] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0100] The above description is only a preferred embodiment of the present disclosure and an explanation of the applied technical principles. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosure concept. For example, the technical solutions formed by mutually replacing the above features with the technical features (but not limited to) having similar functions disclosed in the present disclosure.

[0101] In addition, although the operations are depicted in a particular order, this should not be construed as requiring that the operations be performed in the particular order shown or in sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features described in the context of separate embodiments may also be implemented in combination in a single embodiment. Conversely, the various features described in the context of a single embodiment may also be implemented separately or in any suitable sub-combination in multiple embodiments.

[0102] Although the subject matter has been described in language specific to structural features and / or methodological logical acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. On the contrary, the specific features and acts described above are merely example forms for implementing the claims. Regarding the apparatus in the above embodiments, the specific manner in which each module performs operations has been described in detail in the embodiments related to the method, and will not be elaborated here.

Claims

1. A tool invocation method, characterized in that, Including: The tool name of the function tool to be called according to the large language model, call the function tool corresponding to the tool name, convert the first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter that can be input into the target function corresponding to the function tool, and based on the second parameter, call the target function to obtain the call result output by the function tool; wherein, the data description is used to describe the input parameter structure of the target function; Return the call result to the large language model so that the large language model can obtain the output result based on the call result.

2. The method according to claim 1, wherein The function tool is obtained through the following steps: For each input parameter in the target function, according to the parameter information of the input parameter, construct the field corresponding to the input parameter through reflection; Based on all the fields corresponding to the input parameters, construct an intermediate structure, and the intermediate structure is used to represent the input parameters of the target function through the fields; Generate the data description according to the intermediate structure; Based on the data description, construct the function tool corresponding to the target function.

3. The method according to claim 2, wherein The parameter information of the input parameter is obtained through the following steps: Parse the source code of the target function to obtain the abstract syntax tree of the target function; Based on the abstract syntax tree, determine the function declaration of the target function; Traverse the parameter list in the function declaration to obtain the parameter information of each input parameter in the target function.

4. The method according to claim 2, characterized in that The constructing the function tool corresponding to the target function based on the data description includes: Generate the attribute information of the function tool according to the function annotation information of the target function; Construct the function tool corresponding to the target function according to the attribute information of the function tool and the data description.

5. The method according to any one of claims 1 to 4, characterized in that The converting the first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter that can be input into the target function corresponding to the function tool includes: Construct an intermediate structure according to the data description, and the intermediate structure is used to represent the input parameters of the target function through fields; Based on the intermediate structure, deserialize the first parameter output by the large language model based on the data description corresponding to the function tool to obtain the second parameter.

6. The method according to claim 5, wherein The calling the target function based on the second parameter to obtain the call result output by the function tool includes: Sequentially map the second parameter to the input parameters of the target function through reflection to obtain the call result output by the function tool.

7. The method according to any one of claims 1 to 4, characterized in that, The calling the function tool corresponding to the tool name according to the tool name of the function tool required to be called by the large language model includes: According to the tool name of the function tool required to be called by the large language model, call the function tool corresponding to the tool name from the tool list of the proxy, wherein the function tool is registered in the tool list of the proxy.

8. A tool calling device, characterized in that, Including: A calling module, which is configured to call a function tool corresponding to the tool name according to the tool name of the function tool required by the large language model, convert a first parameter output by the large language model based on the data description corresponding to the function tool into a second parameter that can be input into the target function corresponding to the function tool, and based on the second parameter, call the target function to obtain a call result output by the function tool; wherein the data description is used to describe the input parameter structure of the target function. A returning module, which is configured to return the call result to the large language model so that the large language model can obtain an output result based on the call result.

9. A computer-readable medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processing device, it implements the steps of the method according to any one of claims 1-7.

10. An electronic device, characterized in that, Comprising: A storage device, on which a computer program is stored; A processing device, which is used to execute the computer program in the storage device to implement the steps of the method according to any one of claims 1-7.

11. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1-7.

Citation Information

Cited By

  • Visual arrangement method for model tool calling based on MCP

    CN120743252A