> For the complete documentation index, see [llms.txt](https://ai.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ai.ortusbooks.com/advanced/reference/built-in-functions/aitoolregistry.md).

# aiToolRegistry

Returns the singleton AIToolRegistry instance for registering, discovering, and resolving AI tools globally.

Returns the singleton `AIToolRegistry` instance for registering, discovering, and resolving AI tools globally.

## Syntax

```javascript
aiToolRegistry()
```

## Parameters

No parameters.

## Returns

Returns the singleton `AIToolRegistry` instance. The same registry instance is returned on every call within a runtime.

## Examples

### Register a Tool

```javascript
aiToolRegistry().register(
    name       : "getWeather",
    description: "Get current weather for a location",
    callback   : ( location ) => weatherService.fetch( location )
)
```

### Register with Module Attribution

```javascript
// Keyed as "getWeather@my-module" — easy bulk removal later
aiToolRegistry().register(
    item  : myWeatherTool,
    module: "my-module"
)
```

### Scan a Class for `@AITool` Annotations

```javascript
// Register all methods annotated with @AITool from a class instance
aiToolRegistry().scan( new CustomerService(), "customer-module" )
```

### Scan a Package Path

```javascript
// Scan all .bx files in a package for @AITool-annotated methods
aiToolRegistry().scan( "com.myapp.tools", "my-module" )
```

### Resolve Tools for an Agent

```javascript
// Mix named keys and ITool instances
agent = aiAgent(
    name : "assistant",
    tools: aiToolRegistry().resolveTools( [
        "getWeather",
        "searchProducts@shop-module",
        myCustomToolInstance
    ] )
)
```

### Check and Retrieve Tools

```javascript
registry = aiToolRegistry()

// Check existence
if ( registry.has( "getWeather" ) ) {
    weatherTool = registry.get( "getWeather" )
}

// Get detailed info
info = registry.getToolInfo( "getWeather" )
println( info.name )         // "getWeather"
println( info.description )  // "Get current weather for a location"

// List all registered tools
all = registry.listTools()
all.each( tool => println( tool.getName() ) )

// Get all keys
keys = registry.getKeys()
println( keys )  // [ "getWeather", "searchProducts@shop-module", ... ]
```

### Unregister Tools

```javascript
// Remove a single tool
aiToolRegistry().unregister( "getWeather" )

// Remove all tools from a module (e.g., on module unload)
aiToolRegistry().unregisterByModule( "my-module" )
```

## Registry API Reference

| Method                                                  | Description                                                 |
| ------------------------------------------------------- | ----------------------------------------------------------- |
| `register( item, module, name, description, callback )` | Register an `ITool` instance or closure                     |
| `scan( pathOrInstance, module )`                        | Scan class or package for `@AITool` annotations             |
| `scanClass( instance, module )`                         | Scan a single class instance                                |
| `get( key )`                                            | Retrieve a tool by key                                      |
| `has( key )`                                            | Check if a key exists                                       |
| `getKeys()`                                             | Return all registered keys                                  |
| `getByModule( module )`                                 | Return all `ITool` instances registered under a module name |
| `getModules()`                                          | Return the module names that have registered tools          |
| `listTools()`                                           | Return all registered `ITool` instances                     |
| `getToolInfo( key )`                                    | Return name and description info for a key                  |
| `resolveTools( array )`                                 | Resolve an array of keys and/or instances to `ITool[]`      |
| `unregister( key )`                                     | Remove a tool by key                                        |
| `unregisterByModule( module )`                          | Remove all tools registered under a module name             |

## Related Pages

* [Tool Registry](https://ai.ortusbooks.com/main-components/tool-registry.md) — Full registry documentation
* [Custom Tools](https://ai.ortusbooks.com/extending-boxlang-ai/custom-tools.md) — Building custom tool classes
* [aiTool()](https://ai.ortusbooks.com/advanced/reference/built-in-functions/aitool.md) — Create `ITool` instances


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ai.ortusbooks.com/advanced/reference/built-in-functions/aitoolregistry.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
