Normandy.Tools.Registry
(normandy v0.6.1)
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.
Filters tools by parameter type.
Filters tools by whether they have required parameters.
Retrieves a tool by name from the registry.
Retrieves a tool by name, raising if not found.
Gets metadata for a specific tool by name.
Checks if a tool with the given name exists in the registry.
Gets schema introspection data for a tool if available.
Returns a list of all registered tools.
Gets metadata for all tools in the registry.
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.
Gets tools that support a specific constraint type.
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
Filters tools by parameter type.
Returns a new registry containing only tools that have a parameter of the given type.
Examples
iex> registry = Normandy.Tools.Registry.new([%Calculator{}, %StringTool{}])
iex> Normandy.Tools.Registry.filter_by_param_type(registry, "number")
%Normandy.Tools.Registry{tools: %{"calculator" => %Calculator{}}}
Filters tools by whether they have required parameters.
Returns a new registry containing only tools that match the criteria.
Examples
iex> registry = Normandy.Tools.Registry.new([%Tool1{}, %Tool2{}])
iex> Normandy.Tools.Registry.filter_by_required_params(registry, true)
%Normandy.Tools.Registry{tools: %{"tool1" => %Tool1{}}}
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{}
Gets metadata for a specific tool by name.
Returns detailed metadata including schema introspection if available.
Examples
iex> registry = Normandy.Tools.Registry.new([%CalculatorTool{}])
iex> Normandy.Tools.Registry.get_metadata(registry, "calculator")
{:ok, %{
name: "calculator",
description: "Performs arithmetic operations",
input_schema: %{...},
fields: [...]
}}
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
Gets schema introspection data for a tool if available.
Returns schema field information for schema-based tools, or nil for legacy tools.
Examples
iex> registry = Normandy.Tools.Registry.new([%EnhancedCalculator{}])
iex> Normandy.Tools.Registry.introspect_schema(registry, "enhanced_calculator")
{:ok, [
%{name: :operation, type: :string, required: true, ...},
...
]}
Returns a list of all registered tools.
Examples
iex> registry = Normandy.Tools.Registry.new([%Tool1{}, %Tool2{}])
iex> Normandy.Tools.Registry.list(registry)
[%Tool1{}, %Tool2{}]
Gets metadata for all tools in the registry.
Returns a list of metadata maps for each registered tool.
Examples
iex> registry = Normandy.Tools.Registry.new([%Tool1{}, %Tool2{}])
iex> Normandy.Tools.Registry.list_metadata(registry)
[%{name: "tool1", ...}, %{name: "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", ...}
}
]
Gets tools that support a specific constraint type.
Returns a list of tool names that have parameters with the given constraint.
Examples
iex> registry = Normandy.Tools.Registry.new([%Calculator{}, %StringTool{}])
iex> Normandy.Tools.Registry.tools_with_constraint(registry, :enum)
["calculator", "string_tool"]
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: %{}}