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

ParameterDescription
NameTool name the agent sees (e.g., "formatCurrency", "validateEmail"). Keep it descriptive.
DescriptionExplains what the tool does β€” the agent uses this to decide when to call it. Be specific.
LanguageJavaScript or Python. Note: on indie.money, only JavaScript is available (runs in the platform sandbox).
CodeThe JavaScript function body. Receives input via query (string) or structured input parameters. Must return a string.
Input SchemaOptional JSON Schema defining structured input parameters the agent provides when calling the tool.

Code Environment

FeatureAvailable
Synchronous JSYes β€” variables, loops, conditionals, string manipulation, math
query parameterThe agent's input β€” a string (plain tools) or object (with Input Schema)
Return valueMust return a string. Numbers are auto-converted. Objects are JSON-stringified
fetch / HTTPNo β€” no network access in the sandbox
console.logNo β€” no console output
Async / PromisesNo β€” synchronous code only

Connects To

Parent NodeDescription
AgentRegisters as a tool the agent can call during reasoning.

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, XMLHttpRequest unavailable)
  • 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.