Skip to main content

Introduction

The tool 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
tool <tool_name> {
description = "<what this tool does>"
instructions = "<optional human-readable instructions for the tool>"
...
}
ElementRequiredDescription
toolDeclares an AI tool primitive.
tool_nameThe unique name for the tool (e.g., LogActivity).
descriptionnoOptional human-readable description of the tool.
instructionsnoOptional human-readable instructions for the tool.

Section 1: Inputs

The input 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

For each input, you can:
  • 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

The stack 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 database
  • db.get — Fetch a record from the database
  • precondition — Guard execution with a condition
  • security.create_auth_token — Generate an authentication token
The syntax mirrors how you’d configure these functions visually, but expressed textually. The actual behavior is the same — refer to the function’s existing docs for complete details.

Review all available functions and their XanoScript in the function reference


Section 3: Response

The response 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.
SettingTypeRequiredDescription
descriptionstringnoA human-readable description of the AI tool. Appears in the builder and documentation.
tagsarray[string]noA list of tags used to categorize and organize the tool in your workspace.
historyobjectnoConfigures 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
tool LogActivity {
  description = "Logs any user activity while they are communicating with the agent"
  instructions = "Use this tool to add a new record to the logging table. This tool should be used any time the user sends you a message and you respond. You'll log what the user said, what you said in response, and why you responded the way you did, and/or took the action(s) that you chose to take."
  
  input {
    text user_message? filters=trim
    text agent_message? filters=trim
    text why? filters=trim
  }

  stack {
    db.add log {
      data = {
        created_at   : "now"
        user_message : $input.user_message
        agent_message: $input.agent_message
        why          : $input.why
      }
    } as $log1
  }

  response {
    value = $log1
  }

  tags = ["logging", "activity"]
  history = {inherit: true}
}


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.
https://mintlify.s3.us-west-1.amazonaws.com/xano-997cb9ee/images/vscode.svg

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.
I