2025-05-23 18:30:02 +08:00
---
sidebar_position: 13
slug: /code_component
---
# Code component
A component that enables users to integrate Python or JavaScript codes into their Agent for dynamic data processing.
---
## Scenarios
A **Code** component is essential when you need to integrate complex code logic (Python or JavaScript) into your Agent for dynamic data processing.
2025-08-01 20:22:27 +08:00
## Configurations
2025-05-23 18:30:02 +08:00
2025-08-01 20:22:27 +08:00
### Input
2025-05-23 18:30:02 +08:00
2025-08-01 20:22:27 +08:00
You can specify multiple input sources for the **Code** component. Click **+ Add variable** in the **Input variables** section to include the desired input variables.
2025-05-23 18:30:02 +08:00
2025-08-01 20:22:27 +08:00
### Code
2025-05-23 18:30:02 +08:00
2025-05-26 19:36:35 +08:00
This field allows you to enter and edit your source code.
2025-08-01 20:22:27 +08:00
#### A Python code example
2025-05-23 18:30:02 +08:00
```Python
def main(arg1: str, arg2: str) -> dict:
return {
"result": arg1 + arg2,
}
```
2025-08-01 20:22:27 +08:00
#### A JavaScript code example
2025-05-23 18:30:02 +08:00
```JavaScript
const axios = require('axios');
async function main(args) {
try {
const response = await axios.get('https://github.com/infiniflow/ragflow');
console.log('Body:', response.data);
} catch (error) {
console.error('Error:', error.message);
}
}
```
2025-08-01 20:22:27 +08:00
### Return values
You define the output variable(s) of the **Code** component here.
### Output
The defined output variable(s) will be auto-populated here.
2025-05-23 18:30:02 +08:00