An agent automatic construction method based on a large language model
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- JIANGXI YIYUAN MULTIMEDIA TECH
- Filing Date
- 2026-05-26
- Publication Date
- 2026-08-07
AI Technical Summary
若仅依靠人工经验构建智能体,容易出现工具选择不准确、工作流节点之间输入输出数据不匹配等问题
[0057]本发明通过大语言模型对原始自然语言任务进行任务语义解析,得到任务语义向量和任务约束集合,并基于任务语义向量在工具语义索引库中筛选候选工具集。由此,工具筛选不再依赖人工指定,而是依据任务语义向量与工具语义嵌入向量之间的相似度完成,使候选工具集能够与用户任务内容保持对应关系,并减少无关工具进入后续工作流生成过程;
Smart Images

Figure CN122526652A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large language models, specifically to a method for automatically constructing intelligent agents based on large language models. Background Technology
[0002] With the increasing capabilities of large language models in natural language understanding, task planning, and tool invocation, intelligent agents based on large language models are gradually being applied to scenarios such as intelligent customer service, data analysis, automated office work, code generation, and multi-tool collaborative processing. Intelligent agents typically need to identify the task intent based on the natural language task proposed by the user, select available tools, plan execution steps, and continuously advance the task based on context and tool return results during execution. Current intelligent agent construction processes usually require manually writing prompts, configuring tool invocation interfaces, designing workflow logic, and writing execution code. This construction process relies heavily on developer experience and is difficult to quickly adapt to different task scenarios.
[0003] In practical applications, user-input tasks often involve multiple constraints, such as security restrictions, output format limitations, tool invocation scope, and task boundaries. Relying solely on human experience to build intelligent agents can easily lead to problems like inaccurate tool selection and mismatches between input and output data across workflow nodes. Especially when task constraints are complex, how to automatically generate executable intelligent agents from natural language tasks and continuously refine the agent code based on feedback after execution is a pressing issue that needs to be addressed in current technologies. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention provides an automatic agent construction method based on a large language model, which solves the technical problems mentioned in the background by constructing an end-to-end agent with self-evolution capabilities.
[0005] To achieve the above objectives, the present invention provides the following technical solution:
[0006] An automatic agent construction method based on a large language model includes the following steps:
[0007] S1. Receive the natural language task and call the large language model to perform task semantic parsing on the original natural language task, generating task semantic vector and task constraint set;
[0008] S2. Based on the task semantic vector, perform semantic matching on multiple tools in the pre-built tool semantic index library to filter and obtain a candidate tool set;
[0009] S3. Generate a directed workflow graph based on the candidate toolset and the task constraint set, and perform data flow constraint verification and topology constraint verification on the directed workflow graph to generate a valid workflow graph;
[0010] S4. Generate agent source code based on the valid workflow graph; wherein, the agent source code includes an input module, an inference module, a memory module, a tool invocation module, and an execution output module;
[0011] S5. Run the source code of the agent in an isolated sandbox environment and collect the execution trajectory and feedback indicators during the execution process of the agent;
[0012] S6. Based on the execution trajectory and feedback indicators, iteratively optimize the source code of the agent until the convergence condition is met, and output the target agent instance.
[0013] In some specific embodiments, the generation of the task semantic vector and the task constraint set includes:
[0014] S1-1. Input the original natural language task into the large language model;
[0015] S1-2. Extract the task intent, task object, target output, and execution constraints from the original natural language task using the large language model.
[0016] S1-3. Encode the task intent and task object into a task semantic vector, and organize the target output and execution constraints into a task constraint set;
[0017] The task constraint set includes at least one or more of the following: security constraints, output format constraints, tool call constraints, and functional boundary constraints.
[0018] In some specific embodiments, the step of semantically matching multiple tools in a pre-built tool semantic index library to filter and obtain a candidate tool set includes:
[0019] S2-1. Obtain a pre-built tool semantic index library; wherein, the tool semantic index library includes multiple tools and the tool semantic embedding vectors corresponding to each tool;
[0020] S2-2. Calculate the semantic similarity between the semantic embedding vector of each tool and the semantic vector of the task, respectively.
[0021] ;
[0022] in, This represents the semantic similarity between the i-th tool and the task semantic vector. This represents the semantic embedding vector of the i-th tool. Represents the task semantic vector. express and The product of the L2 norms.
[0023] S2-3. Sort multiple tools in descending order according to semantic similarity to generate a tool matching sequence;
[0024] S2-4. Select a preset number of tools from the tool matching sequence that are ranked first to form a candidate tool set.
[0025] In some specific embodiments, the step of performing data flow constraint verification and topology constraint verification on the directed workflow graph to generate a valid workflow graph includes:
[0026] S3-1. Input the candidate toolset and task constraint set into the workflow graph generation module to generate a directed workflow graph;
[0027] S3-2. Divide the nodes in the directed workflow graph into tool nodes, large language model nodes, and conditional branch nodes;
[0028] S3-3. Establish directed edges between nodes in the directed workflow graph and configure data flow mapping for each directed edge;
[0029] S3-4. Based on the input data pattern and output data pattern of each node, perform data flow constraint verification on the data flow mapping of each directed edge;
[0030] S3-5. Perform topological sorting on the directed workflow graph to determine whether there are loops in the directed workflow graph;
[0031] S3-6. If both the data flow constraint verification and the topology constraint verification pass, the directed workflow graph is determined to be a valid workflow graph.
[0032] In some specific embodiments, data flow constraint verification is performed on the data flow mapping of each directed edge, including:
[0033] For any directed edge from the source node to the target node, determine whether the data stream mapping corresponding to the directed edge belongs to the matching range of the source node's output data pattern and the target node's input data pattern.
[0034] If the data flow mapping does not fall within the matching range, the directed workflow graph is determined to have failed the data flow constraint verification, and the workflow graph is regenerated.
[0035] In some specific embodiments, generating agent source code based on the valid workflow graph includes:
[0036] S4-1. Read the node types, directed edges, and data flow mappings in the valid workflow graph;
[0037] S4-2. Generate corresponding tool call code, large language model call code, and conditional branch code based on the node type;
[0038] S4-3. Generate an execution scheduler based on the directed edges and data flow mapping;
[0039] S4-4. Write the task semantic vector and task constraint set into the dynamic prompt template;
[0040] S4-5. Input the dynamic prompt template and historical context into the large language model calling code, and generate the agent source code based on the output of the large language model and the workflow graph running tool calling code, conditional branch code and execution scheduler.
[0041] In some specific embodiments, the collection of execution trajectories and feedback metrics during the execution of the intelligent agent includes:
[0042] S5-1. Load the source code of the intelligent agent in an isolated sandbox environment;
[0043] S5-2. Restrict network access permissions, file system access permissions, and system call permissions of the isolated sandbox environment;
[0044] S5-3. Run the source code of the agent and record the agent's state, actions, immediate rewards and next state in multiple execution steps to generate an execution trajectory;
[0045] S5-4. Calculate feedback indicators based on the execution trajectory; wherein, the feedback indicators include task completion rate and failure status code.
[0046] In some specific embodiments, the agent's source code is iteratively optimized based on the execution trajectory and feedback metrics until convergence conditions are met, and a target agent instance is output, including:
[0047] S6-1. Input the source code of the agent in the current round, feedback metrics, and the original natural language task into the quality assessment model to generate correction instructions;
[0048] S6-2. Based on the update parameters of the current round and the correction instructions, perform source code update on the source code of the agent in the current round to generate the source code of the agent in the next round.
[0049] The update parameters for the current iteration decrease with each iteration, and their calculation formula is as follows:
[0050] ;
[0051] in, Indicates the first Wheel update parameters, Indicates the initial update parameters. Indicates the attenuation coefficient. Indicates the iteration round;
[0052] S6-3. Calculate task rewards based on the source code of the agent in the next round and the original natural language task;
[0053] S6-4. Determine whether the task reward has reached a preset reward threshold, or whether the change in task reward between two adjacent rounds is less than a preset precision threshold.
[0054] S6-5. If the preset reward threshold or preset accuracy threshold is met, output the source code of the agent in the next round as the target agent instance.
[0055] S6-6. If the preset reward threshold and the preset accuracy threshold are not met, continue to iteratively correct the agent's source code.
[0056] This invention provides a method for automatically constructing intelligent agents based on large language models, which has the following beneficial effects:
[0057] This invention performs task semantic parsing on the original natural language task using a large language model, obtaining task semantic vectors and a set of task constraints. Based on these task semantic vectors, candidate toolsets are then selected from a tool semantic index. Thus, tool selection no longer relies on manual specification but is based on the similarity between the task semantic vector and the tool semantic embedding vector. This ensures that the candidate toolsets correspond to the user's task content and reduces the number of irrelevant tools entering the subsequent workflow generation process.
[0058] Furthermore, this invention generates a directed workflow graph based on a candidate toolset and a task constraint set, and performs data flow constraint verification and topology constraint verification on the directed workflow graph. Therefore, before the agent's source code is generated, the matching of data transfers between nodes can be checked, and loops in the workflow graph can be detected. This ensures that the subsequently generated agent's source code has a clear execution order and data transfer path, reducing runtime failures caused by mismatched node inputs and outputs or cyclic execution.
[0059] Furthermore, the agent's source code is run in an isolated sandbox environment, execution trajectories and feedback metrics are collected, and correction instructions are generated based on the feedback metrics to iteratively optimize and update the agent's source code. Thus, after generation, the agent's source code can continue to be corrected based on task completion rate and failure status codes until the task reward reaches a preset reward threshold or the change in reward between adjacent iterations is less than a preset precision threshold, thereby forming a closed-loop construction process from natural language task input, agent generation, execution verification to feedback optimization. Attached Figure Description
[0060] Figure 1This is a flowchart illustrating an automatic agent construction method based on a large language model according to the present invention.
[0061] Figure 2 This is a flowchart illustrating another embodiment of the intelligent agent automatic construction method based on a large language model according to the present invention. Detailed Implementation
[0062] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0063] Please see Figures 1 to 2 This invention provides a method for automatically constructing intelligent agents based on a large language model, comprising the following steps:
[0064] This invention provides a method for automatically constructing intelligent agents based on large language models, comprising the following steps:
[0065] S1. Receive the natural language task and call the large language model to perform task semantic parsing on the original natural language task, generating task semantic vectors and task constraint sets.
[0066] The specific execution steps of step S1 include:
[0067] S1-1. Input the original natural language task into the large language model;
[0068] S1-2. Extract the task intent, task object, target output, and execution constraints from the original natural language task using the large language model.
[0069] S1-3. Encode the task intent and task object into a task semantic vector, and organize the target output and execution constraints into a task constraint set;
[0070] The task constraint set includes at least one or more of the following: security constraints, output format constraints, tool call constraints, and functional boundary constraints.
[0071] The task semantic parsing process is represented as follows:
[0072] ;
[0073] Where T represents the original natural language task. Represents the inference operator for large language models. Represents the task semantic vector. This represents the set of task constraints.
[0074] Specifically, the original natural language task can be a task description input by the user, such as a task to build an intelligent customer service system, a document processing task, an order query task, a refund processing task, a data analysis task, or a code generation task. When the large language model parses the original natural language task, it extracts the task intent, task object, target output, and execution constraints, and encodes the core task semantics into a task semantic vector. It also organizes security constraints, output format, scope of callable tools, and functional boundaries into a set of task constraints.
[0075] In this embodiment, the task constraint set may include security and compliance constraints, output format constraints, functional boundary constraints, and execution permission constraints. For example, for the task of "building an intelligent customer service agent that can automatically process users' order inquiries and refund applications, and whose responses must meet platform requirements and whose output format is a standardized JSON structure," the large language model can extract "intelligent customer service construction" as the task intent, "order inquiry" and "refund application" as task objects, "standardized JSON structure" as the output format constraint, and "meets platform requirements" as the security and compliance constraint.
[0076] S2. Based on the task semantic vector, perform semantic matching on multiple tools in the pre-built tool semantic index library to obtain a candidate tool set.
[0077] The specific execution steps of step S2 include:
[0078] S2-1. Obtain a pre-built tool semantic index library; wherein, the tool semantic index library includes multiple tools and the tool semantic embedding vectors corresponding to each tool;
[0079] S2-2. Calculate the semantic similarity between the semantic embedding vector of each tool and the semantic vector of the task, respectively.
[0080] The formula for calculating the semantic similarity is:
[0081] ;
[0082] in, This represents the semantic similarity between the i-th tool and the task semantic vector. This represents the semantic embedding vector of the i-th tool. Represents the task semantic vector. express and The product of the L2 norms.
[0083] S2-3. Sort multiple tools in descending order according to semantic similarity to generate a tool matching sequence;
[0084] S2-4. Select a preset number of tools from the tool matching sequence that are ranked first to form a candidate tool set.
[0085] Specifically, the tool semantic index pre-stores multiple tools and their semantic embedding vectors. Tools may include database query tools, order system interfaces, refund process interfaces, search tools, file read / write tools, code execution tools, or formatted output tools. For each tool, the semantic similarity between its tool semantic embedding vector and the task semantic vector is calculated, and the tools are sorted in descending order of semantic similarity.
[0086] After sorting the tools in the tool semantic index in descending order according to semantic similarity, a predetermined number of tools are selected from the top of the sorted list to form a candidate toolset. This process ensures that subsequent workflow diagram generation prioritizes the use of tools that are semantically relevant to the task, reducing the number of irrelevant tools entering the workflow diagram generation stage.
[0087] S3. Generate a directed workflow graph based on the candidate toolset and the task constraint set, and perform data flow constraint verification and topology constraint verification on the directed workflow graph to generate a valid workflow graph.
[0088] The specific execution steps of step S3 include:
[0089] S3-1. Input the candidate toolset and task constraint set into the workflow graph generation module to generate a directed workflow graph;
[0090] The directed workflow graph is represented as follows: ;
[0091] in, Represents a set of nodes. Represents the set of directed edges. This represents a data stream mapping.
[0092] S3-2. Divide the nodes in the directed workflow graph into tool nodes, large language model nodes, and conditional branch nodes;
[0093] Specifically, the node set includes tool nodes, large language model nodes, and conditional branch nodes. Tool nodes are used to call tools from the candidate tool set; large language model nodes are used to write source code, perform text understanding, reasoning, rewriting, or decision-making; and conditional branch nodes are used to determine the subsequent execution path based on intermediate execution results.
[0094] S3-3. Establish directed edges between nodes in the directed workflow graph and configure data flow mapping for each directed edge;
[0095] Specifically, directed edges are used to represent the execution order between nodes, and data flow mapping is used to represent the data structure, field names, and field types corresponding to the transmission of source node output data to target node input data.
[0096] S3-4. Based on the input data pattern and output data pattern of each node, perform data flow constraint verification on the data flow mapping of each directed edge;
[0097] For any directed edge from the source node to the target node, determine whether the data flow mapping corresponding to the directed edge satisfies the matching relationship between the output data pattern of the source node and the input data pattern of the target node. The matching relationship is expressed as:
[0098] ;
[0099] in, Indicates from the source node Point to target node The directed edge, Indicates the data output mode of the source node. This indicates the input data pattern for the target node.
[0100] S3-5. Perform topological sorting on the directed workflow graph to determine whether there are loops in the directed workflow graph;
[0101] S3-6. If both the data flow constraint verification and the topology constraint verification pass, the directed workflow graph is determined to be a valid workflow graph.
[0102] Specifically, if the data flow mapping does not satisfy the matching relationship, a fallback mechanism is triggered, and the directed workflow graph is regenerated. If the data flow mapping satisfies the matching relationship, the directed workflow graph is topologically sorted to determine if there are any loops in the directed workflow graph. If a loop exists, the directed workflow graph is regenerated; if no loop exists, the directed workflow graph is determined to be a valid workflow graph.
[0103] S4. Generate the source code of the agent based on the valid workflow graph.
[0104] The specific execution steps of step S4 include:
[0105] S4-1. Read the node types, directed edges, and data flow mappings in the valid workflow graph;
[0106] S4-2. Generate corresponding tool call code, large language model call code, and conditional branch code based on the node type;
[0107] S4-3. Generate an execution scheduler based on the directed edges and data flow mapping;
[0108] S4-4. Write the task semantic vector and task constraint set into the dynamic prompt template;
[0109] S4-5. Input the dynamic prompt template and historical context into the large language model calling code, and generate the agent source code based on the output of the large language model and the workflow graph running tool calling code, conditional branch code and execution scheduler.
[0110] The process of generating the source code of the intelligent agent is represented as follows:
[0111] ;
[0112] in, This represents the source code of the intelligent agent. Indicates the compiler operator, This indicates a dynamic prompt template. This refers to the history context manager. This indicates the execution scheduler.
[0113] Specifically, the node types, directed edges, and data flow mappings in the valid workflow graph are read. Tool call code, large language model call code, and conditional branch code are generated based on the node types. An execution scheduler is generated based on the directed edges and data flow mappings. The task semantic vector and task constraint set are written into the dynamic prompt template.
[0114] In this embodiment, the dynamic prompt template is used to inject the task semantic vector and task constraint set, so that the agent can comply with the task boundary and output format during execution; the history context manager is used to record multi-turn dialogues, tool return results and intermediate execution states; the execution scheduler is used to schedule tool nodes, large language model nodes and conditional branch nodes according to the topology of the legal workflow graph.
[0115] S5. Run the source code of the agent in an isolated sandbox environment and collect the execution trajectory and feedback indicators during the execution process of the agent.
[0116] The specific execution steps of step S5 include:
[0117] S5-1. Load the source code of the intelligent agent in an isolated sandbox environment;
[0118] S5-2. Restrict network access permissions, file system access permissions, and system call permissions of the isolated sandbox environment;
[0119] S5-3. Run the source code of the agent and record the agent's state, actions, immediate rewards and next state in multiple execution steps to generate an execution trajectory;
[0120] The execution trajectory is represented as follows:
[0121] ;
[0122] in, This represents the state of the t-th execution step. This represents the action taken in the t-th execution step. This represents the immediate reward corresponding to the t-th execution step. Indicates the next state. This indicates the total number of execution steps.
[0123] S5-4. Calculate feedback indicators based on the execution trajectory; wherein, the feedback indicators include task completion rate and failure status code.
[0124] The feedback metric is expressed as follows:
[0125] ;
[0126] in, Indicates the task completion rate. The failure status code indicates a failure status. The task completion rate can be determined based on indicators such as whether the task objective has been completed, whether the output format meets the constraints, and whether the tool call was successful. The failure status code is used to record abnormal states such as tool call failure, restricted permissions, incorrect format, data stream mismatch, or execution timeout.
[0127] Specifically, the agent's source code is deployed to an isolated sandbox environment for execution. The isolated sandbox environment is used to restrict the agent's source code's network access permissions, file system access permissions, and system call permissions to reduce the impact of abnormal code or erroneous tool calls on the host environment.
[0128] S6. Based on the execution trajectory and feedback indicators, iteratively optimize the source code of the agent until the convergence condition is met, and output the target agent instance.
[0129] The specific execution steps of step S6 include:
[0130] S6-1. Input the source code of the agent in the current round, feedback metrics, and the original natural language task into the quality assessment model to generate correction instructions;
[0131] The correction instruction is expressed as follows:
[0132] ;
[0133] in, This indicates the correction instruction in the kth round. This represents a quality assessment model. This represents the source code of the agent in the k-th round. This represents the feedback metric for the k-th round.
[0134] S6-2. Based on the update parameters of the current round and the correction instructions, perform source code update on the source code of the agent in the current round to generate the source code of the agent in the next round.
[0135] The agent source code update process is represented as follows:
[0136]
[0137] Where ⊕ represents the source code update operator, This indicates that the parameters are updated in the k-th round.
[0138] The update parameter can be expressed as:
[0139]
[0140] in, This represents the update parameters in the k-th round. Indicates the initial update parameters. Indicates the attenuation coefficient. Indicates the iteration round;
[0141] S6-3. Calculate task rewards based on the source code of the agent in the next round and the original natural language task;
[0142] The task reward is represented as follows:
[0143] ;
[0144] S6-4. Determine whether the task reward has reached a preset reward threshold, or whether the change in task reward between two adjacent rounds is less than a preset precision threshold.
[0145] The convergence condition is expressed as follows: ;or ;
[0146] in, This represents the convergence reward threshold. This represents the convergence accuracy threshold.
[0147] S6-5. If the preset reward threshold or preset accuracy threshold is met, output the source code of the agent in the next round as the target agent instance.
[0148] S6-6. If the preset reward threshold and the preset accuracy threshold are not met, continue to iteratively correct the agent's source code.
[0149] Specifically, the source code of the agent in the current round, feedback metrics, and the original natural language task are input into the quality assessment model to generate correction instructions. The source code of the agent in the current round is then updated based on these correction instructions to obtain the source code of the agent in the next round. If the task reward in the next round reaches a preset reward threshold, or the change in task reward between two adjacent rounds is less than a preset accuracy threshold, the iteration terminates and the target agent instance is output; otherwise, the next round of correction continues based on the feedback metrics.
[0150] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.
Claims
1. A method for automatically constructing intelligent agents based on a large language model, characterized in that, include: S1. Receive the natural language task and call the large language model to perform task semantic parsing on the original natural language task, generating task semantic vector and task constraint set; S2. Based on the task semantic vector, perform semantic matching on multiple tools in the pre-built tool semantic index library to filter and obtain a candidate tool set; S3. Generate a directed workflow graph based on the candidate toolset and the task constraint set, and perform data flow constraint verification and topology constraint verification on the directed workflow graph to generate a valid workflow graph; S4. Generate agent source code based on the valid workflow graph; wherein, the agent source code includes an input module, an inference module, a memory module, a tool invocation module, and an execution output module; S5. Run the source code of the agent in an isolated sandbox environment and collect the execution trajectory and feedback indicators during the execution process of the agent; S6. Based on the execution trajectory and feedback indicators, iteratively optimize the source code of the agent until the convergence condition is met, and output the target agent instance.
2. The method for automatically constructing intelligent agents based on large language models according to claim 1, characterized in that, The generated task semantic vector and task constraint set include: S1-1. Input the original natural language task into the large language model; S1-2. Extract the task intent, task object, target output, and execution constraints from the original natural language task using the large language model. S1-3. Encode the task intent and task object into a task semantic vector, and organize the target output and execution constraints into a task constraint set; The task constraint set includes at least one or more of the following: security constraints, output format constraints, tool call constraints, and functional boundary constraints.
3. The method for automatically constructing intelligent agents based on a large language model according to claim 1, characterized in that, The process of semantically matching multiple tools in a pre-built tool semantic index library and filtering them to obtain a candidate tool set includes: S2-1. Obtain a pre-built tool semantic index library; wherein, the tool semantic index library includes multiple tools and the tool semantic embedding vectors corresponding to each tool; S2-2. Calculate the semantic similarity between the semantic embedding vector of each tool and the semantic vector of the task, respectively. ; in, This represents the semantic similarity between the i-th tool and the task semantic vector. This represents the semantic embedding vector of the i-th tool. Represents the task semantic vector. express and The product of the L2 norms. S2-3. Sort multiple tools in descending order according to semantic similarity to generate a tool matching sequence; S2-4. Select a preset number of tools from the tool matching sequence that are ranked first to form a candidate tool set.
4. The method for automatically constructing intelligent agents based on large language models according to claim 1, characterized in that, The step of performing data flow constraint verification and topology constraint verification on the directed workflow graph to generate a valid workflow graph includes: S3-1. Input the candidate toolset and task constraint set into the workflow graph generation module to generate a directed workflow graph; S3-2. Divide the nodes in the directed workflow graph into tool nodes, large language model nodes, and conditional branch nodes; S3-3. Establish directed edges between nodes in the directed workflow graph and configure data flow mapping for each directed edge; S3-4. Based on the input data pattern and output data pattern of each node, perform data flow constraint verification on the data flow mapping of each directed edge; S3-5. Perform topological sorting on the directed workflow graph to determine whether there are loops in the directed workflow graph; S3-6. If both the data flow constraint verification and the topology constraint verification pass, the directed workflow graph is determined to be a valid workflow graph.
5. The method for automatically constructing intelligent agents based on large language models according to claim 4, characterized in that, Perform data flow constraint validation on the data flow mapping of each directed edge, including: For any directed edge from the source node to the target node, determine whether the data stream mapping corresponding to the directed edge belongs to the matching range of the source node's output data pattern and the target node's input data pattern. If the data flow mapping does not fall within the matching range, the directed workflow graph is determined to have failed the data flow constraint verification, and the workflow graph is regenerated.
6. The method for automatically constructing intelligent agents based on large language models according to claim 1, characterized in that, The process of generating agent source code based on the valid workflow graph includes: S4-1. Read the node types, directed edges, and data flow mappings in the valid workflow graph; S4-2. Generate corresponding tool call code, large language model call code, and conditional branch code based on the node type; S4-3. Generate an execution scheduler based on the directed edges and data flow mapping; S4-4. Write the task semantic vector and task constraint set into the dynamic prompt template; S4-5. Input the dynamic prompt template and historical context into the large language model calling code, and generate the agent source code based on the output of the large language model and the workflow graph running tool calling code, conditional branch code and execution scheduler.
7. The method for automatically constructing intelligent agents based on a large language model according to claim 1, characterized in that, The collection of execution trajectories and feedback metrics during the execution process of the intelligent agent includes: S5-1. Load the source code of the intelligent agent in an isolated sandbox environment; S5-2. Restrict network access permissions, file system access permissions, and system call permissions of the isolated sandbox environment; S5-3. Run the source code of the agent and record the agent's state, actions, immediate rewards and next state in multiple execution steps to generate an execution trajectory; S5-4. Calculate feedback indicators based on the execution trajectory; wherein, the feedback indicators include task completion rate and failure status code.
8. The method for automatically constructing intelligent agents based on large language models according to claim 1, characterized in that, Based on the execution trajectory and feedback metrics, the source code of the agent is iteratively optimized until the convergence condition is met, and the target agent instance is output, including: S6-1. Input the source code of the agent in the current round, feedback metrics, and the original natural language task into the quality assessment model to generate correction instructions; S6-2. Based on the update parameters of the current round and the correction instructions, perform source code update on the source code of the agent in the current round to generate the source code of the agent in the next round. The update parameters for the current iteration decrease with each iteration, and their calculation formula is as follows: ; in, Indicates the first Wheel update parameters, Indicates the initial update parameters. Indicates the attenuation coefficient. Indicates the iteration round; S6-3. Calculate task rewards based on the source code of the agent in the next round and the original natural language task; S6-4. Determine whether the task reward has reached a preset reward threshold, or whether the change in task reward between two adjacent rounds is less than a preset precision threshold. S6-5. If the preset reward threshold or preset accuracy threshold is met, output the source code of the agent in the next round as the target agent instance. S6-6. If the preset reward threshold and the preset accuracy threshold are not met, continue to iteratively correct the agent's source code.