A data processing method, apparatus, device, and medium

By rewriting dangerous operation nodes as security hook functions and generating short-term tokens before code execution, the execution of code is restricted to within the security boundary, thus solving the security and controllability issues of code generated by AI agents and achieving safe and controllable code execution.

CN121502759BActive Publication Date: 2026-04-14清雁科技(北京)有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-14
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

How can we ensure that the code generated by AI agents can be executed safely and controllably in a real-world operating environment, avoiding security incidents and resource abuse caused by malicious code?

Method used

Before code execution, predefined dangerous operation nodes are rewritten as security hook functions, and a one-time, short-lived JWT access token is generated for each tool call request to restrict the execution of tool call requests within the global namespace, and resource budget is monitored and deducted in real time.

Benefits of technology

It effectively prevents security threats and resource abuse caused by malicious code, ensures that the code is executed in a controllable manner within the security boundary, and meets the compliance requirements of regulations such as ISO/IEC27001 and GDPR.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121502759B_ABST
    Figure CN121502759B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a data processing method and device, equipment and medium, relating to the technical field of information security. The method comprises: obtaining original code data generated by an artificial intelligence agent; parsing the original code data into an abstract syntax tree, and rewriting a predefined dangerous operation node in the abstract syntax tree into a corresponding safe hook function to obtain restricted code data; generating a corresponding access token for each tool call request included in the restricted code data; and in a global namespace, sending a call request to an external service by filling the access token into the corresponding tool call request to receive result data sent by the external service. Thus, the method actively rewrites the predefined dangerous operation node into the corresponding safe hook function at the syntax level before the code is executed, so that even if the artificial intelligence agent generates malicious code, its destructive nature is fundamentally eliminated, thereby ensuring that the code can be safely and controllably executed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of information security technology, and in particular to a data processing method, apparatus, device and medium. Background Technology

[0002] With the rapid development of Large Language Model (LLM) technology, AI agents are now able to autonomously generate corresponding code (such as Python code snippets) based on natural language instructions and complete the tasks instructed by natural language instructions by calling external tools.

[0003] However, ensuring that the code can be executed safely and in a controllable manner in a real-world operating environment has become a pressing technical problem that needs to be solved. Summary of the Invention

[0004] To address the aforementioned issues, this application provides a data processing method, apparatus, device, and medium that can ensure that code can be executed securely and in a controllable manner.

[0005] The embodiments of this application disclose the following technical solutions:

[0006] In a first aspect, this application discloses a data processing method, the method comprising:

[0007] Obtain the raw code data generated by the AI ​​agent;

[0008] The original code data is parsed into an abstract syntax tree, and the predefined dangerous operation nodes in the abstract syntax tree are rewritten into corresponding safety hook functions to obtain restricted code data;

[0009] For each tool call request included in the restricted code data, generate a corresponding access token;

[0010] In the global namespace, by filling the access token into the corresponding tool call request, a call request is sent to the external service in order to receive the result data sent by the external service.

[0011] Optionally, the step of sending a call request to an external service by filling the access token into the corresponding tool call request includes:

[0012] Get real-time budget data;

[0013] If the real-time budget data is greater than a preset threshold, then after deducting the budget value corresponding to this call from the real-time budget data, a call request is sent to the external service by filling the access token into the corresponding tool call request.

[0014] Optionally, the budget value corresponding to this call is related to the type of calling tool used in this call and the number of historical calls.

[0015] Optionally, the method further includes:

[0016] If the real-time budget data is less than or equal to the preset threshold, the execution of the restricted code data is terminated.

[0017] Secondly, this application discloses a data processing apparatus, which includes: a data acquisition module, a node rewriting module, a token generation module, and a request sending module;

[0018] The data acquisition module is used to acquire the raw code data generated by the artificial intelligence agent;

[0019] The node rewriting module is used to parse the original code data into an abstract syntax tree, and rewrite the predefined dangerous operation nodes in the abstract syntax tree into corresponding safety hook functions to obtain restricted code data;

[0020] The token generation module is used to generate a corresponding access token for each tool call request included in the restricted code data;

[0021] The request sending module is used to send a call request to an external service in the global namespace by filling the access token into the corresponding tool call request, so as to receive the result data sent by the external service.

[0022] Optionally, the request sending module is specifically used to: obtain real-time budget data; if the real-time budget data is greater than a preset threshold, then after deducting the budget value corresponding to this call from the real-time budget data, send a call request to the external service by filling the access token into the corresponding tool call request.

[0023] Optionally, the budget value corresponding to this call is related to the type of calling tool used in this call and the number of historical calls.

[0024] Optionally, the device further includes: an execution termination module;

[0025] The execution termination module is used to terminate the execution of the restricted code data if the real-time budget data is less than or equal to the preset threshold.

[0026] Thirdly, this application discloses a data processing device, the device comprising: a memory and a processor;

[0027] The memory is used to store programs;

[0028] The processor is configured to execute the program to implement the various steps of the data processing method as described in the first aspect.

[0029] Fourthly, this application discloses a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the various steps of the data processing method as described in the first aspect.

[0030] Compared with the prior art, this application has the following beneficial effects:

[0031] This application provides a data processing method, apparatus, device, and medium. The method includes: acquiring raw code data generated by an artificial intelligence agent; parsing the raw code data into an abstract syntax tree (AST), and rewriting predefined dangerous operation nodes in the AST into corresponding security hook functions to obtain restricted code data; generating a corresponding access token for each tool call request included in the restricted code data; and sending a call request to an external service in a global namespace by filling the access token into the corresponding tool call request, in order to receive result data sent by the external service. Therefore, this method proactively rewrites predefined dangerous operation nodes into corresponding security hook functions at the syntax level before the code is executed. Even if the artificial intelligence agent generates malicious code, its destructive potential is fundamentally eliminated, thereby ensuring that the code can be executed safely and controllably. Attached Figure Description

[0032] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0033] Figure 1 A flowchart illustrating a data processing method provided in an embodiment of this application;

[0034] Figure 2 A schematic diagram showing the comparison before and after AST rewriting provided for an embodiment of this application;

[0035] Figure 3 A flowchart illustrating an execution tool invocation request provided in an embodiment of this application;

[0036] Figure 4 A schematic diagram of a data processing apparatus provided in an embodiment of this application;

[0037] Figure 5 This is a schematic diagram of a computer-readable medium provided in an embodiment of this application. Detailed Implementation

[0038] As described earlier, with the rapid development of large language model technology, artificial intelligence agents are now able to autonomously generate corresponding code based on natural language instructions and complete the tasks instructed by natural language instructions by calling external tools.

[0039] Currently, to improve the security of code execution, code is typically handed over directly to the Python interpreter and executed within a containerized environment (such as Docker) of the Python interpreter. This approach attempts to limit the potential scope of code damage within the containerized environment through environmental isolation, thereby ensuring the security of the host machine.

[0040] However, even in a container-isolated environment, code can still execute dangerous system calls or make arbitrary network requests without hindrance, which can still lead to serious security incidents.

[0041] Through research, the inventors have proposed a data processing method, apparatus, device, and medium. The data processing method provided in this application proactively rewrites predefined dangerous operation nodes into corresponding security hook functions at the syntax level before code execution. Therefore, even if the AI ​​agent generates malicious code, its destructive potential is fundamentally eliminated, ensuring the code can be executed safely and controllably. Furthermore, the data processing method provides a one-time, short-lived JWT access token for each tool call request. Because the JWT access token has a very short validity period and can only be used for specific operations, the leakage of a single token poses almost no security threat, further ensuring the code can be executed safely and controllably. Even further, the data processing method provides an allocation of call points for each execution instance and deducts them in real time based on the tool type and computational intensity (such as loops). This achieves a hard limit on the resource consumption of a single AI agent instance, ensuring that the CPU usage, memory consumption, and network request frequency of a single instance are limited within a safe range, thereby effectively preventing resource abuse and system instability caused by unpredictable code behavior.

[0042] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.

[0043] See Figure 1The figure is a flowchart of a data processing method provided in an embodiment of this application. This method can be widely applied to cloud or local security sandboxes of Agent frameworks such as Auto-GPT and LangChain, and includes the following steps:

[0044] S101: Obtain the raw code data generated by the AI ​​agent.

[0045] First, the AI ​​Agent, based on the user's input natural language instructions (which are complex tasks requiring interaction with external tools, such as "check today's weather in Shanghai and save it to a PostgreSQL database"), uses a large language model inference engine to break down the task into a series of specific, logically coherent, and executable steps. Then, the large language model inference engine instantiates these steps into a complete string of Python code that can be recognized and executed by the Python interpreter—the raw code data. For example, the raw code data A might look like this:

[0046] import requests, psycopg2

[0047] r=requests.get("http: / / api.weather.com / ...")

[0048] cur.execute("INSERT INTO weather...")

[0049] S102: Parse the original code data into an abstract syntax tree, and rewrite the predefined dangerous operation nodes in the abstract syntax tree into corresponding safety hook functions to obtain restricted code data.

[0050] First, the `ast.parse()` function from the Python standard library is called to parse the raw code data into an Abstract Syntax Tree (AST). An AST is a tree-like representation of the abstract syntactic structure of source code. Compared to the raw code data, the AST strips away non-essential elements such as comments and spaces, purely expressing the logical structure of the code, allowing the program to accurately analyze and manipulate the code itself.

[0051] Secondly, the abstract syntax tree is traversed using either a depth-first or breadth-first algorithm, and all predefined dangerous operation nodes are identified based on the predefined list of dangerous operations.

[0052] Subsequently, the predefined dangerous operation nodes are rewritten as corresponding security hook functions. Security hook functions include at least `_http_tool_`, `_sql_tool_`, and `_shell_tool_`. See also... Figure 2 This figure is a schematic diagram comparing the AST before and after rewriting according to an embodiment of this application. For example, the rewriting rules include, but are not limited to: removing the entire `import requests` statement; rewriting `requests.get()` to `_http_tool_()`; rewriting `open()` to `_read_file_()`; and rewriting the database cursor execution statement to `_sql_tool_()`, etc.

[0053] Finally, after rewriting the abstract syntax tree, the `compile()` function is used to recompile the modified, safe abstract syntax tree into a Python code string, obtaining restricted code data. For example, after processing the original code data A as described above, the resulting restricted code data B can be as follows:

[0054] r=_http_tool_("http: / / api.weather.com / ...","GET",headers={})

[0055] _=_sql_tool_("INSERT INTO weather...",params=())

[0056] Understandably, in the restricted code data generated at this point, all predefined dangerous operation nodes are replaced, and the restricted code data only includes calls to security hook functions. This process, without changing the core logic of the code, fundamentally deprives the code of its ability to directly execute dangerous operations, and the execution of the restricted code data is completely confined within the security boundaries defined by the sandbox system.

[0057] S103: Generate a corresponding access token for each tool call request included in the restricted code data.

[0058] First, the dynamic authorization center identifies all tool call requests by performing static analysis on the restricted code data. For example, if the restricted code data C is as shown below, then this restricted code data C includes: an HTTP tool call targeting "https: / / api.example.com / data" using the "GET" method; an SQL tool call executing a SELECT query on the users table; and an SQL tool call executing an INSERT operation on the audit_log table.

[0059] data1 = _http_tool_("https: / / api.example.com / data", "GET", headers={})

[0060] user = _sql_tool_("SELECT * FROM users WHERE id = %s", (user_id,))

[0061] log = _sql_tool_("INSERT INTO audit_log (action) VALUES ('query')",())

[0062] Subsequently, for each tool invocation request, a corresponding one-time, short-lived JSON Web Token (JWT) access token is generated. See Table 1, which illustrates the fields included in a JWT access token provided in this embodiment of the application:

[0063] Table 1

[0064]

[0065] For example, based on the aforementioned restricted code data C, three independent JWT access tokens can be generated:

[0066] JWT Access Token 1:

[0067] {

[0068] "jti": "a1b2c3d4-...",

[0069] "tool": "http",

[0070] "url_hash": "a1b2c3... (the hash value of https: / / api.example.com / data)",

[0071] "exp": 1718000000 / / Current timestamp + 30 seconds

[0072] }

[0073] JWT Access Token 2:

[0074] {

[0075] "jti": "e5f6g7h8-...",

[0076] "tool": "sql",

[0077] "table": "users",

[0078] "op": "select",

[0079] "exp": 1718000000

[0080] }

[0081] JWT Access Token 3:

[0082] {

[0083] "jti": "i9j0k1l2-...",

[0084] "tool": "sql",

[0085] "table": "audit_log",

[0086] "op": "insert",

[0087] "exp": 1718000000

[0088] }

[0089] Understandably, each JWT access token authorizes only a very specific operation. Even if the code is maliciously modified, the scope of the damage is strictly limited to the area defined by the JWT access token.

[0090] S104: In the global namespace, by filling the access token into the corresponding tool call request, a call request is sent to the external service to receive the result data sent by the external service.

[0091] First, prepare a global namespace (i.e., a sandbox environment). This global namespace only exposes security hook functions such as `_http_tool_`, `_sql_tool_`, and `_print_`. Beyond this, it does not provide any built-in functions or modules that can directly access the network, file system, or system commands, thus ensuring that code execution is completely confined within the preset security boundaries.

[0092] See Figure 3 This figure is a flowchart illustrating an execution tool invocation request according to an embodiment of this application. Subsequently, the tool invocation request is executed in the global namespace. When the security hook function corresponding to the tool invocation request is executed, the following sub-steps are performed atomically:

[0093] A1: Determine the JWT access token corresponding to the tool invocation request.

[0094] A2: Check if the real-time budget data _budget_ of the budget counter is greater than 0. If so, after deducting the budget value corresponding to this call from the real-time budget data, execute step A3.

[0095] It should be noted that the initial value of the budget counter can be dynamically set according to the user level. For example, budget=max(100,min(1000,user_tier*200)) can allocate more resources to higher-level users.

[0096] It should also be noted that the budget value for this call is related to the type of tool used in this call and the number of historical calls. For example, executing an HTTP call deducts 10 points, executing an SQL call deducts 20 points, and executing a loop statement 100 times deducts 5 points.

[0097] If _budget_ > 0, then after deducting the budget value corresponding to this call from the real-time budget data, continue to execute step A3.

[0098] If _budget_ <= 0 (i.e., the budget is exhausted), a custom BudgetExhausted exception is immediately thrown, and currently unfinished transactions are automatically rolled back to ensure data consistency. This exception will cause the execution of the entire restricted code data to be forcibly terminated, thereby effectively preventing resource abuse caused by code logic errors or malicious behavior (such as DDoS attacks, infinite loops, database crawling).

[0099] A3: Send a call request to the external service by filling the JWT access token into the Authorization header of the tool call request.

[0100] It should be noted that external services can be weather API gateways, database gateways, etc.

[0101] When an external service receives a call request, it first verifies whether the signature of the JWT access token is correct, whether the expiration (exp) field is within the validity period, and whether the target resource description in the JWT access token is consistent with the target resource description corresponding to the tool call request.

[0102] If all verifications pass, the external service performs the actual operation and returns the result data. If any verification fails, the external service immediately returns an error (e.g., 403 Forbidden) and will not execute the requested operation, thus fundamentally achieving proactive defense on the server side.

[0103] A4: Receive result data sent by external services.

[0104] If all verifications pass, the result data returned by the external service (such as weather data in JSON format, the number of rows affected by the SQL execution) will be received by the tool call request and assigned to the variable (such as data1) in the restricted code data.

[0105] It should be noted that the restricted code data will continue to execute. When the execution reaches the security hook function corresponding to the tool call request (such as _sql_tool_), the complete process from A1 to A4 above will be repeated until the code execution is completed or terminated due to an exception.

[0106] It should also be noted that the detailed information of each tool call request (including call ID, time, parameters, JWT token identifier, return code, consumption budget, etc.) is asynchronously recorded by the audit log module, forming an immutable operation chain, which fully meets the compliance requirements of ISO / IEC27001 and GDPR on operation traceability and the principle of least privilege.

[0107] Understandably, by introducing a call budget mechanism, a hard quota can be set at the resource allocation level, which effectively ensures the stability and fairness of the host system and prevents a single task from exhausting all resources.

[0108] In summary, this application provides a data processing method. Before code execution, this method proactively rewrites predefined dangerous operation nodes into corresponding security hook functions at the syntax level. Therefore, even if the AI ​​agent generates malicious code, its destructive potential is fundamentally eliminated, ensuring the code can be executed safely and controllably. Furthermore, this method generates a one-time, short-lived JWT access token for each tool call request. Because the JWT access token has a very short validity period and can only be used for specific operations, the leakage of a single token poses almost no security threat, further ensuring the code can be executed safely and controllably. Even further, this method allocates call points to each execution instance and deducts them in real time based on the tool type and computational intensity (such as loops). This achieves a hard limit on the resource consumption of a single AI agent instance, ensuring that the CPU usage, memory consumption, and network request frequency of a single instance are limited within a safe range, effectively preventing resource abuse and system instability caused by unpredictable code behavior.

[0109] See Figure 4 The figure is a schematic diagram of a data processing device provided in an embodiment of this application. The data processing device 400 includes: a data acquisition module 401, a node rewriting module 402, a token generation module 403, and a request sending module 404.

[0110] Data acquisition module 401 is used to acquire raw code data generated by the artificial intelligence agent;

[0111] The node rewriting module 402 is used to parse the original code data into an abstract syntax tree and rewrite the predefined dangerous operation nodes in the abstract syntax tree into corresponding safety hook functions to obtain restricted code data.

[0112] The token generation module 403 is used to generate a corresponding access token for each tool call request included in the restricted code data;

[0113] The request sending module 404 is used to send a call request to an external service in the global namespace by filling the access token into the corresponding tool call request, in order to receive the result data sent by the external service.

[0114] In one specific implementation, the request sending module 404 is specifically used to: obtain real-time budget data; if the real-time budget data is greater than a preset threshold, then after deducting the budget value corresponding to this call from the real-time budget data, send a call request to the external service by filling the access token into the corresponding tool call request.

[0115] In one specific implementation, the budget value corresponding to this call is related to the type of calling tool and the number of historical calls.

[0116] In one specific implementation, the data processing device 400 further includes: an execution termination module;

[0117] The execution termination module is used to terminate the execution of restricted code data if the real-time budget data is less than or equal to a preset threshold.

[0118] In summary, this application provides a data processing device. Before code execution, this device proactively rewrites predefined dangerous operation nodes into corresponding security hook functions at the syntax level. Therefore, even if the AI ​​agent generates malicious code, its destructive potential is fundamentally eliminated, ensuring the code can be executed safely and controllably. Furthermore, this device generates a one-time, short-lived JWT access token for each tool call request. Because the JWT access token has a very short validity period and can only be used for specific operations, the leakage of a single token poses almost no security threat, further ensuring the code can be executed safely and controllably. Even further, this device allocates call points to each execution instance and deducts them in real time based on the tool type and computational intensity (such as loops), achieving a hard limit on the resource consumption of a single AI agent instance. This ensures that the CPU usage, memory consumption, and network request frequency of a single instance are limited within a safe range, effectively preventing resource abuse and system instability caused by unpredictable code behavior.

[0119] This application also provides corresponding data processing equipment and computer-readable media for implementing the data processing method provided in this application.

[0120] The data processing device includes a memory and a processor. The memory is used to store instructions or code, and the processor is used to execute the instructions or code to cause the device to perform a data processing method according to any embodiment of this application.

[0121] See Figure 5 This figure is a schematic diagram of a computer-readable medium provided in an embodiment of this application. The computer-readable medium 500 stores a computer program 511, which, when executed by a processor, implements the above-described... Figure 1 The steps of the data processing method.

[0122] It should be noted that, in the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0123] It should be noted that the machine-readable medium described above in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium can be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0124] The aforementioned computer-readable medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.

[0125] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.

[0126] While several specific implementation details are included in the foregoing discussion, these should not be construed as limiting the scope of this application. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.

[0127] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.

Claims

1. A data processing method, characterized in that, The method includes: Obtain the raw code data generated by the AI ​​agent; The original code data is parsed into an abstract syntax tree, and the predefined dangerous operation nodes in the abstract syntax tree are rewritten into corresponding safety hook functions to obtain restricted code data; For each tool call request included in the restricted code data, generate a corresponding access token; In the global namespace, by filling the access token into the corresponding tool call request, a call request is sent to the external service in order to receive the result data sent by the external service.

2. The method according to claim 1, characterized in that, The step of sending a call request to an external service by filling the access token into the corresponding tool call request includes: Get real-time budget data; If the real-time budget data is greater than a preset threshold, then after deducting the budget value corresponding to this call from the real-time budget data, a call request is sent to the external service by filling the access token into the corresponding tool call request.

3. The method according to claim 2, wherein the budget value corresponding to the current call is related to the type of calling tool and the number of historical calls.

4. The method according to claim 2, characterized in that, The method further includes: If the real-time budget data is less than or equal to the preset threshold, the execution of the restricted code data is terminated.

5. A data processing apparatus, characterized in that, The device includes: a data acquisition module, a node rewriting module, a token generation module, and a request sending module; The data acquisition module is used to acquire the raw code data generated by the artificial intelligence agent; The node rewriting module is used to parse the original code data into an abstract syntax tree, and rewrite the predefined dangerous operation nodes in the abstract syntax tree into corresponding safety hook functions to obtain restricted code data; The token generation module is used to generate a corresponding access token for each tool call request included in the restricted code data; The request sending module is used to send a call request to an external service in the global namespace by filling the access token into the corresponding tool call request, so as to receive the result data sent by the external service.

6. The apparatus according to claim 5, characterized in that, The request sending module is specifically used to: obtain real-time budget data; if the real-time budget data is greater than a preset threshold, then after deducting the budget value corresponding to this call from the real-time budget data, send a call request to the external service by filling the access token into the corresponding tool call request.

7. The apparatus according to claim 6, characterized in that, The budget value corresponding to this call is related to the type of calling tool and the number of historical calls.

8. The apparatus according to claim 6, characterized in that, The device further includes: an execution termination module; The execution termination module is used to terminate the execution of the restricted code data if the real-time budget data is less than or equal to the preset threshold.

9. A data processing device, characterized in that, The device includes: a memory and a processor; The memory is used to store programs; The processor is configured to execute the program to implement the various steps of the data processing method as described in any one of claims 1 to 4.

10. A computer-readable medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the various steps of the data processing method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Cloud service security broker and proxy

    CN106031118A

  • Data processing method and device, electronic equipment and storage medium

    CN114329471A