Skip to main content
A code tool runs a small piece of Python or JavaScript during the call. Use one when you need to work something out rather than just fetch it — a price with rules in it, a date calculation, or tidying up a messy response from somewhere else. If you’re only calling an API, use an HTTP tool instead.

Writing one

Your code gets the arguments the assistant worked out in a variable called _input. Print your result as JSON — whatever you print is what the assistant reads back.
JavaScript works the same way, with _input and console.log:
Print a small object with clearly named fields. The assistant reads those names, so total_eur tells it more than t.
Only the printed JSON comes back. If you print several lines, the last valid JSON line is used; if nothing parses as JSON, the assistant gets the raw text instead. Print once, at the end.

Reaching other values

Besides _input, you can drop variables straight into your code before it runs:
_context holds the same call details programmatically.

Setting one up

Using libraries

You can add packages — pip for Python, npm for JavaScript — with a pinned version:
requests is kept warm, so Python code using it starts immediately. Anything else is installed the first time it’s needed, which adds a few seconds to that call. Pin versions so a release upstream doesn’t change behaviour mid-week.

Where it runs

Your code runs in an isolated sandbox, separate from everything else. It can’t reach your other tools, your data, or the call itself — it gets its arguments, runs, and prints. Keep it short. A code tool runs while a caller is waiting, so anything slow is better done in your own system behind an HTTP tool.

Testing

Test runs your code with arguments you supply and shows the result, so you can work out the logic before attaching the tool to an assistant.