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 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