Code Tool
Give AI agents the ability to execute custom JavaScript code as a tool
Written By pvdyck
Last updated About 3 hours ago
Code Tool
The Code Tool lets you define a custom JavaScript tool that an AI agent can invoke during its reasoning process. Use it for calculations, data transformations, or logic the LLM cannot do natively.
How It Works
You write a JavaScript function, give it a name and description, and optionally define input parameters. The agent sees this as a callable tool and invokes it when its reasoning requires it.
Parameters
Code Environment
Connects To
Example
Name: extractDomainDescription: "Extracts the domain from an email address"Code:
const email = query;return email.split('@')[1] || 'invalid';Limitations
- Executes in the QuickJS sandbox β synchronous JavaScript only.
- No network access (
fetch,XMLHttpRequestunavailable). - No
console.logβ use return values for output. - Must be connected to an Agent node β cannot run standalone.
Tips
- Write a clear, specific Description β this is how the agent decides when to use your tool.
- Keep code simple and focused on one task (Single Responsibility).
- Define an Input Schema when your tool needs multiple parameters instead of a single string.
- For pure math, prefer the Calculator tool. Use Code Tool for string manipulation, formatting, or custom logic.