For the complete documentation index, see llms.txt. This page is also available as Markdown.

AI Tools

Create AI tools that enable function calling, letting AI models access real-time data, perform calculations, and interact with your systems.

AI Tools enable AI models to call functions in your code, providing access to real-time data, external APIs, databases, and any other system integration.

πŸ“‹ Table of Contents


🎯 What are AI Tools?

Tools are functions that you define and make available to AI models. When the AI needs information or wants to perform an action, it can call these tools:

User: "What's the weather in Boston?"
   ↓
AI: Determines it needs weather data β†’ Calls your weather tool
   ↓
Your Tool: Fetches actual weather from API β†’ Returns "72Β°F, Sunny"
   ↓
AI: "The weather in Boston is 72Β°F and sunny."

πŸ”„ Tool Execution Flow

πŸ—οΈ Tool Architecture

πŸ”§ Creating Tools

Basic Tool

Using Tools

πŸ“ Tool Definition

The aiTool() Function

Parameters:

  • name (string): The function name the AI uses to call the tool

  • description (string): Explains what the tool does (AI uses this to decide when to call it)

  • callback (function): Your function that executes when called

Describing Parameters

Use .describeArg() or the fluent .describe{ArgName}() pattern:

Multiple Parameters

βš™οΈ Tool Properties

Access tool properties:

πŸ’‘ Common Tool Patterns

Database Query Tool

API Integration Tool

Calculator Tool

File Operations Tool

Built-In Web Search Tool (v3.2+)

The module auto-registers webSearch@bxai, which lets agents fetch current web information without custom tool wiring.

Use this for fact-checking, current events, and research workflows where model pretraining alone is not enough.

Built-In Console & Logging Tools (v4.0+)

The module auto-registers three utility tools for debugging, logging, and notifications:

Prints a message to the console. Useful for debugging or outputting information you want the user to see.

log@bxai

Sends a message to the AI log file. Useful for keeping a record of interactions or debugging. Log files can be found in the logs directory of your BoxLang installation, typically named ai.log.

Parameters:

Parameter
Type
Default
Description

message

string

required

The message to log

type

string

"info"

Log level: "info", "warning", "error"

sendEmail@bxai

Sends an email using the server's mail configuration. Useful for notifications or alerts. This tool relies on the server's mail configuration being properly set up.

Parameters:

Parameter
Type
Default
Description

to

string

required

Recipient email address

subject

string

required

The subject of the email

body

string

required

The body content

from

string

required

The sender's email address

Note: httpGet@bxai is also available but not auto-registered for security reasons (it can reach internal networks). Register it manually if needed via aiToolRegistry().register( "httpGet", ... ).

πŸ”— Multiple Tools

Provide multiple tools for complex tasks:

Multi-Tool Orchestration

Tools with Agents

Agents can use tools across multiple interactions:

Tools with Models

Bind tools to models for reuse:

Tool Execution Flow

When you provide tools, the AI:

  1. Receives your message and available tools

  2. Decides if a tool is needed based on the question

  3. Calls the tool with arguments it determines

  4. Receives the result from your function

  5. Generates response using the tool result

Handling Tool Errors

Design tools to handle errors gracefully:

Advanced: Custom Schema

For complex parameter types, provide a custom schema:

Best Practices

1. Clear Descriptions

Good descriptions help the AI understand when to use tools:

2. Validate Input

3. Return Structured Data

4. Handle Missing Data

5. Keep Tools Focused

πŸ“¦ Tool Registry

The Tool Registry lets you register tools once and reference them by name across your entire application β€” no need to re-declare tools on every agent.

You can also scan classes annotated with @AITool to register all their methods at once:

See Tool Registry for complete documentation.

Provider Support

Provider
Tool Support
Notes

OpenAI

βœ… Full

Best support, parallel tool calls

Claude

βœ… Full

Excellent tool use

Gemini

πŸ”œ Coming

In development

Ollama

βœ… Model-dependent

Works with supported models

DeepSeek

βœ… Full

Good support

Grok

βœ… Full

Good support

Next Steps

Last updated