From eb1b1663f60762b43d18278bf4eaef849b6f5ba3 Mon Sep 17 00:00:00 2001 From: Florian Felsing Date: Fri, 13 Jun 2025 14:20:40 -0600 Subject: [PATCH 1/2] Add tool for native Gemini search capability --- .../providers/gemini/google_search_tool.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 lib/ruby_llm/providers/gemini/google_search_tool.rb diff --git a/lib/ruby_llm/providers/gemini/google_search_tool.rb b/lib/ruby_llm/providers/gemini/google_search_tool.rb new file mode 100644 index 00000000..3975dda2 --- /dev/null +++ b/lib/ruby_llm/providers/gemini/google_search_tool.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +module RubyLLM + module Providers + module Gemini + # Marker for Gemini's native Google search + class GoogleSearchTool < RubyLLM::Tool + description 'Gemini built-in Google search capability' + + def name = :google_search + def payload = { google_search: {} } + end + end + end +end From 39eca3c00e9625913b7f8617d60750a13cb26d13 Mon Sep 17 00:00:00 2001 From: Florian Felsing Date: Fri, 13 Jun 2025 14:21:55 -0600 Subject: [PATCH 2/2] Update Gemini tools formatter for built-in search support --- lib/ruby_llm/providers/gemini/tools.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/ruby_llm/providers/gemini/tools.rb b/lib/ruby_llm/providers/gemini/tools.rb index 70696e91..ceed14fe 100644 --- a/lib/ruby_llm/providers/gemini/tools.rb +++ b/lib/ruby_llm/providers/gemini/tools.rb @@ -9,9 +9,16 @@ module Tools def format_tools(tools) return [] if tools.empty? - [{ - functionDeclarations: tools.values.map { |tool| function_declaration_for(tool) } - }] + builtins, customs = tools.values.partition { |t| t.name == :google_search } + + formatted_tools = builtins.map(&:payload).uniq + unless customs.empty? + formatted_tools << { + functionDeclarations: customs.map { |t| function_declaration_for(t) } + } + end + + formatted_tools end # Extract tool calls from response data