Node Function
Code Node belongs to Information Processing Node. Tencent Cloud Agent Development Platform (Tencent Cloud ADP) supports using an IDE within the code node, allowing users to write Python code (with built-in commonly used packages such as numpy) to process business logic and return results, such as data transformation and scientific computing.
Directions
Input Variables
Input variables take effect only within the same node and cannot be used cross-node. Support up to 50 input variables to meet scene requirements. Click "Add" to configure input variables as follows.
|
Variable Name | The variable name can only contain letters, digits, or underscores, must start with a letter or underscore, and is mandatory. |
Description | Description of this variable. Optional. |
Data source | The data source of this variable supports two options: "refer" and "input". "Refer" allows selecting output variables from all preceding nodes, while "input" supports manually filling in a fixed value. |
Type | The data type of this variable is unselectable and defaults to the "refer" variable type or the "input" string type. |
Code
Click "Edit Code" to unfold the built-in python code editor.
When editing code, save the function named main. Both input and output are dict class. Call the input variable via params.get('input'). The final result will be returned as a json string. Do not return objects unsupported by json.dumps directly.
After editing the code, you can debug by filling in the input variable of the node in the "Input for testing" box. Click the "Run" button to execute the code, and view the corresponding result in the "Output Result" box.
Output Variable
The output variable processed by this node is empty by default. Users can manually add output variables or use the "Parsed to output variables" feature to automatically fill them from the code execution results. It also contains runtime error information Error (data type is object, this field is empty during normal operation).
Handling error
Exception handling can be enabled manually, supporting exception retry and output content configuration for anomalies. The configuration content is as follows.
|
Max Retry Attempts | The maximum number of times to rerun when the node is running exceptionally. If retries exceed the set number of times, consider the node call failed and return the "output variable for anomalies" content, defaulting to 3. |
Retry Interval | Interval between each rerun, default is 1 second. |
Exception Output Variable | The output variable returned when retries exceed the maximum number. |
Application Example
Write an article based on the user's input topic and style, and split the outline generated by the LLM node into an array of chapter headings and content summaries via the code node.
Code node configuration as follows: