This commit is contained in:
2026-08-08 08:04:08 +07:00
parent e60cbc67c4
commit c1ef544734
6 changed files with 32 additions and 1399 deletions
+3 -3
View File
@@ -10,7 +10,7 @@ Execute the get_weather tool.
# Returns
- `agentToolResult`: Result content with weather data
"""
function execute_tool(toolCallId::String, args::Dict{String,Any}, signal::Union{Nothing,abortSignal}, onPartialResult::Function) :: agentToolResult
function executeTool(toolCallId::String, args::Dict{String,Any}, signal::Union{Nothing,abortSignal}, onPartialResult::Function) :: agentToolResult
city = get(args, "city", "")
units = get(args, "units", "celsius")
@@ -39,7 +39,7 @@ end
"""
Define and return the get_weather agentTool.
"""
function get_tool() :: agentTool
function getTool() :: agentTool
return agentTool(
name = "get_weather",
label = "Weather Lookup",
@@ -52,7 +52,7 @@ function get_tool() :: agentTool
),
"required" => ["city"]
),
execute = execute_tool, # reference the function defined above
execute = executeTool, # reference the function defined above
prepareArguments = nothing,
parallelToolExecute = false
)
+18 -18
View File
@@ -1,25 +1,25 @@
module toolRegistry
export load_tools, register_tool, get_tools, list_tools, clear_tools
export loadTools, registerTool, getTools, listTools, clearTools
using ..type
# Global registry — populated at runtime by load_tools() or register_tool()
# Global registry — populated at runtime by loadTools() or registerTool()
const _registry = Vector{agentTool}()
"""
Load all tool modules from a directory.
Scans `dir` for `.jl` files. Each file must define a function named
`get_tool() :: agentTool`. Files are sorted alphabetically so tool
`getTool() :: agentTool`. Files are sorted alphabetically so tool
registration order is deterministic.
# Tool file format
Each `.jl` file defines one function `get_tool()` that returns an `agentTool`:
Each `.jl` file defines one function `getTool()` that returns an `agentTool`:
```julia
# src/tools/get_weather.jl
function get_tool() :: agentTool
function getTool() :: agentTool
return agentTool(
name = "get_weather",
label = "Weather Lookup",
@@ -52,9 +52,9 @@ end
- `Vector{agentTool}`: All loaded tools
# Errors
- Throws `ArgumentError` if a tool file does not define a `get_tool` function
- Throws `ArgumentError` if a tool file does not define a `getTool` function
"""
function load_tools(dir::String)::Vector{agentTool}
function loadTools(dir::String)::Vector{agentTool}
if !isdir(dir)
throw(ArgumentError("Tool directory does not exist: $dir"))
end
@@ -71,19 +71,19 @@ function load_tools(dir::String)::Vector{agentTool}
# (agentTool, textContent, agentToolResult, etc. are all available)
include(filepath)
# Validate that get_tool was defined (include() places it in current module scope)
if !isdefined(:get_tool)
# Validate that getTool was defined (include() places it in current module scope)
if !isdefined(:getTool)
throw(ArgumentError(
"Tool file $(filepath) does not define a `get_tool()` function. " *
"Each tool file must define: function get_tool() :: agentTool ... end"
"Tool file $(filepath) does not define a `getTool()` function. " *
"Each tool file must define: function getTool() :: agentTool ... end"
))
end
# Call get_tool() — it runs in current scope where types are visible
tool = get_tool()
# Call getTool() — it runs in current scope where types are visible
tool = getTool()
if !(tool isa agentTool)
throw(ArgumentError(
"get_tool() in $(filepath) did not return an agentTool instance, got: $(typeof(tool))"
"getTool() in $(filepath) did not return an agentTool instance, got: $(typeof(tool))"
))
end
@@ -104,7 +104,7 @@ Register a single agentTool into the global registry.
# Returns
- `Vector{agentTool}`: Updated registry
"""
function register_tool(tool::agentTool)::Vector{agentTool}
function registerTool(tool::agentTool)::Vector{agentTool}
push!(_registry, tool)
println("[toolRegistry] Registered tool: $(tool.name)")
return _registry
@@ -116,7 +116,7 @@ Get all registered tools.
# Returns
- `Vector{agentTool}`: Copy of the registry
"""
function get_tools()::Vector{agentTool}
function getTools()::Vector{agentTool}
return deepcopy(_registry)
end
@@ -126,14 +126,14 @@ List all registered tool names and labels.
# Returns
- `Vector{Tuple{String,String}}`: Pairs of (name, label)
"""
function list_tools()::Vector{Tuple{String,String}}
function listTools()::Vector{Tuple{String,String}}
return [(t.name, t.label) for t in _registry]
end
"""
Clear all registered tools from the global registry.
"""
function clear_tools()::Nothing
function clearTools()::Nothing
empty!(_registry)
println("[toolRegistry] Registry cleared")
return nothing