This commit is contained in:
2026-08-07 23:13:13 +07:00
parent 8e356f06bc
commit e60cbc67c4
5 changed files with 347 additions and 7 deletions
+51 -7
View File
@@ -197,23 +197,67 @@ end
"""
A tool available to the agent.
Maps MCP server tool definitions to an executable Julia tool.
# Arguments
- `name::String`: Tool identifier
- `label::String`: Human-readable tool name
- `description::String`: What the tool does
- `parameters::TParameters`: Tool parameters schema (JSON schema)
- `execute::Function`: Tool execution function
- `name::String`: Tool identifier (from MCP `name`)
- `label::String`: Human-readable tool name (from MCP `title`)
- `description::String`: What the tool does (from MCP `description`)
- `inputSchema::Any`: Tool parameters schema (from MCP `inputSchema`, JSON Schema format)
- `execute::Function`: Tool execution function, signature:
`execute(toolCallId::String, args::Dict, signal::Union{Nothing,AbortSignal}, onPartialResult::Function)`
- `prepareArguments::Union{Function, Nothing}`: Optional argument preparation callback
- `parallelToolExecute::Bool`: Override: run tool calls sequentially or in parallel
# Returns
- A new `agentTool` instance
# MCP Tool Example
```
{
"name": "get_weather",
"title": "Weather Lookup",
"description": "Fetch current weather and forecast for a given city.",
"inputSchema": {
"type": "object",
"properties": {
"city": { "type": "string", "description": "City and state/country" },
"units": { "type": "string", "enum": ["celsius", "fahrenheit"], "default": "celsius" }
},
"required": ["city"]
}
}
```
# Example
```julia
tool = agentTool(
name="get_weather",
label="Weather Lookup",
description="Fetch current weather and forecast for a given city.",
inputSchema=Dict(
"type" => "object",
"properties" => Dict(
"city" => Dict("type" => "string", "description" => "City name"),
"units" => Dict("type" => "string", "enum" => ["celsius", "fahrenheit"])
),
"required" => ["city"]
),
execute=(toolCallId, args, signal, onPartialResult) -> begin
city = args["city"]
return agentToolResult(
[textContent("Sunny, 22C in $(city)")],
Dict{Any,Any}(), nothing, false
)
end
)
```
"""
struct agentTool{TParameters, TDetails} # A tool available to the agent
struct agentTool # A tool available to the agent
name::String # Tool identifier
label::String # Human-readable tool name
description::String # What the tool does
parameters::TParameters # Tool parameters schema (JSON schema)
inputSchema::Any # Tool parameters schema (JSON schema, MCP inputSchema format)
execute::Function # Tool execution function
prepareArguments::Union{Function, Nothing} # Optional argument preparation callback
parallelToolExecute::Bool # Override: run tool calls sequentially or in parallel