> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xano.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XanoScript for AI Agents

> Learn how to define and configure AI Agents using XanoScript.

## Introduction

AI Agents in Xano allow you to define intelligent, autonomous workflows powered by models like Gemini, OpenAI, or Claude, directly in XanoScript.

## Anatomy

Every XanoScript Agent follows a predictable structure.

Here’s a quick visual overview of its main building blocks — from **declaration** at the top to **tools** at the bottom.\
\
It's a little different from other primitives, because the settings are defined in the `llm` block, instead of a separate settings block.\
\
You can find more detail about each section by continuing below.

```mermaid theme={null}
flowchart LR
    A[Declaration] --> B[LLM] --> C[Tools]
    style A fill:#f5f5f5,stroke:#ccc,stroke-width:1px
    style B fill:#f5f5f5,stroke:#ccc,stroke-width:1px
    style C fill:#f5f5f5,stroke:#ccc,stroke-width:1px
```

## Section 1: Declaration

Every Agent starts with a **declarative header** that specifies its type, name, and description.

```mermaid theme={null}
flowchart TB
A[Declaration] --> B[LLM] --> C[Tools]
style A fill:#cdeaff,stroke:#0077cc,stroke-width:2px
style B fill:#f5f5f5,stroke:#ccc,stroke-width:1px
style C fill:#f5f5f5,stroke:#ccc,stroke-width:1px
```

```java XanoScript lines icon="code" theme={null}
// This agent answers the user's question to the best of its ability.
agent "Answer a Question" {
  canonical = "Zwt3YW_3"
  tags = ["tag1", "tag2"]
}
```

| Element | Required | Description |
| - | - | - |
| `agent` | ✅ | Declares an Agent primitive and its name. |
| `description` | no | A short summary of the agent. May also appear as a “//” comment above the block. |
| `canonical` | no | The canonical ID for this Agent. |
| `tags` | no | An array of strings used to categorize or filter Agents. |

***

## Section 2: LLM

The `llm` block defines how your Agent interacts with its underlying AI model. All standard model configuration options available in the UI are represented here.

These are a little different from other primitives, because the settings available can change based on the model chosen.

> [!NOTE]
>
> The provider blocks documented on this page cover the four hosts listed below. Agents can also run on **Azure AI Foundry**, **OpenRouter**, and **LiteLLM** — to get the exact XanoScript for one of those, configure the agent in the UI and pull it with [`xano workspace pull`](https://docs.xano.com/xano-cli/push-pull#pull).

```mermaid theme={null}
flowchart TB
A[Declaration] --> B[LLM] --> C[Tools]
style B fill:#cdeaff,stroke:#0077cc,stroke-width:2px
style A fill:#f5f5f5,stroke:#ccc,stroke-width:1px
style C fill:#f5f5f5,stroke:#ccc,stroke-width:1px
```

```java XanoScript lines icon="code" theme={null}
llm = {
  type         : "google-genai"
  system_prompt: "You are a helpful AI Agent that tries to answer the user's query using the best possible information. You are also required to log each interaction using the logging tool."
  max_steps    : 5
  prompt       : "Here is the user's query: {{ $args.query }}"
  ...
```

| Element | Required | Description |
| - | - | - |
| `type` | ✅ | The model host provider. Documented below: `openai`, `anthropic`, `google-genai`, `xano-free`. Azure AI Foundry, OpenRouter and LiteLLM are also supported as hosts — see [Agents](https://docs.xano.com/ai-tools/agents.md). |
| `system_prompt` | no | Core instructions defining the Agent’s role and behavior. |
| `max_steps` | no | How many steps (tool calls) the Agent can take before stopping. |
| `prompt` | no | Additional context or message prompt. Use `{{ $args.property }}` for dynamic data. |
| `api_key` | no | API key for the chosen model provider. |
| `model` | no | Specific model to use. |

### Xano Free Model (Gemini)

These settings are specific to the Xano Free Model (Gemini).

```java XanoScript lines icon="code" theme={null}
  temperature     : 1
  search_grounding: false
  thinking_tokens : 0
  include_thoughts: false
```

| Element | Required | Description |
| - | - | - |
| `temperature` | no | Controls randomness of output. Lower = more deterministic. |
| `search_grounding` | no | For Gemini, whether to enable Google Search grounding. |
| `thinking_tokens` | no | For reasoning models, sets thinking budget. |
| `include_thoughts` | no | Whether to include reasoning traces in the response. |

### Anthropic (Claude)

```java XanoScript lines icon="code" theme={null}
  api_key      : "abc123"
  model        : "claude-4-sonnet-20250514"
  temperature  : 1
  reasoning    : true
```

| Element | Required | Description |
| - | - | - |
| `api_key` | ✅ | API key for the chosen model provider. |
| `model` | ✅ | Specific model to use. |
| `temperature` | no | Controls randomness of output. Lower = more deterministic. |
| `reasoning` | no | Whether to include reasoning traces in the response. |

### Google Generative AI (Gemini)

```java XanoScript lines icon="code" theme={null}
  api_key         : "abc123"
  model           : "gemini-2.5-flash"
  temperature     : 1
  search_grounding: false
  thinking_tokens : 0
  include_thoughts: false
```

| Element | Required | Description |
| - | - | - |
| `api_key` | ✅ | API key for the chosen model provider. |
| `model` | ✅ | Specific model to use. |
| `temperature` | no | Controls randomness of output. Lower = more deterministic. |
| `search_grounding` | no | For Gemini, whether to enable Google Search grounding. |
| `thinking_tokens` | no | For reasoning models, sets thinking budget. |
| `include_thoughts` | no | Whether to include reasoning traces in the response. |

### OpenAI

OpenAI settings are similar to the other models, but also includes some additional advanced settings.

#### OpenAI Settings

```java XanoScript lines icon="code" theme={null}
  api_key         : "abc123"
  model           : "gpt-5-mini"
  temperature     : 1
  reasoning_effort: ""
```

| Element | Required | Description |
| - | - | - |
| `api_key` | ✅ | API key for the chosen model provider. |
| `model` | ✅ | Specific model to use. |
| `temperature` | no | Controls randomness of output. Lower = more deterministic. |
| `reasoning_effort` | no | For reasoning models, sets how much effort the model spends thinking during generation. |

#### OpenAI Advanced Settings

```java XanoScript lines icon="code" theme={null}
  organization    : ""
  project         : ""
  compatibility   : "strict"
```

| Element | Required | Description |
| - | - | - |
| `organization` | no | The organization to use. |
| `project` | no | The project to use. |
| `compatibility` | no | The compatibility level to use. |

***

## Section 3: Tools

The `tools` block defines the tools that an Agent can use. Tools are functions that an Agent can call as part of its steps to resolve the task at hand.

```mermaid theme={null}
flowchart TB
    A[Declaration] --> B[LLM] --> C[Tools]
    style C fill:#cdeaff,stroke:#0077cc,stroke-width:2px
    style A fill:#f5f5f5,stroke:#ccc,stroke-width:1px
    style B fill:#f5f5f5,stroke:#ccc,stroke-width:1px
```

```java XanoScript lines icon="code" theme={null}
tools = [
  {name: "Get_User_Info"}
  {name: "Create_Support_Ticket"}
]
```

| Element | Required | Description |
| - | - | - |
| `tools[]` | ✅ | The tools that the Agent can use. |
|       `name` | ✅ | The name of the tool. |

***

## Full Example

Below is a more complete Agent definition that combines multiple settings:

```java XanoScript lines icon="code" theme={null}
// Handles customer inquiries and support requests automatically.
agent "Customer Support Agent" {
  canonical   = "SUPPORT_AGENT_001"
  tags        = ["support", "customer-service"]

  llm = {
    type            : "anthropic"
    system_prompt   : "You are a helpful Customer Support Agent that resolves issues efficiently..."
    max_steps       : 8
    prompt          : "Customer inquiry: {{ $args.customer_message }}"
    api_key         : "{{ $env.ANTHROPIC_KEY }}"
    model           : "claude-3-7-sonnet-latest"
    temperature     : 0.3
    send_reasoning  : true
    thinking        : {
      type          : "enabled",
      budget_tokens : 10000
    }
  }

  tools = [
    { name: "Get_User_Info" },
    { name: "Update_User_Info" },
    { name: "Create_Ticket" }
  ]
}
```

***

## What's Next

Now that you understand how to define Agents in XanoScript, here are a few great next steps:

> [card] [Explore the function reference](https://docs.xano.com/xanoscript/function-reference)
>
> Learn about the built-in functions available in the stack to start writing more complex logic.

> [card] [Try it out in VS Code](https://docs.xano.com/xanoscript/vs-code)
>
> Use the XanoScript VS Code extension with Copilot to write XanoScript in your favorite IDE.

> [card] [Learn about AI Tools](https://docs.xano.com/xanoscript/ai-tools.md)
>
> AI Tools are used to define the actions that an Agent can take.


## Related topics

- [XanoScript for AI Tools](https://docs.xano.com/xanoscript/ai-tools.md)
- [Intro to XanoScript](https://docs.xano.com/xanoscript/introduction.md)
- [XanoScript for MCP Servers](https://docs.xano.com/xanoscript/mcp-servers.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.