Large model function call optimization method based on code generation, electronic equipment, computer readable storage medium and computer program product

By leveraging semantic understanding and code generation to create large models, the order of function calls and dependencies are optimized, solving the efficiency and accuracy issues in function calls within large models and enabling efficient execution and resource optimization for complex tasks.

CN121455563APending Publication Date: 2026-02-03ZHONGHE TECHNOLOGY (XIONGAN) CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202511528359.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-10-24
Publication Date
2026-02-03

AI Technical Summary

Technical Problem

Existing large-scale model function call techniques suffer from limitations such as single-round call interaction, insufficient accuracy of function calls, and inadequate task decomposition capabilities, resulting in long response times, wasted computing resources, and frequent errors.

Method used

By using a large model of semantic understanding and code generation, user intent is analyzed to generate executable code, and a directed acyclic graph of function scheduling is constructed for optimization, enabling one-time code generation and parallel function calls, and optimizing the function call order and dependencies.

Benefits of technology

It significantly improves function call efficiency and accuracy, reduces system latency and computational costs, supports efficient decomposition and execution of complex tasks, and fully utilizes the programming capabilities of large models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121455563A_ABST
    Figure CN121455563A_ABST
Patent Text Reader

Abstract

The invention discloses a large model function call optimization method based on code generation, electronic equipment, a computer readable storage medium and a computer program product, and the method comprises the steps: adopting a semantic understanding large model, and converting a natural language intention of a user into an executable rule; generating codes meeting scene requirements by adopting a code generation large model; a function call optimization method is adopted to call the codes meeting the scene requirements; the optimization method comprises the steps of obtaining a call function set in codes meeting scene requirements; constructing a function scheduling directed acyclic graph by taking the calling functions as nodes and the dependency relationship between the two calling functions as edges based on the calling function set and the dependency relationship of each calling function; performing linear sorting and layering on each node in the function scheduling directed acyclic graph; the nodes at the same level have no direct or indirect dependency relationship; and executing the calling functions at the same level in parallel.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of large model function calling, and particularly relates to a large model function calling optimization method based on code generation, an electronic device, a computer readable storage medium and a computer program product. BACKGROUND

[0002] With the rapid development of artificial intelligence technology, large models are increasingly widely used in various fields. The function call capability of large models enables them to interact with external tools and services, and has rich applications in scenarios such as financial intelligent customer service and user service, e-commerce and local life service, Internet of Things and smart home control. However, the existing large model function calling technology has the following key problems in actual application: (1) Single round of calling interaction restriction: Most large model systems can only call one function in one round of interaction, such as complex tasks that need multiple function calls in financial intelligent customer service applications, which must be implemented through multiple dialogues, and each call requires complete context. This limitation significantly increases response time, reduces task execution efficiency, and causes waste of computing resources.

[0003] (2) Insufficient function call accuracy: In existing technologies, large models have great uncertainty in understanding function parameters, selecting appropriate functions, and determining calling order, which can easily result in incorrect function calls or parameter passing.

[0004] (3) Task decomposition capability limitation: When facing complex tasks such as financial intelligent customer service, the task needs to be decomposed into multiple sub-tasks, each corresponding to a specific function call. Traditional methods lack effective task decomposition and execution flow planning capabilities, making it difficult to handle tasks with complex dependency relationships.

[0005] Existing technologies mainly rely on direct function call interfaces and multi-round dialogue mechanisms, and lack sufficient utilization of large model programming capabilities. Research shows that many large models perform well in code generation tasks, with strong programming logic understanding and code construction capabilities, but this advantage has not been effectively utilized in function calling. SUMMARY

[0006] The application aims to solve the defects of existing function calling methods when facing complex tasks such as financial intelligent customer service. The application proposes a large model function calling optimization method based on code generation, an electronic device, a computer readable storage medium and a computer program product.

[0007] Technical solution: In a first aspect, the application proposes a large model function calling optimization method based on code generation, including: According to the application scene, through the definition of variables, condition judgment and parameter passing, the semantic understanding large model is used to analyze and convert the natural language intention of the user to obtain executable rules; The code generation large model is used to generate code meeting the scene requirements according to the executable rules; The function call optimization method is used to optimize the code meeting the scene requirements, and the final result meeting the scene requirements is output by executing the optimized code; The function call optimization method includes the following steps: Step 1: obtaining a set of calling functions in the code meeting the scene requirements; Step 2: based on the set of calling functions and the dependency relationship of each calling function, a function scheduling directed acyclic graph is constructed with the calling function as the node and the dependency relationship between two calling functions as the edge; Step 3: linearly sorting and layering each node in the function scheduling directed acyclic graph, ensuring that any directed edge f j → f i , the node f j are arranged before f i ; the nodes located in the same level have no direct or indirect dependency relationship; The execution of the optimized code includes: parallel execution of the calling functions located in the same level.

[0008] Further, when the task to be completed is financial intelligent customer service, the set of calling functions required includes real-time data query calling function, business information analysis calling function, natural language processing calling function, compliance detection calling function and log audit calling function.

[0009] Further, the dependency relationship includes: the output of a calling function is the input dependency of another calling function, and in the execution process, the calling function must be completed before executing another calling function.

[0010] Further, in step 3, the linear sorting and layering of each node in the function scheduling directed acyclic graph includes: The in-degree of all nodes in the function scheduling directed acyclic graph is calculated, and the in-degree is the number of edges pointing to the node; the level of all nodes is initialized to 0; All nodes with an in-degree of 0 are added to the initial queue; Take the head node from the initial queue, add it to the linear ordering result list, traverse all direct successor nodes of the node, reduce the in-degree of the direct successor nodes by 1, and update the level of the direct successor nodes to the larger value between the current level and the level of the node + 1; for the updated direct successor nodes, if the in-degree becomes 0, add them to the initial queue; repeat the step until the initial queue is empty; until the length of the linear ordering result list is equal to the total number of nodes in the function scheduling directed acyclic graph, the sorting is successful.

[0011] Further, if the length of the linear ordering result list is not equal to the total number of nodes in the function scheduling directed acyclic graph, it indicates that there is a loop in the function scheduling directed acyclic graph, the dependency relationship of each calling function is rechecked, and the function scheduling directed acyclic graph is reconstructed.

[0012] Further, the parallel execution of calling functions at the same level includes: Defining a complex condition, dividing the nodes in the function scheduling directed acyclic graph into complex nodes and non-complex nodes; Taking the complex node as the starting point, recursively tracing all predecessor dependent nodes with a path length not exceeding a set value, and defining the predecessor dependent nodes as a complex subgraph node set of the complex node; When parallel executing calling functions at the same level, for complex nodes therein, taking all outputs of the complex subgraph node set of the complex node as input parameters of the complex node; for non-complex nodes therein, taking the outputs of the direct predecessor node set of the non-complex node as input parameters of the non-complex node.

[0013] Further, the complex condition includes: the number of input parameters of the calling function is greater than a set number or the historical average execution time of the calling function is greater than a set time.

[0014] In a second aspect, the present application provides an electronic device, which includes: at least one processor; and a memory in communication connection with the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute a large model function call optimization method based on code generation.

[0015] In a third aspect, the present application provides a computer readable storage medium, which stores computer instructions for enabling a processor to implement a large model function call optimization method based on code generation when executed.

[0016] Fourthly, the present invention proposes a computer program product, which includes a computer program that, when executed by a processor, implements a large model function call optimization method based on code generation.

[0017] Beneficial Effects: This invention provides an innovative solution for the efficient execution of complex tasks by deeply integrating the code generation capability of large models with the function call mechanism. Compared with existing technologies, this invention has the following advantages: (1) Significantly improves execution efficiency. The traditional single-round, single-function-call pattern requires multiple model inferences for complex tasks, significantly increasing system latency and computational costs. This invention introduces a code generation mechanism, replacing multiple rounds of function calls with a single code generation, reducing the number of model inferences in the traditional scheme to a maximum of 10, where 1 is the number of function calls required for the task, enabling the generation of a complete task execution plan with a single inference. In typical complex task scenarios, this significantly reduces the number of model calls, greatly improves execution efficiency, and reduces system latency and computational costs.

[0018] (2) Enhance the accuracy of function calls. Direct function calls rely on the model's understanding of function semantics, which can easily lead to parameter errors or disordered call order. This invention utilizes the powerful programming logic understanding capabilities of the large model to ensure the syntactic correctness and logical consistency of function calls through code generation, transforming ambiguous natural language intentions into precise program logic. Compared with the direct function call method, the accuracy of the call sequence is greatly improved.

[0019] (3) Supports complex task decomposition and execution. This invention supports parallel function calls. By automatically planning steps and managing parameters, it effectively improves the efficiency and flexibility of function calls and solves the limitation of traditional agents calling functions once per round of dialogue.

[0020] (4) Existing technologies lack effective modeling of task dependencies and dynamic planning of execution processes. This invention realizes automatic decomposition of complex tasks and optimal execution path planning by constructing a task scheduling topology graph.

[0021] (5) The present invention can make full use of the advantages of code generation of large models, significantly improve the efficiency, accuracy and task processing capabilities of function calls, and provide an efficient technical solution for the application of large models in complex application scenarios, including but not limited to financial intelligent customer service scenarios. Attached Figure Description

[0022] Figure 1 This is a flowchart of a large model function call optimization method based on code generation proposed in this invention. Detailed Implementation

[0023] In order to make the purpose, technical solutions and advantages of the present application clearer, a code generation-based large model function call optimization method proposed by the present application will be further described below in combination with the drawings in the present application.

[0024] Embodiment one: Taking a financial intelligent customer service application as an example, the user asks: "Help me check which of the financial products I bought in the last 3 months are low-risk, and calculate how much money I can get after deducting the service fee if I redeem them now, and can I use the coupons in my account to deduct the service fee?". In the face of this user question, the traditional single-round single-function call mode needs to call "user holding query function", "product risk level query function", "redemption amount calculation function", "coupon application scope query function" and various specific information confirmation "follow-up function" these 5 functions.

[0025] To solve the efficiency and accuracy problem in large model function call technology, the embodiment of the present application proposes a function call optimization method based on code generation, mainly including the following steps: Step 1: Based on the analysis of user intent by large model, the code converts the imprecise natural language intent into machine executable rules through explicit variable definition, condition judgment and parameter passing: for example, "the last 3 months" can be converted to start_date = end_date - timedelta(days=90) (accurate to day, including the beginning and end), "low-risk" can be converted to risk_levels[h["product_id"]] in ["R1", "R2"] (binding the risk level code of the financial industry standard) and so on. The large model used in this step is a text understanding large model, including but not limited to: Qwen3-Max-Preview.

[0026] Step 2: A complete Python code containing "data query, risk screening, amount calculation, coupon verification" is generated by the large model according to the user intent obtained by analysis. The large model used in this step is a code generation large model, including but not limited to Qwen3-Coder.

[0027] Step 3: The generated code is optimized by the function call optimization method, and the optimized code is run once to automatically call all functions and output the final result. The whole process only needs 1 model inference, reducing the traditional O ( n ) times of inference to O (1) times.

[0028] The implementation process of the function call optimization method is described in detail as follows: S100: Construct function scheduling directed graph. The specific operation includes: assuming that the function set is called Each function accepts parameters and returns results , that is .

[0029] According to the dependency relationship of the function, a directed acyclic graph (DAG) is constructed . Each node represents a function , and each edge represents that the output of the function is the input dependency of , that is, must be completed before can be executed. That is .

[0030] S200: Linearly sort the nodes in the directed acyclic graph G , that is, topological sorting, to ensure that for any directed edge , node is arranged before , to provide a basic constraint for function call order. In the embodiment of the application, not only is the topological sorting completed, but also the layering of each node is completed. The specific operation includes: S201: Modify the Kahn algorithm based on breadth-first search (BFS) to realize linear sorting; including: initializing the in-degree and level of the node. Including: calculating the in-degree (the number of edges pointing to node ) of all nodes in G , and initializing the level of all nodes to 0, and adding all nodes with an in-degree of 0 to the initial queue Q .

[0031]

[0032]

[0033]

[0034] Among them, represents the in-degree of node v, represents the level of node v.

[0035] S202: Iteratively process nodes and update in-degree. Including: taking the head node v from the queue Q , adding it to the topological sorting result list T . Then traverse the nodev All direct successor nodes u (i.e., satisfy) ),Will u minus 1 (meaning) v Processing completed, restrictions lifted. u A dependency), u The level is updated to the current level and v The larger value between the level + 1.

[0036]

[0037]

[0038]

[0039]

[0040] in, Represents a node v The set of direct successor nodes.

[0041] S203: Add the successor node with an in-degree of 0 to the queue, i.e., the updated successor node. u If its in-degree becomes 0 (all prerequisites have been processed), then add it to the queue. Q .

[0042]

[0043] S204: Termination condition and result verification, i.e., repeating S201 and S202 until the queue is reached. Q The list is empty. If the topological sort result list is empty at this point... T The length is equal to G Total number of middle nodes If the sorting is successful, then the sorting is successful; otherwise, it means... G The presence of a cycle in the data does not conform to the definition of a Directed Acyclic Graph (DAG), and the functional dependencies need to be checked.

[0044]

[0045] S300: Function subtask partitioning. Specifically includes: S301: Subgraph Recognition. The core of subgraph recognition is to identify subgraphs from the global graph. G Extract complex function dependencies that have independent execution capabilities. First, predefine function nodes. v Is it a complex judgment function? :

[0046] in, function node v The set of parameters, is the number of input parameters of function node v is the average execution time of function node v . Node v is complex if the number of input parameters is greater than 5 or the average execution time is greater than 100 milliseconds.

[0047] S302: DFS dependency tracing. Including: starting from complex function node v , recursively trace all its predecessor dependency nodes with depth-first search (DFS) whose path length is no more than D (the default value is 2). Define the complex subgraph node set of function node v as :

[0048] wherein, is the number of edges of the shortest path from function node v to its predecessor dependency node u .

[0049] The corresponding complex subgraph edge set and complex subgraph are expressed as:

[0050]

[0051] S400: Function call parallel strategy. Specifically includes: According to the hierarchical division rule, in the task set L of the same level , any two nodes have no direct or indirect dependency relationship (if there is a dependency, the level must be different).

[0052]

[0053] For any function node in the task set v , it can be executed in parallel to improve efficiency, which is divided into two types according to the different parameter input methods: (1) Function node v is complex, and the other predecessor dependency node set in the complex subgraph node set has completed execution. Since v is closely related to all predecessor dependency nodes, when executing function node v , all outputs of need to be taken as input parameters.​

[0054]

[0055] (2) Function node v is not complex, only considering the function node v and the set of immediate predecessor nodes dependence, so when the function node v , the output of the input parameters .

[0056]

[0057] Topological sorting and hierarchical time complexity is , the time complexity of parallel execution is the sum of the maximum execution time of each level , better than the time complexity of serial execution .

[0058] The above user question can be extended to more general and more complex problems (involving a larger number of function calls, different function calls have dependencies between each other).

[0059] Embodiment two: The embodiment discloses a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to realize the steps disclosed in any one of the above embodiments.

[0060] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing related hardware, and the computer program can be stored in a non-volatile computer readable storage medium. When the computer program is executed, it can include the processes of the above-mentioned embodiments. Any reference to memory, storage, database or other medium used in each embodiment provided by the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (Read-Only Memory, ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc.

[0061] Any combination of the technical features in the above embodiments can be made, and for the sake of brevity, not all possible combinations are described above, however, as long as the combination of the technical features does not exist in contradiction, it shall be considered within the scope of the present disclosure.

[0062] The above embodiments only express several implementation manners of the present application, and the description is relatively specific and detailed, but it shall not be understood as a limitation on the patent scope of the present application. It shall be pointed out that, for ordinary skilled persons in the art, several modifications and improvements can be made without departing from the concept of the present application, and these shall be within the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the appended claims.

Claims

1. A method for optimizing function calls in large models based on code generation, characterized in that: include: Based on the application scenario, through clear variable definition, condition judgment and parameter passing, a semantic understanding big model is used to analyze and transform the user's natural language intent to obtain executable rules. The code generation model uses executable rules to generate code that meets the requirements of the scenario. The code that meets the requirements of the scenario is optimized by using function call optimization methods. By executing the optimized code, the final result that meets the requirements of the scenario is output. The function call optimization method includes the following steps: Step 1: Obtain the set of called functions in the code that meets the requirements of the scenario; Step 2: Based on the set of called functions and the dependencies between each called function, construct a directed acyclic graph for function scheduling, with each called function as a node and the dependencies between two called functions as edges. Step 3: Perform linear sorting and layering of the nodes in the directed acyclic graph of the function scheduling, ensuring that for any directed edge... f j → f i Node f j All ranked in f i Previously, nodes at the same level had no direct or indirect dependencies. The optimized code execution includes: executing call functions at the same level in parallel.

2. The method for optimizing large model function calls based on code generation according to claim 1, characterized in that: The application scenario is intelligent customer service in the financial sector.

3. The method for optimizing large model function calls based on code generation according to claim 1, characterized in that: The dependencies include: the output of one function call is the input of another function call, and during execution, one function call must be completed before the other function call can be executed.

4. The method for optimizing large model function calls based on code generation according to claim 1, characterized in that: Step 3, which involves linearly sorting and layering the nodes in the directed acyclic graph of the function scheduling, specifically includes: The function schedules the in-degree of all nodes in the directed acyclic graph, where the in-degree is the number of edges pointing to the node; the level of all nodes is initialized to 0. Add all nodes with an in-degree of 0 to the initial queue; Take the head node from the initial queue and add it to the linearly sorted result list. Iterate through all the direct successor nodes of the head node, decrement the in-degree of each direct successor node by 1, and update the level of each direct successor node to the larger value between the current level and the node's level + 1. For each updated direct successor node, if its in-degree becomes 0, add it to the initial queue. Repeat this step until the initial queue is empty. The sorting is successful when the length of the linearly sorted result list equals the total number of nodes in the directed acyclic graph scheduled by the function.

5. The method for optimizing large model function calls based on code generation according to claim 4, characterized in that: If the length of the linear sorting result list is not equal to the total number of nodes in the function scheduling directed acyclic graph, it indicates that a cycle exists in the function scheduling directed acyclic graph. The dependencies of each called function should be re-examined, and the function scheduling directed acyclic graph should be reconstructed.

6. The method for optimizing large model function calls based on code generation according to claim 1, characterized in that: The parallel execution of called functions at the same level specifically includes: Define complex conditions to classify nodes in the directed acyclic graph of function scheduling into complex nodes and non-complex nodes; Starting from a complex node, recursively trace all its predecessor dependent nodes whose path length does not exceed a set value, and define the predecessor dependent nodes as the set of complex subgraph nodes of the complex node. When executing called functions at the same level in parallel, for complex nodes, the outputs of all nodes in the complex subgraph of the complex node are used as the input parameters of the complex node; for non-complex nodes, the outputs of the set of the direct predecessor nodes of the non-complex node are used as the input parameters of the non-complex node.

7. The method for optimizing large model function calls based on code generation according to claim 6, characterized in that: The complex conditions include: the number of input parameters for the function call is greater than a set number, or the historical average execution time of the function call is greater than a set time.

8. An electronic device, characterized in that, The electronic device includes: At least one processor; and a memory communicatively connected to the at least one processor; The memory stores a computer program that can be executed by the at least one processor, which is then executed by the at least one processor to enable the at least one processor to perform a large model function call optimization method based on code generation as described in any one of claims 1-7.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the large model function call optimization method based on code generation as described in any one of claims 1-7.

10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements a large model function call optimization method based on code generation as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Code optimization scheduling method for encoder

    CN105843660A

  • Knowledge graph-based large model task calling execution method and device

    CN118963869A

  • Tool calling method and device, equipment, storage medium and program product

    CN120011578A

  • Context sensing code generation and real-time optimization method and system based on large language model

    CN120523448A

  • Code generation method and system based on artificial intelligence

    CN120803432A