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.
π― 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 tooldescription(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:
print@bxai
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:
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:
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@bxaiis also available but not auto-registered for security reasons (it can reach internal networks). Register it manually if needed viaaiToolRegistry().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:
Receives your message and available tools
Decides if a tool is needed based on the question
Calls the tool with arguments it determines
Receives the result from your function
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
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
Advanced Chatting - Tool examples with
aiChat()AI Agents - Using tools with autonomous agents
Tool Registry - Register tools globally
Custom Tools - Build custom tool classes
Working with Models - Binding tools to models
MCP Client - Connect to external tool servers
Last updated