Rag.Agent.Registry (rag v0.3.4)
View SourceTool registry for managing available agent tools.
The registry maintains a collection of tools that can be used by agents. It provides functions for registering, looking up, and executing tools.
Usage
# Create a registry with initial tools
registry = Registry.new(tools: [SearchTool, ReadFileTool])
# Register additional tools
registry = Registry.register(registry, AnalyzeTool)
# Execute a tool
{:ok, result} = Registry.execute(registry, "search", %{"query" => "test"}, context)
Summary
Functions
Returns the number of registered tools.
Executes a tool by name.
Filters tools by a predicate function.
Formats all tools for LLM function calling.
Gets a tool by name.
Checks if a tool is registered.
Lists all registered tool modules.
Lists all registered tool names.
Creates a new tool registry.
Registers a tool in the registry.
Registers multiple tools at once.
Unregisters a tool by name.
Types
Functions
@spec count(t()) :: non_neg_integer()
Returns the number of registered tools.
Examples
iex> Registry.count(registry)
2
Executes a tool by name.
Examples
iex> Registry.execute(registry, "my_tool", %{"input" => "test"}, %{})
{:ok, "result"}
iex> Registry.execute(registry, "unknown", %{}, %{})
{:error, {:tool_not_found, "unknown"}}
Filters tools by a predicate function.
Examples
iex> Registry.filter(registry, fn tool -> tool.name() == "my_tool" end)
%Registry{...}
Formats all tools for LLM function calling.
Examples
iex> Registry.format_for_llm(registry)
[%{name: "tool1", description: "...", parameters: %{...}}, ...]
Gets a tool by name.
Examples
iex> Registry.get(registry, "my_tool")
{:ok, MyTool}
iex> Registry.get(registry, "unknown")
{:error, :not_found}
Checks if a tool is registered.
Examples
iex> Registry.has_tool?(registry, "my_tool")
true
Lists all registered tool modules.
Examples
iex> Registry.list(registry)
[Tool1, Tool2]
Lists all registered tool names.
Examples
iex> Registry.names(registry)
["tool1", "tool2"]
Creates a new tool registry.
Options
:tools- List of tool modules to register initially
Examples
iex> Registry.new()
%Registry{tools: %{}}
iex> Registry.new(tools: [MyTool])
%Registry{tools: %{"my_tool" => MyTool}}
Registers a tool in the registry.
If a tool with the same name already exists, it will be replaced.
Examples
iex> registry |> Registry.register(MyTool)
%Registry{tools: %{"my_tool" => MyTool}}
Registers multiple tools at once.
Examples
iex> Registry.register_all(registry, [Tool1, Tool2])
%Registry{tools: %{"tool1" => Tool1, "tool2" => Tool2}}
Unregisters a tool by name.
Examples
iex> Registry.unregister(registry, "my_tool")
%Registry{...}