Introduction
Thetool
primitive lets you define AI tools using XanoScript.
Each AI tool corresponds to a function that an AI agent can call to perform specific tasks — but expressed in code.
AI tools will typically:
- Declare their name and description
- Include instructions for the AI agent
- Accept inputs from the agent
- Run one or more operations in a stack
- Return a response
Anatomy
Every XanoScript AI tool follows a predictable structure. Here’s a quick visual overview of its main building blocks — from declaration at the top to settings at the bottom.You can find more detail about each section by continuing below.
Declaration
Every AI tool starts with a declarative header that specifies its type and name.XanoScript
Element | Required | Description |
---|---|---|
tool | ✅ | Declares an AI tool primitive. |
tool_name | ✅ | The unique name for the tool (e.g., LogActivity ). |
description | no | Optional human-readable description of the tool. |
instructions | no | Optional human-readable instructions for the tool. |
Section 1: Inputs
Theinput
block defines the data that the AI agent will provide when calling this tool. You can declare types, optionality, and filters:
Hover over this image to see the XanoScript version
- Declare its type (
text
,email
,password
, etc.) - Mark it as optional (
?
) - Apply filters (
filters=trim|lower
)
Learn more about the available data types
Section 2: Stack
Thestack
block contains the actual logic that will be executed when the AI tool is called.
Hover over this image to see the XanoScript version
Each block inside stack corresponds to a function available in Xano’s visual builder:
db.add
— Insert a new record into the databasedb.get
— Fetch a record from the databaseprecondition
— Guard execution with a conditionsecurity.create_auth_token
— Generate an authentication token
Review all available functions and their XanoScript in the function reference
Section 3: Response
Theresponse
block defines what data your AI tool returns to the agent:
Hover over this image to see the XanoScript version
- The
value
assignment determines the JSON returned to the AI agent. - Variables captured in the stack (e.g.,
$log1
) can be returned here.
Settings
AI tool primitives support several optional settings that control tagging and version history. These settings are defined at the root level of the tool block, after the input, stack, and response blocks. They affect how the tool is organized and documented.Setting | Type | Required | Description |
---|---|---|---|
description | string | no | A human-readable description of the AI tool. Appears in the builder and documentation. |
tags | array[string] | no | A list of tags used to categorize and organize the tool in your workspace. |
history | object | no | Configures version inheritance and history behavior. {inherit: true} allows this tool to inherit history settings from the workspace. |
Detailed Example
Below, you’ll see a complete example of a typical AI tool for logging user activity.XanoScript
What’s Next
Now that you understand how to define AI tools in XanoScript, here are a few great next steps:Explore the function reference
Learn about the built-in functions available in the stack to start writing more complex logic.
Try it out in VS Code
Use the XanoScript VS Code extension with Copilot to write XanoScript in your favorite IDE.
Learn about Custom Functions
They work just like AI tools, but let you create reusable logic, and are a great next step when learning XanoScript.