Workflow automatic generation method and system based on multi-agent and sandbox microcirculation
By employing a multi-agent approach and a sandbox micro-loop method, the problems of high workflow generation failure rate, lack of self-healing mechanism, interaction deadlock, and context pollution in existing technologies are solved, thus achieving efficient and secure automatic workflow generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- 浙江实在智能科技有限公司
- Filing Date
- 2026-05-20
- Publication Date
- 2026-06-19
Smart Images

Figure CN122240080A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of natural language processing technology, specifically relating to a method and system for automatically generating workflows based on multi-agent and sandbox micro-loops. Background Technology
[0002] With the acceleration of business automation and digital transformation, enterprise-level workflow orchestration systems (such as Dify and Apache Airflow) play a crucial role in application integration and data processing. Traditional workflow construction mainly relies on developers writing code or business planners manually dragging and dropping and configuring nodes on a graphical user interface (GUI). This not only requires a high learning curve, but development efficiency is also often limited by human experience.
[0003] In recent years, the rapid evolution of Large Language Models (LLMs) has spurred a revolution in the fields of Natural Language to Action (NALSA) and automated code generation. Systems based on multi-agent architectures are beginning to attempt to directly generate workflow configuration files through natural language business requirement identification, thereby achieving automated "intent-as-application" construction.
[0004] Currently, the industry has mainly developed the following three typical technical approaches for generating automated workflows: 1. Single End-to-End Generation Architecture: The system provides a global rule prompt to the monolithic large language model, requiring the model to directly hard-code the business logic and output it as structured data (such as deeply nested JSON or YAML files) that conforms to the target system specifications after understanding the user's natural language.
[0005] 2. Template and Node Matching Architecture Based on Retrieval Augmentation (RAG): To address the issue of single-model systems easily forgetting component parameters (creating illusions), some systems introduce an external vector database. Before the generation process, the system converts user requirements into vectors, retrieves the most similar historical workflow templates or fragmented documents of specific nodes (Node Schema) from the database, and supplements the model with context before generation.
[0006] 3. Multi-Agent Collaborative Architecture: To cope with extremely complex logical orchestration, the industry has begun to introduce multi-agent frameworks (such as orchestration engines based on LangGraph, AutoGen, etc.) for step-by-step collaboration. Their core pipeline typically consists of the following three key modules: The Planner / Supervisor Agent, located at the forefront of the architecture, serves as the central hub for dialogue and routing. The Planner is responsible for understanding the user's overall intent, breaking down multi-turn dialogues, and planning an initial blueprint (such as determining the need to "fetch data" and "save to the database"). This node typically inherits all of the user's historical dialogue memories and graph states.
[0007] Discovery Agent / Subgraph: This module is used to visualize the conceptual blueprint. It receives tasks to find feasible nodes, initiates multiple semantic searches through the network to the platform interface or vector library to search for the exact node name and parameter description corresponding to the requirements, and "mounts" these scattered component features into the global context.
[0008] The Builder Agent, acting as the end of the pipeline, is responsible for processing and handling the lengthy scheduling logs from the Planner and the complex instructions retrieved by Discovery. Within this overall context, it is responsible for the wiring and ultimately outputs a complete set of structured configuration files (JSON / YAML) directly to the system from the language model.
[0009] The aforementioned single-generation, external retrieval, or multi-agent pipeline solutions all attempt to reduce the difficulty of machine-generated complex graphical business orchestration through different context assembly and scheduling mechanisms.
[0010] Although the aforementioned multi-agent collaborative mechanism conceptually achieves the decomposition of task steps, it still reveals the following serious technical shortcomings in the operation and output loop of actual complex industrial workflows: 1. Forcing the output of non-native structured configurations leads to an extremely high generation failure rate (corresponding to generation expression defects): Large Language Models (LLMs) primarily use natural language and massive amounts of standard programming code as their pre-training corpora, making "coding" their core strength. However, current technologies still force large models to directly output large chunks of JSON or YAML configuration data with extremely deep hierarchies, verbose fields, and stringent requirements for bracket closure during the Builder stage. This completely violates the model's strengths and is highly prone to structural failures such as mismatched brackets, incorrect nesting levels, missing required parameters, and fabricated useless node parameters (illusions).
[0011] 2. Lack of a self-healing reverse engineering mechanism, and the high token computing power cost of full blind retries (corresponding to debugging and verification defects): Because ordinary JSON data cannot, like program code, throw precise exceptions with specific line numbers and variable types directly through a standard compiler at runtime, once JSON format validation or business validation fails, large models or external controllers often struggle to accurately pinpoint which deep-level field has a semantic or validity error, resulting in the system only receiving a general "generation failed" feedback. To fix the error, the system has to require the model to re-output a massive JSON package of thousands of lines for a full blind repair without specific line number guidance. This lack of a localized, precise tracking mechanism not only makes it difficult for the system to achieve automatic self-repair but also wastes a huge amount of token computing power in countless meaningless retries, leading to uncontrollable cost inflation.
[0012] 3. Long-tail retrieval relies heavily on serial single-point queries, which can easily lead to interaction deadlocks (corresponding to a defect in the Discovery module): Existing technologies heavily rely on the underlying vector database with network latency when Discovery handles available node constraint searches. When large models encounter complex requirements with multiple node combinations, their retrieval tools can only perform single-point queries and confirm the component format one by one, often falling into a serial O(N) interaction trap of "guessing nodes -> initiating retrieval -> waiting for response -> finding discrepancies -> correcting and retrying." This not only causes extremely high system construction latency but also results in a massive waste of useless tokens in frequent "question and answer" retrieval communications, severely reducing the throughput and success rate of the construction.
[0013] 4. Lack of physical isolation of state machines leads to deep context and state pollution (corresponding to Planner architecture flow defects): Existing multi-agent pipelines generally fail to strictly separate the "natural language communication boundary" and the "core code generation boundary" at the physical level. Accompanied by the massive parameter text of workflow nodes, multiple rounds of small talk, Planner's scheduling logs, and detailed user background descriptions, information flows mixed along the graph state pool all the way to the final builder. With the snowballing accumulation of historical records, it easily leads to the final generation model losing focus (context drift). During the code writing phase, the model is often completely polluted by the lengthy non-technical communication vocabulary from the previous sections, losing its pure compiler perspective, resulting in the output being mixed with idle chatter and explanations, causing the structure to collapse directly.
[0014] Therefore, it is very important to design an automatic workflow generation method and system based on multi-agent and sandbox micro-loop that has the characteristics of conforming to model programming instinct, using chained DSL code to replace JSON, combining sandbox isolation and row-level anomaly tracking to achieve closed-loop self-healing error correction, and utilizing pure memory batch aggregation retrieval and state machine physical isolation. Summary of the Invention
[0015] This invention aims to overcome the problems of existing automated workflow generation technologies, such as forcing large language models to output non-native, deeply nested JSON configurations leading to high generation failure rates, lack of precise row-level self-healing mechanisms causing huge token retry overhead, interaction deadlocks and high latency caused by serial single-point retrieval, and lack of physical isolation of state machines leading to context pollution. It provides a method and system for automatically generating workflows based on multi-agent and sandbox micro-loops, which can guide the model to generate chained DSL code, combine sandbox safe execution and precise row-level error correction of exception stacks, adopt pure memory batch aggregation retrieval, and achieve graph state machine physical isolation.
[0016] To achieve the above-mentioned objectives, the present invention adopts the following technical solution: The automatic workflow generation method based on multi-agent and sandbox micro-loop includes the following steps; S1 intercepts the user's natural language requests, performs intent analysis and traffic routing, extracts business construction instructions from them, and blocks the transmission of historical dialogue records and dialogue content unrelated to workflow construction to subsequent processing steps, thereby achieving physical isolation of context. S2, in response to the business construction instruction, retrieve the parameter constraint information of all components required for the workflow concurrently from the node configuration specifications preloaded into local memory through the batch query interface; S3. Based on the obtained node parameter constraints, generate domain-specific language code that conforms to the chained call syntax. The code is used to declare workflow nodes and define the execution flow between nodes using the chained method. S4, the domain-specific language code is sent into a restricted isolation sandbox for secure execution. In the isolation sandbox, network and external storage access permissions are revoked, and only static memory deduction is performed to parse and construct the abstract syntax tree of the workflow. S5, perform strong type integrity verification on the abstract syntax tree. If the verification fails, intercept the exception stack, extract the specific line number of the error and the missing field information and report it back. At the same time, trigger local correction to form a sandbox micro-loop closed loop. Repeat steps S3 to S5 until the verification passes. S6 translates the validated abstract syntax tree into a format that meets the protocol requirements of the target platform, serializes it into a standard configuration file that the target system can recognize, and outputs it.
[0017] Preferably, step S1 includes the following process: S11, the natural language request is sent to the intent classification stage; S12, if it is determined that the natural language request is a dialogue unrelated to workflow construction, then a response is generated directly and the request is blocked from being passed to subsequent processing steps. S13, if the natural language request is determined to be a workflow construction request, then the core construction instructions are extracted and reconstructed into clean task instructions. S14, the clean task instructions are passed to the code generation stage.
[0018] Preferably, step S2 includes the following process: S21, During the initialization phase, the parameter formats and rule descriptions of all workflow nodes on the target platform are fully loaded into local memory to build an inverted index based on local memory addressing; S22, through batch query that supports array parameter passing, submits a list of all node names to be arranged at once; S23 utilizes an in-memory text similarity algorithm to concurrently retrieve and aggregate the necessary parameter constraints of all relevant nodes within milliseconds, returning them all at once for subsequent code generation.
[0019] Preferably, step S3 includes the following process: S31 outputs a clear, code-based domain-specific language to replace deeply nested JSON or YAML configuration files; S32 uses a low-level encapsulated node object library to instantiate and configure workflow nodes by declaring variables. S33, the execution flow between nodes is defined using a chained call syntax, which includes at least one of node addition, sequential pointing, conditional true branch jump, and conditional false branch jump; S34, the generated domain-specific language code contains only business logic, which is automatically compiled into an abstract syntax tree of the workflow by the underlying engine when executed in the isolated sandbox.
[0020] Preferably, in step S4, when the domain-specific language code is executed in the isolated sandbox, it does not trigger any real external interface calls or physical data storage actions, but only performs static memory deduction to construct the abstract syntax tree.
[0021] Preferably, step S5 includes the following process: S51, based on the preset node specification dictionary, performs item-by-item scanning and verification of the parameter integrity, data type and hierarchical constraints of each component in the abstract syntax tree; S52 automatically removes redundant logs from the underlying framework when verification fails, simplifies the exception stack into a recovery instruction containing the error code line number and the name of the missing field, and then sends it back to trigger a local correction.
[0022] Preferably, when a local correction is triggered in step S5, only the local code line that erroneous is corrected and rewritten.
[0023] Preferably, step S6 includes the following process: S61, according to the underlying protocol requirements of the target system, translate the node parameters and topological relationships in the abstract syntax tree; S62, serialize the translated data into a standard configuration file that conforms to the target system specifications, wherein the standard configuration file is in JSON or YAML format; S63 automatically completes the node coordinates and edge relationship parameters required by the front-end canvas.
[0024] Preferably, the method also includes the following process: In step S1, the intent analysis stage and the code generation stage are configured as different graph state nodes through a multi-agent orchestration framework, and the original natural language dialogue record is prevented from entering the state bus during graph state transition.
[0025] This invention also provides an automatic workflow generation system based on multi-agent and sandbox micro-loop, including: The gateway agent is used to intercept users' natural language requests, perform intent analysis and traffic routing, and pass business construction instructions to the code generation agent. The code generation agent receives business construction instructions, obtains node configuration specifications through a batch query interface, and generates domain-specific language code that conforms to the chained call syntax. A pure memory retrieval engine is used to fully load the configuration specifications of all nodes into local memory during system initialization, respond to batch query requests of code-generated intelligent agents, and concurrently aggregate and return the parameter constraint information of the required components within milliseconds. An isolation sandbox is used to securely execute the domain-specific language code, strip network and external storage access, and parse and build the abstract syntax tree of the workflow in memory; The strong type validation and error correction module is used to perform integrity validation on the abstract syntax tree, capture exception stacks and extract error code line numbers and missing field information, and feed them back to the code generation agent for local correction, forming a closed-loop self-healing micro-cycle. The platform adapter is used to serialize the validated abstract syntax tree into a standard configuration file that can be recognized by the target system and output it.
[0026] Compared with existing technologies, the beneficial effects of this invention are: (1) It releases the original advantages of "Coding Native" and completely overcomes the pitfalls of non-native structure generation: This invention maps the JSON / YAML configuration file of the target platform to short-sentence program code (DSL) based on the chained call feature; this completely reverses the wrong path of the traditional "forcing large models to output nested data", closely following the innate instinct of pre-trained language models (LLM) to "be the best at writing code"; by stripping redundant fields and strict syntax bracket constraints, it significantly reduces parameter omissions and structural misalignments, resulting in a several-fold increase in the accuracy of zero-shot generation. (2) Establish a precise self-healing mechanism at the sandbox "line" granularity to end the astronomical token computing power overhead caused by full-scale blind testing: This invention uses an isolated sandbox to intercept Python execution errors (Traceback exception stack) and precisely locks the parameter errors to specific lines and fields; After receiving a reverse prompt similar to "compiler error", the large model only needs to call the local string replacement tool (batch_str_replace) to fine-tune a single line of code to complete the closed-loop self-healing; This completely ends the sky-high token settlement bill caused by repeated reload debugging of long texts; (3) Use a pure memory O(1) batch aggregation engine to eliminate serial single-point retrieval deadlock and high communication delay: Completely abandon the traditional The Discovery architecture in this scenario has a high latency and is uncontrollable network layer vector database (RAG); using the foundation technology of "batch array active parameter passing + pure memory-level CPU string fuzzy matching", the serial network blocking of "retrieval-wait-retry" required when building large models is collapsed into a batch aggregated memory read at the millisecond level; this not only reduces the overall architecture response latency by nearly 80%, but also successfully avoids the waste of meaningless RAG polling tokens; (4) Establish the physical isolation boundary of the graph state machine to cut off the context drift and generation domain pollution from the root: In response to the problem of historical dialogue flowing along with the context in the existing Planner architecture, this architecture has a gateway agent (Triage) in front. Agent strictly separates the natural language chatter area from the core code isolation development area at the bottom layer of GraphState; when large models are arranged logically within the sandbox, they obtain the requirement of absolutely pure instructions, fundamentally preventing compilation failures caused by idle chatter explanations in the code due to attention loss; at the same time, the shielding mechanism of the restricted sandbox also ensures excellent host security. Attached Figure Description
[0027] Figure 1 This is a flowchart of an automatic workflow generation method based on multi-agent and sandbox micro-loop in this invention; Figure 2This is a schematic diagram of the operational logic of isolated sandbox execution and closed-loop error correction in this invention. Detailed Implementation
[0028] To more clearly illustrate the embodiments of the present invention, specific implementation methods will be described below with reference to the accompanying drawings. Obviously, the drawings described below are merely some embodiments of the present invention. For those skilled in the art, other drawings and other implementation methods can be obtained based on these drawings without any creative effort.
[0029] This invention provides an automatic workflow generation method based on multi-agent and sandbox micro-loop, comprising the following steps; 1. Intercept users' natural language requests, perform intent analysis and traffic routing, extract business construction instructions from them, and block the transmission of historical dialogue records and dialogue content unrelated to workflow construction to subsequent processing steps to achieve physical isolation of context. 2. In response to the business construction instruction, the parameter constraint information of all components required for the workflow is obtained concurrently at one time from the node configuration specifications preloaded into local memory through the batch query interface; 3. Based on the obtained node parameter constraints, generate domain-specific language code that conforms to the chained call syntax. The code is used to declare workflow nodes and define the execution flow between nodes using the chained method. 4. The domain-specific language code is sent to a restricted isolation sandbox for secure execution. In the isolation sandbox, network and external storage access permissions are revoked, and only static memory deduction is performed to parse and construct the abstract syntax tree of the workflow. 5. Perform strong type integrity verification on the abstract syntax tree. If the verification fails, intercept the exception stack, extract the specific line number of the error and the missing field information and report it back. At the same time, trigger local correction to form a sandbox micro-loop closed loop. Repeat steps S3 to S5 until the verification passes. 6. Translate the validated abstract syntax tree into a format that meets the protocol requirements of the target platform, serialize it into a standard configuration file that the target system can recognize, and output it.
[0030] This invention not only defines the macroscopic intelligent agent flow architecture, but also delves into the underlying code compilation and memory retrieval mechanisms. The specific global architecture and flow are as follows: Figure 1 As shown, Figure 1 This invention demonstrates four key stages in its technological flow. Its core processing unit consists of a front-end gateway agent (Triage Agent) and a back-end code generation agent (CodeBuilder Agent), and fully covers the six specific steps shown in the diagram: 1. State Machine Barrier and Intent Isolation Phase (corresponding to Step 1): First, the user's natural language requests are intercepted by the front-end gateway for intent analysis and triage. A dedicated gateway agent (Triage Agent) is responsible for sorting and classifying these requests. If the request is determined to be a simple question-and-answer session or casual conversation, the response is directly intercepted without triggering downstream actions. If the request contains valid instructions for building / adjusting, useless small talk and historical burdens are removed, and the core natural language business request (Prompt) is assembled into a standardized instruction without loss of quality and then passed on to the downstream relay unit—the code generation agent (Code Builder Agent). This physical disconnection and graph state transition isolation prevents memory bias and contamination caused by the model processing unpruned long dialogues.
[0031] 2. Ultra-fast in-memory full-batch schema aggregation stage (corresponding to step 2): The system then utilizes a pure in-memory ultra-fast matching engine (Schema Registry) to respond to batch queries of the generated agent, instantly injecting all necessary node component constraint configurations into the agent in one go. This eliminates the need for traditional high-latency, loop-based single-point retrieval.
[0032] 3. Built-in DSL code generation and sandbox resolution self-healing phase (corresponding to steps 3, 4, and 5): After obtaining sufficient and accurate dependency context, the code generation agent officially intervenes at this point, producing Fluent Domain-Specific Language (DSL) code with graph connectivity characteristics, and sending it to a restricted isolation sandbox (exec) for execution. Code execution does not directly manipulate the business side, but implicitly constructs an Abstract Syntax Tree (AST) graph object, and uses a dynamic strong type checker for interception and review. If formatting or spelling errors fail to be verified, the system automatically extracts the Traceback error line number and quickly feeds it back to the code generation agent at the underlying level for error correction and refactoring until the local loop verification is 100% successful.
[0033] 4. Target Platform Semantic Composition and Standard Serialization Stage (corresponding to step 6): After verifying full compliance, the internal data is smoothly serialized by the target platform adapter into the standard configuration (JSON / YAML) specified by the target business environment and then output.
[0034] The technical solution of this invention specifically includes the following six sequentially progressive processing steps in the code: Step 1: Natural Language Request Interception and Intent Triage Isolation (Triage Gateway): Overview of Steps, Objectives, and Methods: The core objective of this step is to achieve strict separation between the front-end and back-end workspaces, preventing the large language model from being affected by irrelevant user information and excessively long dialogues during code generation, thus ensuring the stability of the generated code. By introducing a state machine routing mechanism, the system establishes a dedicated gateway agent responsible for sorting out front-end requirements, only transmitting the sorted core business requests to the back-end code generation nodes, thereby cutting off state pollution caused by dialogue through physical communication isolation.
[0035] Specific execution process: 1. Foreground Intent Judgment and Transmission (Interception and Routing): The system prevents the model responsible for generating the actual connection logic from directly processing the user's original long dialogue. Instead, the request is first sent to a dedicated gateway agent (Triage Agent) responsible for intent classification. This agent is responsible for understanding the user's intent and routing it: if it is determined to be a normal dialogue or theoretical question, it immediately answers it and blocks its propagation downstream; if it is a specific workflow building request, its core building instructions are extracted and reconstructed into a clean task (Prompt).
[0036] 2. Backend Physical Isolation and State Transition (State Tree Relay): Subsequently, the system uses a multi-agent orchestration framework to pass clean instructions with clear business orientations across stages to the independently operating code generation module (Code BuilderAgent). This approach of strictly separating the multi-round interaction context from the core generation environment on the system graph state variables effectively avoids long text memory drift and ensures that the code generation agent always focuses on the design of the core task logic.
[0037] Step 2: Local batch high-speed retrieval based on node configuration specifications: This step aims to address the high latency and efficiency issues caused by "single-node retrieval of external networks" in traditional architectures. The system abandons the inefficient external vector network retrieval mode, instead preloading the configuration specifications of all modules into local memory at once. The code generation module can initiate concurrent calls using a batch query interface, and the underlying ultra-fast pure memory matching algorithm can instantly return all the required node parameter specifications, laying the foundation for generating accurate code for large models.
[0038] Specific execution process: 1. Local dictionary construction (pure memory caching mechanism): During initialization, the system loads and caches the fields, parameter specifications and data types of all available components on the target platform into physical memory at once.
[0039] 2. Batch Query Interface (Concurrent Batch Processing): Before the large model begins "writing code" to assemble the workflow, the system provides a tool that supports batch queries. The Agent can pass in the names of multiple components to be used in a single interaction, and the tool will process these query requests synchronously, avoiding repeated single communications.
[0040] 3. Ultra-fast memory retrieval and context injection (O(1) aggregation engine): The system utilizes a text similarity algorithm based on the pure local CPU (such as a similarity algorithm based on the ratio of word set ratios) to accurately locate all the required parameters and constraints of the components needed by the agent within milliseconds. This accurate configuration information is "fed" to the agent as context, at a speed hundreds of times faster than traditional network retrieval, fundamentally blocking the hallucinations caused by large models not knowing what parameters to fill in.
[0041] Step 3: Constructing a minimalist DSL code that aligns with the programming instincts of large models: The core objective of this step is to avoid having large models directly generate massive JSON files that are extremely prone to errors. Deeply nested JSON forces models to match numerous parentheses and quotation marks, which not only consumes a lot of tokens but also contradicts the pre-trained strength of large models, which excel at writing logical code. Therefore, this system guides the code generation module to output a highly concise code—a domain-specific language (DSL). This allows large models to assemble workflow connections using intuitive code syntax, while the tedious JSON formatting and conversion work is handled by the underlying system.
[0042] Specific execution process: 1. Avoiding the JSON nesting trap (outputting a lightweight DSL): Forcing large models to output extremely deep-level structured data (such as JSON) can easily lead to "missing brackets" or "misaligned indentation," causing the entire parsing process to crash. This method instead allows the agent to output a code-based DSL with clear logic and a very high fault tolerance, drastically reducing the token consumption and syntax error rate in the first round of generation.
[0043] 2. Highly abstract component-level encapsulation: The system encapsulates a workflow node object library at the underlying level. After the agent receives the node parameter requirements obtained in step 2, it does not need to assemble a complex JSON dictionary. It can directly complete the instantiation configuration of the node (e.g., `llm_node = node("dify.llm", prompt="Please translate")`) just like declaring variables in daily code.
[0044] 3. Chained Call Syntax: To allow large models to focus on the business logic of the workflow, the system abandons the traditional graph construction method that requires large models to calculate screen coordinates (X / Y) or assemble complex two-dimensional arrays. By introducing a chained call design, the system provides a code format that conforms to natural language intuition, such as `.add("Node A").to("Node B").on_true("Node C")`. The agent can accurately and clearly connect all workflow nodes by simply following the code call chain.
[0045] 4. Automated background compilation focusing on pure business logic: During the code generation phase, the agent is completely freed from complex layout alignment and data formatting, focusing solely on outputting pure business code. Subsequently, when these minimalist connection codes (such as executing the `.to()` method) are run in the isolated sandbox environment, the underlying engine automatically compiles them implicitly in the background, directly converting them into a workflow abstract syntax tree (AST) that fully conforms to the target platform's specifications, achieving a seamless mapping from "minimalist code" to "complex system configuration files".
[0046] Example of DSL code configuration output: In contrast to standard JSON output, which often consists of hundreds of lines, the system architecture transforms the underlying layers into abstract method statements such as node, if_else, and workflow. The model only needs to produce a few lines of DSL declarative control code with specific syntax, and the system can automatically build the required internal memory state of the workflow based on the underlying engine.
[0047] Step 4: Security simulation and workflow abstract syntax tree (AST) construction based on the isolation sandbox: This step aims to securely host and parse the code generated from large models, completely eliminating the risk of unauthorized code execution. The system establishes a restricted sandbox isolation environment to compile and perform simulations on the generated code under security constraints.
[0048] During this simulation, the sandbox does not actually trigger underlying system resources or initiate backend network calls. Instead, it relies purely on static calculations based on object mounting relationships and flow declarations in the code. Through this safe and lightweight in-memory simulation, the system can parse the business logic flow between nodes and ultimately construct an abstract syntax tree (AST) in memory that accurately describes the workflow connectivity topology.
[0049] like Figure 2 The specific execution process is shown below: 1. Secure Restricted Execution Environment (Isolation Sandbox): The system allocates an independent micro-execution space in memory. This space forcibly strips all access permissions to external persistent storage (such as databases) and underlying network interfaces, ensuring that the code generated by large models runs in an absolutely closed and risk-free environment.
[0050] 2. Side-effect-free trial run and AST construction: The DSL code generated by the code generation agent is fed into this isolated sandbox for static evaluation and simulation. This computation process will never trigger actual external communication or physical data storage actions; instead, it purely parses the call flow of code objects in memory, thereby generating an Abstract Syntax Tree (AST) that accurately represents the workflow topology. This technology directly intercepts and immunizes against the possibility of model instructions overstepping their authority to tamper with business data or attack the host machine at the physical level.
[0051] Step 5: Fully Automated Closed-Loop Error Correction Based on Precise Anomaly Tracking (Self-Healing Micro-Circulation) This step aims to establish a highly fault-tolerant, self-healing barrier for the code generation process of large models. Since it's difficult to completely avoid hidden problems such as "missing parameters" or "type mismatches" when generating complex configurations for the first time, the system introduces an internal strong type checking mechanism for static interception and verification. The program parses and refines captured obscure exceptions into explicit error messages, which are then thrown back to the model, triggering a precise and targeted error correction loop. This micro-loop will operate fully automatically until the generated code passes 100% validity checks.
[0052] For example Figure 2 The specific execution process is shown below: 1. Strong Type Constraint Review (Dynamic Verification): The AST structure generated by the sandbox simulation is sent to the central interception and verification layer (based on dynamic verification technology stacks such as Pydantic). The system will check and screen all components one by one according to the preset node specification dictionary to see if the parameter key values are complete and whether the data type and hierarchical constraints are compliant and allow access.
[0053] 2. Traceback Extraction: If the verification module captures operational violations such as "core type mismatch" or "missing key parameters," the system will intercept the underlying exception stack traceback log. To avoid lengthy underlying error messages from the framework side polluting the context of the large model, the system will trim irrelevant information and refine and assemble it into precisely delimited recovery instructions, such as: "Exception blocking: When executing the Database component instantiation statement on line 4, the required constraint variable table_name was missing."
[0054] 3. Fine-grained source tracing and automated closed-loop error correction: The system, upon halting the error flow, sends refined exception information back to the code generation agent as a "self-driven correction trigger." With targeted error correction guidance accurate to the line number and field level, the large model can intuitively identify its own syntax or logic deviations and output corrected local code accordingly. This combined behavior of "sandbox evaluation → verification error interception → stack trace extraction and backpropagation → model self-correction" constitutes a high-speed, closed-loop state machine. Only when compilation and verification achieve 100% compliance will this closed state be released, and the final workflow output.
[0055] Step 6: Target platform format adaptation and serialization output This step is the final output of the entire automated workflow generation chain. Its core task is to securely and losslessly transform the Abstract Syntax Tree (AST), which has undergone sandbox testing and achieved 100% compliance with operational standards, into a standard serialized file (such as JSON or YAML) that can be directly recognized by the target platform, through a built-in platform adapter. This step completes the final leap from "pure in-memory abstract logic" to "standardized deployment product for commercial use," realizing a complete closed loop from requirement input to executable project file output.
[0056] Specific execution process: 1. Adapter Precise Translation and Serialization: After the AST in memory passes all legality checks in the sandbox, the system confirms that it has release-level logical accuracy. Subsequently, the system hands the AST over to the dedicated adapter for the corresponding target platform. The adapter translates, reorganizes, and serializes the AST tree parameters into a target platform-compatible format according to the underlying protocol requirements of the target system (e.g., automatically completing the node coordinates and edge relationships required by the front-end canvas).
[0057] 2. Standardized Data Packaging and One-Click Deployment: The structured streaming data, after being reconstructed by the adapter, will be encapsulated into a standard JSON or YAML file. This integrated package not only perfectly preserves the underlying logical topology of the model construction but also highly conforms to the import specifications of the customer's target system, allowing for direct one-click loading and deployment. At this point, the system has successfully completed the entire automated engineering process, from code intelligence agent generation and sandbox lossless deduction to automated error correction and release delivery.
[0058] In addition, the present invention also provides an automatic workflow generation system based on multi-agent and sandbox micro-loop, including: The gateway agent is used to intercept users' natural language requests, perform intent analysis and traffic routing, and pass business construction instructions to the code generation agent. The code generation agent receives business construction instructions, obtains node configuration specifications through a batch query interface, and generates domain-specific language code that conforms to the chained call syntax. A pure memory retrieval engine is used to fully load the configuration specifications of all nodes into local memory during system initialization, respond to batch query requests of code-generated intelligent agents, and concurrently aggregate and return the parameter constraint information of the required components within milliseconds. An isolation sandbox is used to securely execute the domain-specific language code, strip network and external storage access, and parse and build the abstract syntax tree of the workflow in memory; The strong type validation and error correction module is used to perform integrity validation on the abstract syntax tree, capture exception stacks and extract error code line numbers and missing field information, and feed them back to the code generation agent for local correction, forming a closed-loop self-healing micro-cycle. The platform adapter is used to serialize the validated abstract syntax tree into a standard configuration file that can be recognized by the target system and output it.
[0059] Based on the technical solution of this invention, the following case scenario illustrates the implementation process of this invention in practical applications. The specific application implementation scheme is as follows: The following section uses the typical business scenario of "automatic classification and storage of customer complaints" as an example to break down the workflow of this system and the evolution of intermediate data states in detail. This invention performs multi-stage dimensionality reduction and compilation on the user's natural language input, forming verifiable intermediate states at each key node, and finally ensuring zero defects in the output product through automated closed-loop error correction.
[0060] Business Scenario Setting: A salesperson inputs a natural language request: "Please create a workflow for me. The workflow needs to support passing in a 'customer comment' parameter via API. After receiving the parameter, the system should use a large model to analyze whether this comment is a customer complaint. If it is a complaint, write the data to a MySQL database. Regardless of whether it is a complaint or not, the process should end with a response node returning the analysis conclusion."
[0061] Detailed process flow and status breakdown: Phase 1: Front-end intent purification and contextual noise reduction (Triage traffic splitting): The aforementioned requests, imbued with complex context, were not directly handed over to the core code generator. Instead, they were first handled by the front-end routing agent (Triage Agent). The agent's primary task was to logically refine and identify the intent within the natural language. It filtered out user pleasantries and irrelevant historical chatter, extracting pure build instructions (such as API triggers, large model analysis, MySQL writes, conditional branch judgments, etc.), and then seamlessly passed these core requests to the downstream code generation module.
[0062] In this process, the system implements "physical truncation" and noise reduction for long text dialogue memory at the underlying architecture. The downstream code generation model (Code Builder Agent) only receives clear business logic lines, fundamentally eliminating attention drift caused by processing divergent long texts.
[0063] Phase Two: Active Retrieval of Large Models and Rapid Local Batch Dependency Reading (Batch-Schema Fetching) The code generation agent entering the inner loop has the capability to perform batch queries with array parameters (such as the `get_node_schema(List[str])` tool). Before starting to write workflow code, the system will first have the agent evaluate the list of nodes required to implement the business logic and proactively initiate batch component queries.
[0064] Upon receiving a query command, the underlying pure in-memory search engine is immediately activated. Utilizing CPU-level string feature matching algorithms (such as the Token Set Ratio similarity algorithm), the system completes concurrent aggregation of the pre-built local component index within milliseconds, instantly and accurately binding the parameter operation specifications (Schema) of all relevant components, including "API triggers," "large model inference," "MySQL database," and "response nodes," and returning them to the model.
[0065] This ultra-fast concurrent retrieval mechanism based on local pure memory not only completely surpasses traditional external RAG network queries in terms of response speed, but also injects strong parameter constraints into the model before it is even started, fundamentally eliminating the illusion that large models can "write randomly out of thin air" when they are unaware of the underlying field requirements.
[0066] Phase 3: Workflow code generation based on built-in DSL: With the aforementioned precise pre-parameter constraints, the code generation agent begins generating domain-specific programming instructions (DSL code) featuring chained API calls. Considering the inherent instability of the pre-trained model, we assume here that the model occasionally misses parameters (e.g., forgetting to fill in a database table name). In this case, the system generates the following example of basic DSL pseudocode: 1. Define the starting node (start_node) using the node primitive and configure the input parameter property containing the string variable "message"; 2. Define large model analysis nodes (llm) using node primitives and configure prompt parameters to identify complaint intent; 3. Use the if_else component to define conditional branch nodes (branch), and bind the judgment condition to a logical expression (Expr) that the output of the large model is equal to "complaint"; 4. Use the node primitive to define the database storage node (db) and configure the parameters for inserting data (Note: The simulation system made a mistake here and omitted the required table_name parameter). 5. Define the response node (ans) using the node primitive and configure the return parameters for outputting the final conclusion; 6. Instantiate a global workflow entity and name it the "Complaint Handling" task; 7. Define the workflow topology and branching: Add the starting node to the workflow and connect the main model node and the branch judgment node in sequence; when the judgment condition is true, the process points to the database node to save the data, and then flows into the response node; when the condition is false, skip the save operation and directly point to the response node to end the process.
[0067] Compared to traditional solutions that require the model to output a final JSON text containing hundreds or thousands of nested dictionaries at once, this system produces highly concise, semantically cohesive, logic-oriented control code at this stage. Its straightforward edge-connection expression system not only significantly reduces the probability of large-scale bracket and closure errors in the generated content, but also provides an execution foundation for the next step of parsing and validation based on the syntax tree.
[0068] Phase 4: Isolation Sandbox Operation and Automatic Error Correction Micro-loop Subsequently, the system loads the generated DSL code into an isolated sandbox completely stripped of network and disk access permissions for trial execution. This execution process never initiates actual read / write operations to the external database; instead, it purely parses the code's call flow within the sandbox memory, thereby constructing an Abstract Syntax Tree (AST) representing the workflow entity logic.
[0069] Next, a strong type validator (such as Pydantic) on the outer layer of the sandbox performs an attribute integrity scan on this AST. At this point, the system accurately captures that the `database` node generated by the large model has indeed missed the `table_name` parameter, which is required by the business logic.
[0070] At this point, the system will intercept the error stacks thrown by the underlying layer, automatically remove meaningless framework runtime logs, and refine them into targeted feedback that the large model can directly understand (e.g., "Validation failed: Error instantiating component [database] on line 5, missing required field 'table_name'").
[0071] Upon receiving this precise error message, the code generation agent, much like a human programmer debugging a program based on compiler errors, can quickly locate the incorrect line number and complete the correct code containing `table_name` in the next interaction. This micro-loop mechanism of "error reporting-blocking-feedback-rewriting" constructs a highly resilient error-proofing foundation. Any non-compliant code will be scrapped and rebuilt within the sandbox closed loop, completely eliminating the risk of deploying incomplete workflows to the production environment.
[0072] Phase 5: Target Platform Adaptation and Standard Configuration Serialization Output Once the system confirms that the AST in memory has passed 100% validity verification, the control center will call the dedicated adapter to perform smooth format translation and data reconstruction based on this flawless tree structure.
[0073] Ultimately, the system will output a standard structured file (supporting JSON or YAML format) that fully conforms to the underlying parsing specifications of the target platform (such as Dify / n8n). This file not only accurately reproduces the complex business logic, but also automatically completes format parameters such as front-end coordinates, ensuring that when this configuration file is imported into any target system, it can directly and losslessly render a complete and usable workflow canvas.
[0074] The core objective of this invention is to completely reverse the traditional, inefficient approach of "having models generate structured data" and fully leverage the technical characteristics of large language models, which are "adept at writing code logic." To this end, this invention abstracts and maps the configuration rules of the target system to a Python domain-specific language (DSL) based on chained API calls (Fluent API), and uses this as the orchestration carrier for the workflow.
[0075] By combining a pure in-memory O(1) aggregation retrieval engine with a restricted security sandbox equipped with an exception handling mechanism, this method achieves a paradigm shift from "outputting error-prone JSON" to "outputting highly accurate chained code." When logical deviations occur in the code, the system can perform "self-immune" error correction at an extremely fine granular level, down to the "line number," based on sandbox feedback. This solution not only drastically reduces token execution overhead and trial-and-error debugging costs but also fundamentally guarantees the absolute compliance output of complex industrial-grade workflows.
[0076] The innovative aspects of this invention are as follows: 1. Code transformation and precise line number correction mechanism based on isolation sandbox: a. Short code snippets replace full JSON (dimensionality reduction generation): The large language model (code generation agent) no longer directly outputs massive and error-prone workflow JSON configuration files. Instead, the system guides it to generate concise control code (Domain-Specific Language DSL) that expresses the logic of connections. This chained code (Fluent API) aligns with the model's inherently robust "code-writing" intuition, significantly reducing the error rate.
[0077] b. Secure simulation operation within the sandbox (isolation and resolution): The system provides a secure sandbox (exec scope) in the background, where network and system operation permissions are removed. The generated code is only "test-run" within this secure space and will never trigger real external business interfaces. The sole purpose of code execution is to instantiate component objects in memory following the function connection logic, and then assemble them into a standardized workflow underlying basic graph structure (Abstract Syntax Tree (AST) object).
[0078] c. Precise error correction via line number reporting, similar to a compiler (self-healing closed loop): The initially generated tree structure is immediately sent to the verification engine (strong type validator) for inspection. If a missing or incorrect parameter is detected in the model, the sandbox can intercept the original code traceback, precisely extracting which line of code is missing which specific constraint field, and directly return this concise error to the generated model. Based on this, the large model can precisely locate and perform low-cost remediation and repair only the problematic lines of code, much like a programmer fixing a bug.
[0079] This invention employs a system-level core method that combines "replacing JSON with code, sandboxing the topology structure tree, and extracting error line numbers from the code to guide retrying".
[0080] 2. A high-speed component parameter retrieval mechanism based on pure in-memory batch processing: a. Local full cache of the instruction manual (memory dictionary engine): During the initialization phase, the system loads all parameter formats and rule descriptions (Schema) of all workflow nodes on the target platform into the local high-speed memory in one go, and builds a name and rule inverted index that supports pure CPU addressing.
[0081] b. Batch Query for One-Time Orders (Package Acquisition Interface): The system resolutely abandons the industry's mainstream slow single-point retrieval mode that requires large models to repeatedly ask and answer questions through external networks and vector databases (RAG). The system directly provides a "batch query tool" for the code generation agent, allowing large models to submit a list of all node names they need to orchestrate at once (passed via array parameters).
[0082] c. Millisecond-level fuzzy matching aggregation (instantaneous response assembly): After the tool receives a batch list of nodes from a large model, the underlying layer directly utilizes pure CPU-level text feature algorithms (such as Token Set Ratio fuzzy matching) to concurrently lock and extract all the necessary rules for the mentioned nodes in an extremely short time of almost O(1). These scattered descriptions are seamlessly bound into a detailed and complete set of rules, which are then fed back into the current context memory of the large model in one go.
[0083] This invention adopts a system architecture that "utilizes local memory caching combined with a large model array parameter passing tool to instantaneously and concurrently acquire all relevant component constraints within a single interaction callback".
[0084] 3. A context isolation and pollution prevention scheduling system based on graph state machine properties: a. Multi-agent state node segmentation: The system orchestration framework distinguishes "intent recognition" and "code compilation" into different system state processing nodes (State Nodes). The front-end node is responsible for acquiring natural language and abstracting a "business data graph blueprint" that only contains the outline of the required processing components.
[0085] b. Context Cleansing and Memory Blocking Bus: Construct a unidirectional data transfer bus. The natural language history dialogue memory processed by the front-end nodes is deliberately blocked by the system, allowing only the highly abstract business blueprint structure data to be delivered to the dedicated code generation state node. This ensures that the code generation environment is completely physically isolated from the chat context.
[0086] The above description is merely a detailed explanation of preferred embodiments and principles of the present invention. For those skilled in the art, there may be changes in specific implementation methods based on the ideas provided by the present invention, and these changes should also be considered within the scope of protection of the present invention.
Claims
1. A workflow automatic generation method based on multi-agent and sandbox microcirculation, characterized in that, Includes the following steps; S1 intercepts the user's natural language requests, performs intent analysis and traffic routing, extracts business construction instructions from them, and blocks the transmission of historical dialogue records and dialogue content unrelated to workflow construction to subsequent processing steps, thereby achieving physical isolation of context. S2, in response to the business construction instruction, retrieve the parameter constraint information of all components required for the workflow concurrently from the node configuration specifications preloaded into local memory through the batch query interface; S3. Based on the obtained node parameter constraints, generate domain-specific language code that conforms to the chained call syntax. The code is used to declare workflow nodes and define the execution flow between nodes using the chained method. S4, the domain-specific language code is sent into a restricted isolation sandbox for secure execution. In the isolation sandbox, network and external storage access permissions are revoked, and only static memory deduction is performed to parse and construct the abstract syntax tree of the workflow. S5, perform strong type integrity verification on the abstract syntax tree. If the verification fails, intercept the exception stack, extract the specific line number of the error and the missing field information and report it back. At the same time, trigger local correction to form a sandbox micro-loop closed loop. Repeat steps S3 to S5 until the verification passes. S6 translates the validated abstract syntax tree into a format that meets the protocol requirements of the target platform, serializes it into a standard configuration file that the target system can recognize, and outputs it. 2.The multi-agent and sandbox micro-cycle based workflow automatic generation method according to claim 1, wherein, Step S1 includes the following process: S11, the natural language request is sent to the intent classification stage; S12, if it is determined that the natural language request is a dialogue unrelated to workflow construction, then a response is generated directly and the request is blocked from being passed to subsequent processing steps. S13, if the natural language request is determined to be a workflow construction request, then the core construction instructions are extracted and reconstructed into clean task instructions. S14, the clean task instructions are passed to the code generation stage. 3.The multi-agent and sandbox micro-cycle based workflow automatic generation method according to claim 2, characterized in that, Step S2 includes the following process: S21, During the initialization phase, the parameter formats and rule descriptions of all workflow nodes on the target platform are fully loaded into local memory to build an inverted index based on local memory addressing; S22, through batch query that supports array parameter passing, submits a list of all node names to be arranged at once; S23 utilizes an in-memory text similarity algorithm to concurrently retrieve and aggregate the necessary parameter constraints of all relevant nodes within milliseconds, returning them all at once for subsequent code generation.
4. The multi-agent and sandbox micro-cycle based workflow automatic generation method according to claim 3, characterized in that, Step S3 includes the following process: S31 outputs a clear, code-based domain-specific language to replace deeply nested JSON or YAML configuration files; S32 uses a low-level encapsulated node object library to instantiate and configure workflow nodes by declaring variables. S33, the execution flow between nodes is defined using a chained call syntax, which includes at least one of node addition, sequential pointing, conditional true branch jump, and conditional false branch jump; S34, the generated domain-specific language code contains only business logic, which is automatically compiled into an abstract syntax tree of the workflow by the underlying engine when executed in the isolated sandbox.
5. The multi-agent and sandbox micro-cycle based workflow automatic generation method according to claim 4, characterized in that, In step S4, when the domain-specific language code is executed in the isolated sandbox, it does not trigger any real external interface calls or physical data storage actions, but only performs static memory deduction to construct the abstract syntax tree.
6. The automatic workflow generation method based on multi-agent and sandbox micro-loop according to claim 5, characterized in that, Step S5 includes the following process: S51, based on the preset node specification dictionary, performs item-by-item scanning and verification of the parameter integrity, data type and hierarchical constraints of each component in the abstract syntax tree; S52 automatically removes redundant logs from the underlying framework when verification fails, simplifies the exception stack into a recovery instruction containing the error code line number and the name of the missing field, and then sends it back to trigger a local correction.
7. The automatic workflow generation method based on multi-agent and sandbox micro-loop according to claim 6, characterized in that, When a local correction is triggered in step S5, only the local lines of code that erroneous are corrected and rewritten.
8. The automatic workflow generation method based on multi-agent and sandbox micro-loop according to claim 7, characterized in that, Step S6 includes the following process: S61, according to the underlying protocol requirements of the target system, translate the node parameters and topological relationships in the abstract syntax tree; S62, serialize the translated data into a standard configuration file that conforms to the target system specifications, wherein the standard configuration file is in JSON or YAML format; S63 automatically completes the node coordinates and edge relationship parameters required by the front-end canvas.
9. The automatic workflow generation method based on multi-agent and sandbox micro-loop according to claim 8, characterized in that, It also includes the following processes: In step S1, the intent analysis stage and the code generation stage are configured as different graph state nodes through a multi-agent orchestration framework, and the original natural language dialogue record is prevented from entering the state bus during graph state transition.
10. A workflow automatic generation system based on multi-agent and sandbox micro-loop, used to implement the workflow automatic generation method based on multi-agent and sandbox micro-loop as described in any one of claims 1-9, characterized in that, The workflow automatic generation system based on multi-agent and sandbox micro-loop includes: The gateway agent is used to intercept users' natural language requests, perform intent analysis and traffic routing, and pass business construction instructions to the code generation agent. The code generation agent receives business construction instructions, obtains node configuration specifications through a batch query interface, and generates domain-specific language code that conforms to the chained call syntax. A pure memory retrieval engine is used to fully load the configuration specifications of all nodes into local memory during system initialization, respond to batch query requests of code-generated intelligent agents, and concurrently aggregate and return the parameter constraint information of the required components within milliseconds. An isolation sandbox is used to securely execute the domain-specific language code, strip network and external storage access, and parse and build the abstract syntax tree of the workflow in memory; The strong type validation and error correction module is used to perform integrity validation on the abstract syntax tree, capture exception stacks and extract error code line numbers and missing field information, and feed them back to the code generation agent for local correction, forming a closed-loop self-healing micro-cycle. The platform adapter is used to serialize the validated abstract syntax tree into a standard configuration file that can be recognized by the target system and output it.