Overview
The Code Tool lets your agent run JavaScript code inline during a call. It’s ideal for lightweight tasks like data transformation, formatting, and simple read-only API lookups without needing to set up a custom function endpoint.Setup
1
Add the tool
In your agent’s Functions section, click Add Function and select Code Tool.
2
Name and describe it
Give the tool a unique name and a clear description so the LLM knows when to invoke it.
3
Write your JavaScript
Use the available globals in your script:
Standard built-ins (
Math, JSON, Date, Array methods) work normally. require and import are not available.4
Extract response values
Map JSON paths from your script’s return value to dynamic variable names for use later in the conversation.
5
Configure speech
Optionally set what the agent says while the code runs or after it completes.
6
Update your prompt
Tell the agent when to invoke the tool: