update
This commit is contained in:
+23
-23
@@ -1,6 +1,6 @@
|
||||
module toolRegistry
|
||||
|
||||
export ToolStore, loadTools, registerTool, getTools, clearTools, listTool
|
||||
export toolStore, loadTools, registerTool, getTools, clearTools, listTool
|
||||
|
||||
using Dates
|
||||
using JSON, DataStructures
|
||||
@@ -9,14 +9,14 @@ using ..type
|
||||
"""
|
||||
Per-agent isolated tool storage.
|
||||
|
||||
Each agent gets its own `ToolStore` so tool registration is independent —
|
||||
Each agent gets its own `toolStore` so tool registration is independent —
|
||||
`registerTool(store, tool)` only affects that agent's tool set.
|
||||
|
||||
# Fields
|
||||
- `tools::OrderedDict{String, agentTool}` — keyed by name for O(1) lookup + ordered iteration
|
||||
- `name::String` — identifier for debugging/logs
|
||||
"""
|
||||
struct ToolStore
|
||||
struct toolStore
|
||||
tools::OrderedDict{String, agentTool}
|
||||
name::String
|
||||
end
|
||||
@@ -29,14 +29,14 @@ Create a new isolated tool store.
|
||||
|
||||
# Examples
|
||||
```julia
|
||||
store = ToolStore(name="agent1")
|
||||
store = toolStore(name="agent1")
|
||||
tools = loadTools(store, "src/tools")
|
||||
registerTool(store, my_tool)
|
||||
agent = yiemAgent(tools=getTools(store), llmCall=..., _tool_store=store)
|
||||
```
|
||||
"""
|
||||
function ToolStore(; name::String="default")::ToolStore
|
||||
ToolStore(OrderedDict{String, agentTool}(), name)
|
||||
function toolStore(; name::String="default")::toolStore
|
||||
toolStore(OrderedDict{String, agentTool}(), name)
|
||||
end
|
||||
|
||||
"""
|
||||
@@ -44,12 +44,12 @@ List tool definition — lets the agent query available tools for collision dete
|
||||
when creating new tools via writeTool.
|
||||
|
||||
# Arguments
|
||||
- `store::ToolStore`: The tool store to list from
|
||||
- `store::toolStore`: The tool store to list from
|
||||
|
||||
Each `ToolStore` gets its own `listTool` instance bound to that store,
|
||||
Each `toolStore` gets its own `listTool` instance bound to that store,
|
||||
so each agent sees only its own tools.
|
||||
"""
|
||||
function listTool(store::ToolStore)::agentTool
|
||||
function listTool(store::toolStore)::agentTool
|
||||
return agentTool(
|
||||
name = "listTools",
|
||||
label = "List Tools",
|
||||
@@ -80,7 +80,7 @@ function listTool(store::ToolStore)::agentTool
|
||||
end
|
||||
|
||||
"""
|
||||
Load all tool modules from a directory into a specific ToolStore.
|
||||
Load all tool modules from a directory into a specific toolStore.
|
||||
|
||||
Scans `dir` for `.jl` files. Each file must define a function named
|
||||
`getTool()::agentTool`. Files are sorted alphabetically so tool
|
||||
@@ -91,7 +91,7 @@ defined in the file (`validateRequiredArgs`, `prepareArguments`, `executeTool`,
|
||||
and any helper functions) are namespaced and never collide with other tools.
|
||||
|
||||
# Arguments
|
||||
- `store::ToolStore`: The tool store to register tools into
|
||||
- `store::toolStore`: The tool store to register tools into
|
||||
- `dir::String`: Directory path to scan for `.jl` tool files
|
||||
|
||||
# Returns
|
||||
@@ -102,7 +102,7 @@ and any helper functions) are namespaced and never collide with other tools.
|
||||
|
||||
# Examples
|
||||
```julia
|
||||
julia> store = ToolStore(name="agent1")
|
||||
julia> store = toolStore(name="agent1")
|
||||
julia> tools = loadTools(store, "src/tools")
|
||||
OrderedDict{String, agentTool} with 3 entries:
|
||||
"getWeather" => agentTool(...)
|
||||
@@ -110,7 +110,7 @@ OrderedDict{String, agentTool} with 3 entries:
|
||||
"listTools" => agentTool(...)
|
||||
```
|
||||
"""
|
||||
function loadTools(store::ToolStore, dir::String)::OrderedDict{String, agentTool}
|
||||
function loadTools(store::toolStore, dir::String)::OrderedDict{String, agentTool}
|
||||
if !isdir(dir)
|
||||
throw(ArgumentError("Tool directory does not exist: $dir"))
|
||||
end
|
||||
@@ -172,10 +172,10 @@ function loadTools(store::ToolStore, dir::String)::OrderedDict{String, agentTool
|
||||
end
|
||||
|
||||
"""
|
||||
Register a single agentTool into a specific ToolStore.
|
||||
Register a single agentTool into a specific toolStore.
|
||||
|
||||
# Arguments
|
||||
- `store::ToolStore`: The tool store to register into
|
||||
- `store::toolStore`: The tool store to register into
|
||||
- `tool::agentTool`: The tool to register
|
||||
|
||||
# Returns
|
||||
@@ -183,25 +183,25 @@ Register a single agentTool into a specific ToolStore.
|
||||
|
||||
# Examples
|
||||
```julia
|
||||
julia> store = ToolStore(name="agent1")
|
||||
julia> store = toolStore(name="agent1")
|
||||
julia> registerTool(store, my_tool)
|
||||
[toolRegistry:agent1] Registered tool: my_tool
|
||||
```
|
||||
"""
|
||||
function registerTool(store::ToolStore, tool::agentTool)::OrderedDict{String, agentTool}
|
||||
function registerTool(store::toolStore, tool::agentTool)::OrderedDict{String, agentTool}
|
||||
store.tools[tool.name] = tool
|
||||
println("[$(store.name)] Registered tool: $(tool.name)")
|
||||
return store.tools
|
||||
end
|
||||
|
||||
"""
|
||||
Get the registered tools from a specific ToolStore.
|
||||
Get the registered tools from a specific toolStore.
|
||||
|
||||
Returns the internal `OrderedDict` directly — O(1) lookup by name,
|
||||
ordered iteration preserving registration order.
|
||||
|
||||
# Arguments
|
||||
- `store::ToolStore`: The tool store to query
|
||||
- `store::toolStore`: The tool store to query
|
||||
|
||||
# Returns
|
||||
- `OrderedDict{String, agentTool}`: Tools keyed by name, in registration order
|
||||
@@ -215,15 +215,15 @@ OrderedDict{String, agentTool} with 3 entries:
|
||||
"getTime" => agentTool(...)
|
||||
```
|
||||
"""
|
||||
function getTools(store::ToolStore)::OrderedDict{String, agentTool}
|
||||
function getTools(store::toolStore)::OrderedDict{String, agentTool}
|
||||
return store.tools
|
||||
end
|
||||
|
||||
"""
|
||||
Clear all registered tools from a specific ToolStore.
|
||||
Clear all registered tools from a specific toolStore.
|
||||
|
||||
# Arguments
|
||||
- `store::ToolStore`: The tool store to clear
|
||||
- `store::toolStore`: The tool store to clear
|
||||
|
||||
# Returns
|
||||
- `nothing`
|
||||
@@ -234,7 +234,7 @@ julia> clearTools(store)
|
||||
[toolRegistry:agent1] Registry cleared
|
||||
```
|
||||
"""
|
||||
function clearTools(store::ToolStore)::Nothing
|
||||
function clearTools(store::toolStore)::Nothing
|
||||
empty!(store.tools)
|
||||
println("[$(store.name)] Registry cleared")
|
||||
return nothing
|
||||
|
||||
Reference in New Issue
Block a user