This commit is contained in:
2026-08-08 08:51:07 +07:00
parent c1ef544734
commit 04e75e61b8
6 changed files with 69 additions and 20 deletions
+49
View File
@@ -0,0 +1,49 @@
"""
Execute the get_time tool.
# Arguments
- `toolCallId::String`: Unique identifier for this tool call
- `args::Dict{String,Any}`: Parsed arguments from the LLM
- `signal::Union{Nothing,abortSignal}`: Optional abort signal
- `onPartialResult::Function`: Callback for streaming partial results
# Returns
- `agentToolResult`: Result content with current time
"""
function executeTool(toolCallId::String, args::Dict{String,Any}, signal::Union{Nothing,abortSignal}, onPartialResult::Function)::agentToolResult
tz = get(args, "timezone", "local")
t = now()
if tz == "local"
timeStr = string(t)
else
timeStr = string(t)
end
return agentToolResult(
[textContent("Current time: $(timeStr)")],
Dict{Any,Any}(), nothing, false
)
end
"""
Define and return the get_time agentTool.
"""
function getTool()::agentTool
return agentTool(
name = "get_time",
label = "Get Current Time",
description = "Get the current date and time.",
inputSchema = Dict{String,Any}(
"type" => "object",
"properties" => Dict(
"timezone" => Dict("type" => "string", "description" => "Timezone (currently only 'local' is supported)")
),
"required" => []
),
execute = executeTool,
prepareArguments = nothing,
parallelToolExecute = false
)
end
@@ -1,5 +1,5 @@
"""
Execute the get_weather tool.
Execute the getWeather tool.
# Arguments
- `toolCallId::String`: Unique identifier for this tool call
@@ -10,7 +10,7 @@ Execute the get_weather tool.
# Returns
- `agentToolResult`: Result content with weather data
"""
function executeTool(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")
@@ -37,11 +37,11 @@ function executeTool(toolCallId::String, args::Dict{String,Any}, signal::Union{N
end
"""
Define and return the get_weather agentTool.
Define and return the getWeather agentTool.
"""
function getTool() :: agentTool
function getTool()::agentTool
return agentTool(
name = "get_weather",
name = "getWeather",
label = "Weather Lookup",
description = "Fetch current weather and forecast for a given city.",
inputSchema = Dict{String,Any}(
+6 -6
View File
@@ -11,17 +11,17 @@ const _registry = Vector{agentTool}()
Load all tool modules from a directory.
Scans `dir` for `.jl` files. Each file must define a function named
`getTool() :: 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 `getTool()` that returns an `agentTool`:
```julia
# src/tools/get_weather.jl
function getTool() :: agentTool
# src/tools/getWeather.jl
function getTool()::agentTool
return agentTool(
name = "get_weather",
name = "getWeather",
label = "Weather Lookup",
description = "Fetch current weather and forecast for a given city.",
inputSchema = Dict{String,Any}(
@@ -72,10 +72,10 @@ function loadTools(dir::String)::Vector{agentTool}
include(filepath)
# Validate that getTool was defined (include() places it in current module scope)
if !isdefined(:getTool)
if !isdefined(@__MODULE__, :getTool)
throw(ArgumentError(
"Tool file $(filepath) does not define a `getTool()` function. " *
"Each tool file must define: function getTool() :: agentTool ... end"
"Each tool file must define: function getTool()::agentTool ... end"
))
end