tencent cloud

Code Node
Last updated:2026-02-04 11:02:42
Code Node
Last updated: 2026-02-04 11:02:42

Node Function

The code node belongs to the Information Processing Node. Tencent Cloud Agent Development Platform supports using IDE inside the code node, allowing users to write Python code (with built-in common Python packages such as NumPy) and JavaScript code to process business logic and return response 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.
Configuration
Description
Variable Name
The variable name can only contain letters, digits, or underscores, must start with a letter or underscore. Required.
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. Required
Type
The data type of this variable cannot be selected and defaults to the variable type of "refer" or the string type of "input".

Code

Click Edit Code to unfold the built-in code editor. It defaults to Python and can be manually switched to another programming language.



After switching the programming language, the content in the IDE will be cleared and automatically replaced with the code template of the new language. Please note: when switching back to the original language again, the system does not reserve the previous edit content.
Regardless of the programming language used, when editing code, define function named main. For Python language, in the node, input and output are dict, call input variable via params.get('input'). For JavaScript language, input and output are object, call input variable via params.input.
The final result will be returned in JSON string form. Please ensure the return content can be serialized (such as number, string, list, dictionary and other common classes), avoid returning objects that cannot be serialized by `json.dumps()`.
After editing the code, you can debug by filling in the input variable of the node in the Input for testing box. Click Run to execute the code, and view the response result in the Output Result box.
The built-in Python packages in the code executor are as follows. Importing Java related packages or custom dependencies is not currently supported.
Package Name
Edition
Description
python
>= 3.9, < 3.13
Specify the version range of the Python runtime environment to ensure project compatibility.
ipykernel
^ 6.29.4
Provide Python kernel support for Jupyter Notebook/Lab.
pydantic
2.8.2
For defining data model and automatic validation of input data, commonly used for API request verification.
python-dotenv
>= 1.0.0
Load environment variables in the .env file.
jinja2
>= 3.0.0
A powerful template engine to generate HTML or configuration files.
aiohttp-jinja2
>= 1.0
Integrate Jinja2 Template into aiohttp Web framework to generate dynamic page.
pyzmq
>= 25.0.0
Python API for ZeroMQ, used for high performance distributed message communication.
fastapi
>= 0.110.0
High performance Web API framework, commonly used for rapid development of RESTful/GraphQL services.
uvicorn
>= 0.30.0
ASGI server for running FastAPI, supporting async high-concurrency.
python-multipart
>= 0.0.9
Parser for handling HTTP forms and file upload.
fastapi-utilities
>= 0.2.0
Provide additional tools for FastAPI (such as background job scheduling, dependency management).
uhashring
^ 2.3
Consistent hashing algorithm library for node selection in distributed cache/storage systems.
psutil
>= 6.0.0
Obtain system operating status (CPU, memory, Disk, network), commonly used for monitoring.
nbformat
>= 5.0.0
Read-write Jupyter Notebook (.ipynb) files.
nbclient
>= 0.10.0
Automatically execute Jupyter Notebook in code and collect results.
xlsxwriter
^ 1.3.7
Generate Excel files (with format, charts), commonly used for report export.
sseclient-py
>= 1.8.0
Listen to server-sent events (SSE) and implement real-time message push.
python-prctl
>= 1.8.1
Control Linux process attributes (such as name, power), commonly used for system-level applications.
prometheus_client
^ 0.21.0
Export application monitoring metrics for Prometheus collection and display.
flask
^ 3.0.0
Lightweight Web framework, suitable for rapid development of small websites and APIs.
numpy
1.26.4
Numerical computation library, offering efficient multi-dimensional array operations, the basis of scientific computing.
sympy
1.13.3
Symbolic computation library, capable of algebraic operations, equation solving, and symbolic calculus.
levenshtein
0.25.0
Calculate string similarity (Levenshtein distance), used for fuzzy matching.
cryptography
43.0.0
Provide encryption, decryption, and signature cryptography features.
thefuzz
0.22.1
String fuzzy matching tool, used for search or data cleansing.
branca
0.8.1
Generate HTML/JS components, often used in conjunction with Folium for map visualization.
folium
0.19.4
Generate interactive maps with Python (based on Leaflet.js).
basemap
1.4.1
Plot maps on matplotlib, commonly used for geographic visualization.
basemap-data
1.3.2
Basemap requires geographic data files.
pyecharts
2.0.8
Generate ECharts charts with Python, supporting interactive visualization.
tencentcloud-dlc-connector
^ 1.2.1
Connect to Tencent Cloud DLC (Data Lake Compute) SDK.
python-pptx
^ 1.0.2
Generate and modify PowerPoint files, commonly used for automated report.
clickhouse-driver
^ 0.2.9
Python Client for ClickHouse Database.
openai
>= 1.0.0
Official library for calling OpenAI APIs such as GPT and DALL·E.
requests
>= 2.30.0
The most commonly used HTTP request library for calling Web APIs.
urllib3
>= 2.0.0
Underlying HTTP library, core dependency of requests.
pandas
1.5.3
Provide DataFrame table structure, suitable for data cleansing and analysis.
pyyaml
>= 6.0.0
Read and write to the YAML configuration file.
click
>= 8.0.0
A library for quick command line tool writing.
cycler
>= 0.12.0
Generate style loop (color, line type), dependency of matplotlib.
xlrd
>= 2.0.0
Read an Excel file (mainly .xls format).
openpyxl
>= 3.0.0
Read-write .xlsx Excel file, dependency of pandas.
tabulate
>= 0.9.0
Render table data as Markdown/HTML/plain text tables.
matplotlib
3.4.3
Python's most basic plotting library, support various charts.
seaborn
^ 0.13.2
An advanced statistical plotting library built on matplotlib, offering more beautiful plots.
scikit-learn
^ 1.5.0
Machine learning library, providing algorithms such as categorization, regression, clustering, and dimensionality reduction.
gmssl
>= 3.2.1
SM algorithm implementation and encrypt communication cryptography library.

AI Code Generation

The system has a built-in AI code generation feature that supports users in describing requirements through natural language. When users select code content in the editor, the system will automatically display an AI Optimization button. Clicking this button will pop up an AI request box for filling in specific generation requirements.



Enter a description or modification request for the code in the request box, then click "Generate Code". The AI code assistant will automatically perform code completion or regeneration based on the input description and selected code snippet.




To obtain more accurate generated results, it is advisable to select all code before generation so that AI can fully understand the context, thus generating a code framework with complete structure and consistent variable naming.
After generation completed, the system will display AI-generated code suggestions. If satisfied with the generated result, click the "Accept" button to replace the current code with the AI-generated code. If not satisfied, click the "Reject" button to discard this modification and reserve the original content.

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 (off by default), supporting timeout trigger processing, exception retry, and exception handling method configuration. The configuration content is in the table below.
Currently only support duration set by the user for "timeout trigger processing", other exceptions are automatically identified by the platform.
Configuration
Description
Timeout Trigger Handling
The maximum duration for node operation triggers exception handling when exceeded. The default timeout value for code nodes is 60s, with a timeout setting range of 1-60s.
Max Retry Attempts
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 execute the exception handling method below. Default is 3 times.
Retry Interval
Interval between each rerun, default is 1 second.
Handling Method
Support three types: "Output Specific Content", "Execution Exception Flow", and "Interrupt Flow".
Output Content
Select the exception handling method as "Output Specific Content". The output variable returned when retries exceed the maximum number.

Select the exception handling method as "Output Cpecific content". When an exception occurs, the workflow will not be interrupted. After exception retry, the node will return directly the output variable and variable value set by the user in the output content.
Select the exception handling method as "Execution Excption Flow". When an exception occurs, the workflow will not be interrupted. After exception retry, the node will execute the user-defined exception handling process.

Select the exception handling method as "Interrupt Flow". There are no more settings. When an exception occurs, the workflow execution is interrupted.

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:




Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback