Code Tool
Give AI agents the ability to execute custom JavaScript code as a tool
Written By pvdyck
Last updated 18 days 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';Error Handling
If your tool code throws an error, the error message is returned to the agent as a string (e.g., There was an error: "TypeError: x is not a function"). The agent can then decide to retry or adjust its approach. Tool errors do not crash the agent.
Input Schema
When Input Schema is enabled, you can define structured parameters. Provide a JSON example of the input your tool expects β the platform generates the schema automatically. The agent then sends a JSON object matching that structure instead of a plain string.
Example input (the platform generates the schema from this):
{"city": "London", "unit": "celsius"}Your code then receives query as an object:
const city = query.city;const unit = query.unit;return `Temperature in ${city}: 22 ${unit}`;Limitations
- Executes in the secure code 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
- Must return a value β returning nothing will produce an error
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.
Related
Status
This integration is available but has not yet been independently validated on indie.money. If you encounter issues, please report them.