Code tools
Describe a small tool, let Nagent write and run the code for it, test it on examples, and give it to your agents. A Beta feature.
Browse documentation
What a code tool is
A code tool is a small tool that Nagent writes for you. You describe what it should do and give examples of its input and output, Nagent writes the code, checks it against your examples, runs it on its own, and registers it as a connector your agents can call. Code tools are Beta.
Use one when you want a calculation or a rule your agents can call, such as a rate lookup from a table you paste, a unit conversion, or a check that a reference number is well formed. For an API you already have, see adding a connector.
What a code tool cannot do in this version
- It has no internet. It cannot call another service or fetch a page.
- It has no data store. It keeps nothing between calls.
- It works on its input only. Whatever it answers is computed from what the agent sent it in that call.
If the job needs an outside system, add a connector for that system instead.
Build one
- Open Connectors and press Build a code tool.
- Say what the tool should do in the box, or press one of the examples. Press Draft it.
- Read the draft: the tool's name and purpose, then for each operation what it does, what it takes, what it gives back and the examples it must get right. To change it, write the change under Describe a change, for example "also return the median", and press Change it. The draft is replaced with the changed one.
- If the request needs the internet or stored data, the draft says so and points you to Add a connector instead.
- Edit the details opens every field, filled from the draft: the Operation name, What it does, the Input schema and Output schema as JSON, and Examples. Use it to set anything by hand.
- Press Build the tool. The build runs in stages (writing the tool, checking, building, starting, testing on your examples) and the list under Code tool builds shows where it is.
Drafting uses a few credits. The build is what costs about 300 credits.
Your agent can also ask for a code tool in a chat. The request waits on an approval card, and nothing is built until a person approves it.
Examples are the test
Give one to five examples for every operation, each an input and the output you expect. Nagent writes the code to produce those outputs and then runs the code on them, so a tool that does not match its examples does not go live. Pick examples that cover the edges: an empty value, the largest case, a case that should be refused. Do not put passwords, keys or tokens in an example; a build that has one is refused.
Review and test before you confirm
When a build finishes, the list says Built, being added to your connectors, then Ready for review with a Review link beside it once the tool is a connector. It waits in review, so no agent can use it yet.
- Press Review and read the operations as built.
- Test appears only on read operations (a GET or HEAD, or an operation declared as a read). It sends the operation's first example as its input, so it checks that the tool answers one of your own cases. A write operation cannot be tested here. A read must pass its test before you can confirm it as a read.
- Press Confirm on each operation to record what kind it is, or disable the operations you do not want.
- Once every operation is confirmed or disabled, press Activate. That is what makes the tool live. To change the tool instead, build again with a changed description.
A code tool always uses signed requests, so a call from an agent carries a signature the tool checks. There is nothing to set up. The tool holds its own secret, so it has no Rotate secret button; build it again to change it.
What a build costs
A build uses credits. Before it starts, Nagent checks that the workspace has about 300 credits and that the agent asking has room in its own budget. A build that ran is charged what it really cost when it finishes, whether it succeeds or fails. If a finished build reports no cost, the estimate of about 300 credits is charged; a failed build that reports no cost is not charged. A build that never started is not charged. A workspace can run two builds at once and ten a day.
Running a confirmed tool from an agent is a normal connector call.
When a build fails
The list shows Failed, the reason, and any checks that did not pass. Change the description or an example and build again. A build that never started shows as Failed with "The build did not start." after ten minutes, is not charged, and stops counting toward the two builds at once.