@@ -281,7 +281,8 @@ def need_builtin_tool_call(self) -> bool:
281281 # TODO: figure out which tools are MCP tools
282282 if ( # noqa: SIM103
283283 last_message .type == "function_call"
284- and last_message .name in ("code_interpreter" , "python" )
284+ and last_message .name
285+ in ("code_interpreter" , "python" , "web_search_preview" )
285286 ):
286287 return True
287288
@@ -310,12 +311,38 @@ async def call_python_tool(
310311
311312 return [message ]
312313
314+ async def call_search_tool (
315+ self , tool_session : Union ["ClientSession" , Tool ], last_msg : FunctionCall
316+ ) -> list [ResponseInputOutputItem ]:
317+ self .called_tools .add ("browser" )
318+ if envs .VLLM_TOOL_JSON_ERROR_AUTOMATIC_RETRY :
319+ try :
320+ args = json .loads (last_msg .arguments )
321+ except json .JSONDecodeError as e :
322+ return _create_json_parse_error_messages (last_msg , e )
323+ else :
324+ args = json .loads (last_msg .arguments )
325+ result = await tool_session .call_tool ("search" , args )
326+ result_str = result .content [0 ].text
327+
328+ message = ResponseFunctionToolCallOutputItem (
329+ id = f"fco_{ random_uuid ()} " ,
330+ type = "function_call_output" ,
331+ call_id = f"call_{ random_uuid ()} " ,
332+ output = result_str ,
333+ status = "completed" ,
334+ )
335+
336+ return [message ]
337+
313338 async def call_tool (self ) -> list [ResponseInputOutputItem ]:
314339 if not self .parser .response_messages :
315340 return []
316341 last_msg = self .parser .response_messages [- 1 ]
317342 if last_msg .name == "code_interpreter" :
318343 return await self .call_python_tool (self ._tool_sessions ["python" ], last_msg )
344+ elif last_msg .name == "web_search_preview" :
345+ return await self .call_search_tool (self ._tool_sessions ["browser" ], last_msg )
319346 return []
320347
321348 def render_for_completion (self ):
0 commit comments