Normandy.Tools.Registry (normandy v0.2.0)
View SourceManages 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
Functions
@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
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
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{}
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
Returns a list of all registered tools.
Examples
iex> registry = Normandy.Tools.Registry.new([%Tool1{}, %Tool2{}])
iex> Normandy.Tools.Registry.list(registry)
[%Tool1{}, %Tool2{}]
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"]
@spec new() :: t()
Creates a new empty tool registry.
Examples
iex> Normandy.Tools.Registry.new()
%Normandy.Tools.Registry{tools: %{}}
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{}, ...}}
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{}}}
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", ...}
}
]
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: %{}}