local agent = require("agent")
local td = {
name = "dedup_test_tool",
schema = {
description = "A tool that exists twice over.",
input_schema = {
type = "object",
properties = { spec = { type = "string" } },
required = { "spec" },
},
},
handler = function()
return "ok"
end,
}
tool.register(td.name, td.schema, td.handler)
local registry = agent._registry_candidates()
local both = {}
for _, c in ipairs(registry) do
both[#both + 1] = c
end
for _, c in ipairs(agent._extra_candidates({ td })) do
both[#both + 1] = c
end
local ok, err = pcall(agent._build_tools, both, nil)
assert(not ok, "a name claimed by both the registry and extra_tools must be refused, not merged")
assert(
tostring(err):find("duplicate tool name 'dedup_test_tool'", 1, true) ~= nil,
"the refusal must name the tool, got: " .. tostring(err)
)
local tools = agent._build_tools(registry, nil)
assert(tools["dedup_test_tool"] ~= nil, "dedup_test_tool must be bound from the registry")
local count = 0
for _ in pairs(tools) do
count = count + 1
end
print("dedup=ok")
print("tool_count=" .. tostring(count))