# Class LittleGhost::ToolRegistry

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/ToolRegistry.html

ToolRegistry turns an agent's tool declarations into the exact set a model can
call during one run. It validates names, binds run collaborators, and closes
owned tool instances with the run.

    binding = LittleGhost::Tool::Binding.new
    registry = LittleGhost::ToolRegistry.new([HelpCenterLookupTool], binding:)
    registry.names # => ["policy_lookup"]

Entries may be Tool instances, Tool subclasses, nested arrays, or provider
classes that implement `tools(binding)`. Names must be unique,
contain only letters, numbers, underscores, or hyphens, and be at most 64
characters. Owned tools are closed once in reverse order.

## Inheritance

`LittleGhost::ToolRegistry < Object`

## Includes

- `Enumerable`

## Class methods

<a id="method-c-new"></a>
### `.new`

```ruby
.new(tools = [], binding: Tool::Binding.new)
```

Binds newly instantiated tools to `binding`.

## Instance methods

<a id="method-i-close"></a>
### `#close`

```ruby
#close()
```

Closes every owned tool.

<a id="method-i-each"></a>
### `#each`

```ruby
#each(&block)
```

Yields each registered tool instance.

<a id="method-i-fetch"></a>
### `#fetch`

```ruby
#fetch(name)
```

Finds the named tool or raises ToolError when it is unavailable.

<a id="method-i-names"></a>
### `#names`

```ruby
#names()
```

Lists the frozen model-visible tool names.

<a id="method-i-register"></a>
### `#register`

```ruby
#register(tool, replace: false)
```

Registers `tool` and returns `self`. When `replace` is true, replaced owned
tools are closed after the new entries have been validated.

<a id="method-i-specifications"></a>
### `#specifications`

```ruby
#specifications()
```

Collects the frozen model-facing tool specifications.
