Code node executes JavaScript code when the agent enters it. Unlike custom functions, code nodes run directly in UponAI’s sandbox — no external server needed. The node is not intended for having a conversation with the user, but the agent can still talk while code is running if needed.Documentation Index
Fetch the complete documentation index at: https://documentation.uponai.com/llms.txt
Use this file to discover all available pages before exploring further.
Code Node vs Custom Function
| Code Node | Custom Function | |
|---|---|---|
| Runs | JavaScript in UponAI’s sandbox | HTTP request to your server |
| Requires | Nothing — runs directly | Your own API endpoint |
| Best for | Data transformation, simple API calls, logic & calculations | Complex integrations, accessing internal systems |
| Max code size | 5,000 characters | N/A (runs on your server) |
Write Your Code
Write JavaScript
Write your JavaScript code in the editor. You have access to dynamic variables, call metadata, and the fetch function for HTTP requests.
Set response variables (optional)
Use Store Fields as Variables to extract values from your code’s return value and save them as dynamic variables. Specify a variable name and the JSON path to the value.For example, if your code returns
These variables can then be referenced as
{ "status": "shipped", "estimated_delivery": "March 25" }:| Variable Name | JSON Path | Extracted Value |
|---|---|---|
| order_status | status | ”shipped” |
| delivery_date | estimated_delivery | ”March 25” |
{{order_status}} and {{delivery_date}} in other nodes.JavaScript Environment
Your code runs in a JavaScript sandbox with the following globals available. The code editor provides autocomplete for globals, dynamic variable names, and built-in functions.dv — Dynamic Variables
Access your agent’s dynamic variables as properties on the dv object. All values are strings.
metadata — Call Metadata
Access metadata passed when the call was created via the API.
fetch(url) — HTTP Requests
Make HTTP requests to external APIs. Works like the standard Fetch API.
console.log() — Debugging
Logs appear in the test output panel when using Run Code, and are also available in call logs.
- Standard JavaScript built-ins available:
Math,JSON,Date,Array,Object,Stringmethods, etc. - External packages (
require,import) are not available — usefetch()for external integrations - Code is limited to 5,000 characters
Examples
Format data from dynamic variables
Fetch data from a public API
Conditional logic with API call
Security and Architecture Guidance
| Use case | Recommended |
|---|---|
| Formatting, calculations, string cleanup | Code Node |
| Simple read-only lookups to low-risk public APIs | Code Node, with caution |
| Accessing internal systems or private APIs | Custom Function |
| Writing to CRM, EHR, booking, payment, or ticketing systems | Custom Function |
| Workflows requiring secrets, audit logs, retries, idempotency, or policy enforcement | Custom Function |
When Can Transition Happen
If Wait for Result is turned off:- Speak During Execution on → transitions once agent is done talking
- Speak During Execution off → transitions immediately after code starts running
- User interrupts → transition happens once user is done speaking
- Speak During Execution on → transitions once code finishes and agent is done talking
- Speak During Execution off → transitions once code finishes
- User interrupts → transition happens once code finishes and user is done speaking
Node Settings
| Setting | Description |
|---|---|
| Speak During Execution | Agent says something while code runs. Choose Prompt (LLM generates) or Static Text (exact text). |
| Wait for Result | Agent waits for code to finish before transitioning. Guarantees result and variables are ready at the next node. |
| Timeout | How long code can run before timing out. Range: 5–60 seconds. Default: 30 seconds. |
| Global Node | See Global Node guide. |
| Block Interruptions | Agent will not be interrupted by user when speaking. |
| LLM | Choose a different model — used for speak-during-execution message generation when set to Prompt. |
| Fine-tuning Examples | Fine-tune transition behavior. See Finetune Examples guide. |