CN-122027396-A - Tool calling method and device
Abstract
One or more embodiments of the present disclosure provide a tool calling method and apparatus. The gateway system can receive a dialogue request sent by a client to a target request gateway through a tool calling method applied to the gateway system, forward the dialogue request to an upper gateway step by step through a hierarchical relation of a target gateway chain, add tools configured by the forwarding gateway to a first tool list corresponding to the dialogue request in each forwarding process until the tools are forwarded to a root gateway to obtain an aggregation tool set, then send the dialogue request and the aggregation tool set to a model service platform through the root gateway so that the model service platform generates a first tool calling instruction based on the dialogue request and the aggregation tool set and returns the first tool calling instruction to the gateway system, and send a first calling result to the model service platform and acquire a request result of the dialogue request from the model service platform based on the first tool calling instruction.
Inventors
- ZHANG QICHAO
- WANG ZIJIE
- LI JINYAN
Assignees
- 蚂蚁区块链科技(上海)有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260126
Claims (10)
- 1. A tool calling method, characterized by being applied to a gateway system, wherein the gateway system comprises a root gateway and at least one gateway chain connected with the root gateway, each gateway chain comprises at least one hierarchical sub-gateway, and the method comprises: Receiving a dialogue request sent by a client to a target request gateway, wherein the target request gateway is a gateway of a target gateway chain in the at least one gateway chain; Forwarding the dialogue request to an upper gateway step by step through the target request gateway based on the hierarchical relation of the target gateway chain, and adding a tool configured by the forwarding gateway to a first tool list corresponding to the dialogue request in each forwarding process until forwarding to the root gateway to obtain an aggregation tool set, wherein the root gateway and each sub-gateway are respectively configured with corresponding tools; Sending the dialogue request and the aggregation tool set to a model service platform through the root gateway so that the model service platform generates a first tool call instruction based on the dialogue request and the aggregation tool set and returns the first tool call instruction to the gateway system; and carrying out tool call based on the first tool call instruction, sending a first call result to the model service platform, and acquiring a request result of the dialogue request from the model service platform, wherein the request result is obtained by the model service platform based on the first call result.
- 2. The tool call method according to claim 1, wherein the performing tool call based on the first tool call instruction, and sending a first call result to the model service platform, includes: Forwarding the first tool calling instruction to a target execution node step by step through the root gateway based on the hierarchical relation of the target gateway chain, wherein the target execution node is configured with a first target tool designated by the first tool calling instruction; Calling the first target tool to obtain the first calling result based on the first tool calling instruction through the target executing node, and forwarding the first calling result to the root gateway step by step to an upper gateway based on the hierarchical relation of the target gateway chain; And sending the first calling result to the model service platform through the root gateway.
- 3. The tool call method according to claim 2, wherein forwarding the first tool call instruction to a target execution node by the root gateway to a lower gateway step by step based on a hierarchical relationship of the target gateway chain comprises: determining, by the root gateway and sub-gateways of each level, whether the first target tool is a self-configuring tool; determining a gateway configured with the first target tool as the target executing node in the case that the gateway configured with the first target tool exists in the root gateway and all hierarchical sub-gateways; in the event that there is no gateway configured with the first target tool in the root gateway and all hierarchical sub-gateways, the client is determined to be the target execution node.
- 4. The tool invocation method of claim 1, wherein the dialog request includes a second tool list of the client, the method further comprising: the second tool list is determined to be the first tool list.
- 5. The tool calling method according to claim 4, wherein the second tool list includes tools in the gateway system, and the adding the tools configured for the forwarding gateway to the first tool list corresponding to the session request includes: Determining whether tools configured by the forwarding gateway exist in the first tool list through the forwarding gateway; And adding the tool of the current forwarding gateway configuration to the first tool list under the condition that the tool of the current forwarding gateway configuration does not exist.
- 6. A tool invocation method for use with a model service platform configured with a large language model, the method comprising: receiving a dialogue request and an aggregation tool set sent by a gateway system; generating, by the large language model, a first tool call instruction based on the dialog request and the aggregate tool set; sending the first tool calling instruction to the gateway system so that the gateway system can make tool calling based on the first tool calling instruction and return a first calling result to the model service platform; generating a request result of the dialogue request based on the first calling result through the large language model; And sending the request result to the gateway system.
- 7. The tool call method of claim 6, wherein the generating a first tool call instruction based on the dialog request and the aggregate tool set comprises: analyzing the request information in the dialogue request to obtain M first execution tasks corresponding to the request information, wherein M is a positive integer; determining a first target tool from the aggregate tool set that completes each of the first execution tasks; First tool calling instructions corresponding to each first executing task and the corresponding first target tool are generated based on the first executing task and the corresponding first target tool.
- 8. The tool call method of claim 7, wherein the sending the first tool call instruction to the gateway system comprises: based on the execution sequence of the M first execution tasks, sending first tool calling instructions corresponding to each first execution task to the gateway system; the method for sending the first tool call instruction corresponding to the Nth first execution task to the gateway system comprises the following steps: a first tool calling instruction corresponding to the Nth first execution task is sent to the gateway system, wherein N is a positive integer smaller than or equal to M; receiving a first calling result corresponding to an Nth first execution task returned by the gateway system; when a first calling result corresponding to the Nth first executing task indicates that the tool call is successful and an undelivered first tool calling instruction exists, sending a first tool calling instruction corresponding to the (n+1) th first executing task to the gateway system; And ending sending a first tool calling instruction to the gateway system under the condition that a first calling result corresponding to the Nth first executing task indicates that the tool calling fails.
- 9. The tool call method of claim 6, wherein the generating the request result of the dialog request based on the first call result comprises: generating a second execution task based on the first call result and the request information; Determining a second target tool for completing the second execution task from the aggregation tool set, and generating a second tool call instruction based on the second execution task and the second target tool corresponding to the second execution task; sending the second tool calling instruction to the gateway system so that the gateway system can carry out tool calling based on the second tool calling instruction and return a second calling result to the model service platform; And generating the request result based on the first calling result and the second calling result.
- 10. An electronic device, the electronic device comprising: a memory for storing a computer program product; A processor for executing the computer program product stored in the memory and which, when executed, implements the tool call method of any one of the preceding claims 1 to 5 or claims 6 to 9.
Description
Tool calling method and device Technical Field One or more embodiments of the present disclosure relate to the field of computer technology, and in particular, to a tool calling method and apparatus. Background With the development of artificial intelligence technology, the application of a large language model (Large Language Model, LLM) is increasingly wide, and the integration of the large language model and an external tool has become an important research direction for expanding the application boundary of the model and supporting the execution of complex tasks, so that the large language model is widely applied to multiple scenes such as intelligent interaction, request processing and the like. In a multi-domain collaborative application scenario, external tools are usually provided independently by different domains, presenting a huge number and variety of features, making it difficult for large language models to efficiently aggregate and invoke these decentralized tools. Meanwhile, the interaction flow of the client is complex, and the flexibility and expandability of tool call are difficult to adapt to the complex scene requirements. Accordingly, there is a need to provide a more efficient tool invocation scheme to accommodate the intelligent invocation requirements in a multi-domain tool decentralized environment. Disclosure of Invention In order to efficiently aggregate multi-domain decentralized tools, flexibility, expandability and reliability of model calling tools are improved, and interaction complexity of clients is reduced. In a first aspect, one or more embodiments of the present specification provide a tool calling method applied to a gateway system, the gateway system including a root gateway and at least one gateway chain connected to the root gateway, each gateway chain including at least one hierarchical sub-gateway, the method comprising: Receiving a dialogue request sent by a client to a target request gateway, wherein the target request gateway is a gateway of a target gateway chain in the at least one gateway chain; Forwarding the dialogue request to an upper gateway step by step through the target request gateway based on the hierarchical relation of the target gateway chain, and adding a tool configured by the forwarding gateway to a first tool list corresponding to the dialogue request in each forwarding process until forwarding to the root gateway to obtain an aggregation tool set, wherein the root gateway and each sub-gateway are respectively configured with corresponding tools; Sending the dialogue request and the aggregation tool set to a model service platform through the root gateway so that the model service platform generates a first tool call instruction based on the dialogue request and the aggregation tool set and returns the first tool call instruction to the gateway system; and carrying out tool call based on the first tool call instruction, sending a first call result to the model service platform, and acquiring a request result of the dialogue request from the model service platform, wherein the request result is obtained by the model service platform based on the first call result. In a possible implementation manner, the performing tool call based on the first tool call instruction, and sending a first call result to the model service platform, includes: Forwarding the first tool calling instruction to a target execution node step by step through the root gateway based on the hierarchical relation of the target gateway chain, wherein the target execution node is configured with a first target tool designated by the first tool calling instruction; Calling the first target tool to obtain the first calling result based on the first tool calling instruction through the target executing node, and forwarding the first calling result to the root gateway step by step to an upper gateway based on the hierarchical relation of the target gateway chain; And sending the first calling result to the model service platform through the root gateway. In a possible implementation manner, the step-by-step forwarding, by the root gateway, the first tool call instruction to a lower gateway based on the hierarchical relationship of the target gateway chain, to a target execution node includes: determining, by the root gateway and sub-gateways of each level, whether the first target tool is a self-configuring tool; determining a gateway configured with the first target tool as the target executing node in the case that the gateway configured with the first target tool exists in the root gateway and all hierarchical sub-gateways; in the event that there is no gateway configured with the first target tool in the root gateway and all hierarchical sub-gateways, the client is determined to be the target execution node. In a possible implementation manner, the dialogue request includes a second tool list of the client, and the method further includes: the second tool list is determined to