Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/llm/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ if result.tool_calls and #result.tool_calls > 0 then
end
```

A tool needs a `name` and a `schema`; `description` is optional, and every driver sends a
tool without one with the description field omitted.

Tool calls with malformed JSON arguments retain the original string in `arguments` and
`raw_arguments`, with the decoder diagnostic in `arguments_error`. These optional fields
are absent on valid calls. Hosts must reject calls with `arguments_error` through their
Expand Down
2 changes: 1 addition & 1 deletion src/llm/src/google/mapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function mapper.map_tools(contract_tools)
local tools = {}

for _, tool in ipairs(contract_tools) do
if tool.name and tool.description and tool.schema then
if tool.name and tool.schema then
table.insert(tools, {
name = tool.name,
description = tool.description,
Expand Down
2 changes: 1 addition & 1 deletion src/llm/src/openai/mapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function openai_mapper.map_tools(contract_tools, opts)
local tool_name_map = {}

for _, tool in ipairs(contract_tools) do
if tool.name and tool.description and tool.schema then
if tool.name and tool.schema then
table.insert(tools, {
type = "function",
name = tool.name,
Expand Down
2 changes: 1 addition & 1 deletion src/llm/src/openai_compat/mapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ function openai_mapper.map_tools(contract_tools)
local tool_name_map = {}

for _, tool in ipairs(contract_tools) do
if tool.name and tool.description and tool.schema then
if tool.name and tool.schema then
table.insert(openai_tools, {
type = "function",
["function"] = {
Expand Down
11 changes: 11 additions & 0 deletions src/llm/test/google/mapper_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,17 @@ local function define_tests()
tests.is_nil(google_tools)
end)

it("should send a tool declared without a description", function()
local google_tools = mapper.map_tools({
{ name = "ping", schema = { type = "object", properties = {} } }
}) :: any

tests.eq(#google_tools, 1)
tests.eq(google_tools[1].name, "ping")
tests.is_nil(google_tools[1].description)
tests.eq(google_tools[1].parameters.type, "object")
end)

it("should skip tools with missing required fields", function()
local contract_tools = {
{
Expand Down
12 changes: 12 additions & 0 deletions src/llm/test/openai/mapper_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,18 @@ local function define_tests()
test.eq(tools[1].strict, true)
end)

it("should send a tool declared without a description", function()
local tools, tool_map = openai_mapper.map_tools({
{ name = "ping", schema = { type = "object", properties = {} } }
})

test.eq(#tools, 1)
test.eq(tools[1].name, "ping")
test.is_nil(tools[1].description)
test.eq(tools[1].parameters.type, "object")
test.not_nil(tool_map["ping"])
end)

it("should handle empty tools array", function()
local tools, tool_map = openai_mapper.map_tools({})

Expand Down
12 changes: 12 additions & 0 deletions src/llm/test/openai_compat/mapper_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,18 @@ local function define_tests()
test.is_nil(next(tool_map))
end)

it("should send a tool declared without a description", function()
local openai_tools, tool_map = openai_mapper.map_tools({
{ name = "ping", schema = { type = "object", properties = {} } }
})

test.eq(#openai_tools, 1)
test.eq(openai_tools[1]["function"].name, "ping")
test.is_nil(openai_tools[1]["function"].description)
test.eq(openai_tools[1]["function"].parameters.type, "object")
test.not_nil(tool_map["ping"])
end)

it("should skip tools with missing required fields", function()
local contract_tools = {
{
Expand Down
Loading