update
This commit is contained in:
+40
-11
@@ -1,12 +1,51 @@
|
||||
module toolRegistry
|
||||
|
||||
export loadTools, registerTool, getTools, listTools, clearTools
|
||||
export loadTools, registerTool, getTools, clearTools
|
||||
|
||||
using ..type
|
||||
|
||||
# Global registry — populated at runtime by loadTools() or registerTool()
|
||||
const _registry = Vector{agentTool}()
|
||||
|
||||
# Auto-register the built-in listTools tool
|
||||
function __init__()
|
||||
registerTool(_listTool())
|
||||
end
|
||||
|
||||
"""
|
||||
List tool definition — lets the agent query available tools for collision detection
|
||||
when creating new tools via writeTool.
|
||||
"""
|
||||
function _listTool()::agentTool
|
||||
return agentTool(
|
||||
name = "listTools",
|
||||
label = "List Tools",
|
||||
description = "List all available tools with their names, labels, and descriptions. Use this before creating a new tool to check for name collisions.",
|
||||
inputSchema = Dict{String,Any}(
|
||||
"type" => "object",
|
||||
"properties" => Dict{String,Any}(),
|
||||
"required" => Any[]
|
||||
),
|
||||
execute = (toolCallId, args, signal, onPartialResult) -> begin
|
||||
tools = getTools()
|
||||
if isempty(tools)
|
||||
result_text = "No tools registered."
|
||||
else
|
||||
lines = String["- $(t.name): $(t.label) — $(t.description)" for t in tools]
|
||||
result_text = "Available tools:\n" * join(lines, "\n")
|
||||
end
|
||||
return agentToolResult(
|
||||
[textContent(result_text)],
|
||||
Dict{Any,Any}("count" => length(tools)),
|
||||
nothing, false
|
||||
)
|
||||
end,
|
||||
prepareArguments = nothing,
|
||||
validateRequiredArgs = nothing,
|
||||
parallelToolExecute = false
|
||||
)
|
||||
end
|
||||
|
||||
"""
|
||||
Load all tool modules from a directory.
|
||||
|
||||
@@ -120,16 +159,6 @@ function getTools()::Vector{agentTool}
|
||||
return deepcopy(_registry)
|
||||
end
|
||||
|
||||
"""
|
||||
List all registered tool names and labels.
|
||||
|
||||
# Returns
|
||||
- `Vector{Tuple{String,String}}`: Pairs of (name, label)
|
||||
"""
|
||||
function listTools()::Vector{Tuple{String,String}}
|
||||
return [(t.name, t.label) for t in _registry]
|
||||
end
|
||||
|
||||
"""
|
||||
Clear all registered tools from the global registry.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user