fix: resolve BuiltinTools to strings for vllm tool_call messages

When the result of a ToolCall gets passed back into vLLM for the model
to handle the tool call result (as is often the case in agentic
tool-calling workflows), we forgot to handle the case where
BuiltinTool calls are not string values but instead instances of the
BuiltinTool enum. This fixes that, properly converting those enums to
string values before trying to serialize them into an OpenAI chat
completion request to vLLM.

PR #1931 fixed a bug where we weren't passing these tool calling
results back into vLLM, but as a side-effect it created this
serialization bug when using BuiltinTools.

Resolves #2070

Signed-off-by: Ben Browning <bbrownin@redhat.com>
This commit is contained in:
Ben Browning 2025-04-30 20:10:33 -04:00
parent 293d95b955
commit fd9d52564b
2 changed files with 33 additions and 2 deletions

View file

@ -532,12 +532,17 @@ async def convert_message_to_openai_dict(message: Message, download: bool = Fals
if hasattr(message, "tool_calls") and message.tool_calls:
result["tool_calls"] = []
for tc in message.tool_calls:
# The tool.tool_name can be a str or a BuiltinTool enum. If
# it's the latter, convert to a string.
tool_name = tc.tool_name
if isinstance(tool_name, BuiltinTool):
tool_name = tool_name.value
result["tool_calls"].append(
{
"id": tc.call_id,
"type": "function",
"function": {
"name": tc.tool_name,
"name": tool_name,
"arguments": tc.arguments_json if hasattr(tc, "arguments_json") else json.dumps(tc.arguments),
},
}