Normandy.Tools.Registry (normandy v0.2.0)

View Source

Manages a collection of tools available to an agent.

The Registry provides a structured way to register, retrieve, and list tools that an agent can use during execution.

Summary

Functions

Returns the number of tools in the registry.

Retrieves a tool by name from the registry.

Retrieves a tool by name, raising if not found.

Checks if a tool with the given name exists in the registry.

Returns a list of all registered tools.

Returns a list of all tool names in the registry.

Creates a new empty tool registry.

Creates a new tool registry with the given tools.

Registers a tool in the registry.

Generates a list of tool schemas for LLM consumption.

Removes a tool from the registry by name.

Types

t()

@type t() :: %Normandy.Tools.Registry{tools: %{required(String.t()) => struct()}}

Functions

count(registry)

@spec count(t()) :: non_neg_integer()

Returns the number of tools in the registry.

Examples

iex> registry = Normandy.Tools.Registry.new([%Tool1{}, %Tool2{}])
iex> Normandy.Tools.Registry.count(registry)
2

get(registry, tool_name)

@spec get(t(), String.t()) :: {:ok, struct()} | :error

Retrieves a tool by name from the registry.

Returns {:ok, tool} if found, :error otherwise.

Examples

iex> registry = Normandy.Tools.Registry.new([%CalculatorTool{}])
iex> Normandy.Tools.Registry.get(registry, "calculator")
{:ok, %CalculatorTool{}}

iex> Normandy.Tools.Registry.get(registry, "nonexistent")
:error

get!(registry, tool_name)

@spec get!(t(), String.t()) :: struct()

Retrieves a tool by name, raising if not found.

Examples

iex> registry = Normandy.Tools.Registry.new([%CalculatorTool{}])
iex> Normandy.Tools.Registry.get!(registry, "calculator")
%CalculatorTool{}

has_tool?(registry, tool_name)

@spec has_tool?(t(), String.t()) :: boolean()

Checks if a tool with the given name exists in the registry.

Examples

iex> registry = Normandy.Tools.Registry.new([%CalculatorTool{}])
iex> Normandy.Tools.Registry.has_tool?(registry, "calculator")
true

iex> Normandy.Tools.Registry.has_tool?(registry, "nonexistent")
false

list(registry)

@spec list(t()) :: [struct()]

Returns a list of all registered tools.

Examples

iex> registry = Normandy.Tools.Registry.new([%Tool1{}, %Tool2{}])
iex> Normandy.Tools.Registry.list(registry)
[%Tool1{}, %Tool2{}]

list_names(registry)

@spec list_names(t()) :: [String.t()]

Returns a list of all tool names in the registry.

Examples

iex> registry = Normandy.Tools.Registry.new([%CalculatorTool{}])
iex> Normandy.Tools.Registry.list_names(registry)
["calculator"]

new()

@spec new() :: t()

Creates a new empty tool registry.

Examples

iex> Normandy.Tools.Registry.new()
%Normandy.Tools.Registry{tools: %{}}

new(tools)

@spec new([struct()]) :: t()

Creates a new tool registry with the given tools.

Examples

iex> tools = [%MyTool{}, %OtherTool{}]
iex> Normandy.Tools.Registry.new(tools)
%Normandy.Tools.Registry{tools: %{"my_tool" => %MyTool{}, ...}}

register(registry, tool)

@spec register(
  t(),
  struct()
) :: t()

Registers a tool in the registry.

The tool is indexed by its tool_name.

Examples

iex> registry = Normandy.Tools.Registry.new()
iex> tool = %CalculatorTool{}
iex> Normandy.Tools.Registry.register(registry, tool)
%Normandy.Tools.Registry{tools: %{"calculator" => %CalculatorTool{}}}

to_tool_schemas(registry)

@spec to_tool_schemas(t()) :: [map()]

Generates a list of tool schemas for LLM consumption.

Returns a list of maps containing tool metadata (name, description, schema).

Examples

iex> registry = Normandy.Tools.Registry.new([%CalculatorTool{}])
iex> Normandy.Tools.Registry.to_tool_schemas(registry)
[
  %{
    name: "calculator",
    description: "Performs arithmetic operations",
    input_schema: %{type: "object", ...}
  }
]

unregister(registry, tool_name)

@spec unregister(t(), String.t()) :: t()

Removes a tool from the registry by name.

Examples

iex> registry = Normandy.Tools.Registry.new([%CalculatorTool{}])
iex> Normandy.Tools.Registry.unregister(registry, "calculator")
%Normandy.Tools.Registry{tools: %{}}