From 4018b9ca80accc15a57c4d083a3aae7b8a0fc16b Mon Sep 17 00:00:00 2001 From: matteo serva Date: Sat, 14 Feb 2026 09:01:48 +0100 Subject: [PATCH] Fix gpt-oss tool calling: pass tool args and tool responses as json --- common/chat.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/common/chat.cpp b/common/chat.cpp index 47a34d5822..d5aac2db77 100644 --- a/common/chat.cpp +++ b/common/chat.cpp @@ -2029,9 +2029,25 @@ static common_chat_params common_chat_params_init_gpt_oss(const common_chat_temp auto has_reasoning_content = msg.contains("reasoning_content") && msg.at("reasoning_content").is_string(); auto has_tool_calls = msg.contains("tool_calls") && msg.at("tool_calls").is_array(); - if (has_reasoning_content && has_tool_calls) { + + if (msg.at("role") == "tool") + { + auto adjusted_message = msg; + std::string response = msg.value("content",std::string()); + adjusted_message["content"] = json::parse(response); + adjusted_messages.push_back(adjusted_message); + } else if (has_tool_calls) { auto adjusted_message = msg; - adjusted_message["thinking"] = msg.at("reasoning_content"); + if(has_reasoning_content) + { + adjusted_message["thinking"] = msg.at("reasoning_content"); + } + for ( auto& tool_call : adjusted_message.at("tool_calls")) + { + auto& function = tool_call.at("function"); + std::string args = function.value("arguments",std::string()); + function["arguments"] = json::parse(args); + } adjusted_messages.push_back(adjusted_message); } else { adjusted_messages.push_back(msg);