Class: Google::ADK::FunctionTool
- Defined in:
- lib/google/adk/tools/function_tool.rb
Overview
Tool that wraps a Ruby callable (Proc, Method, etc.)
Instance Attribute Summary collapse
-
#callable ⇒ Object
readonly
Returns the value of attribute callable.
-
#parameters_schema ⇒ Object
readonly
Returns the value of attribute parameters_schema.
Attributes inherited from BaseTool
Instance Method Summary collapse
-
#call(params = {}) ⇒ Object
Execute the wrapped function.
-
#initialize(name:, description: nil, callable:, parameters_schema: nil) ⇒ FunctionTool
constructor
Initialize a function tool.
-
#schema ⇒ Hash
Get parameter schema.
-
#to_gemini_schema ⇒ Hash
Convert to Gemini API schema format.
Constructor Details
#initialize(name:, description: nil, callable:, parameters_schema: nil) ⇒ FunctionTool
Initialize a function tool
17 18 19 20 21 |
# File 'lib/google/adk/tools/function_tool.rb', line 17 def initialize(name:, description: nil, callable:, parameters_schema: nil) super(name: name, description: description) @callable = callable @parameters_schema = parameters_schema # Don't default here, let to_gemini_schema handle it end |
Instance Attribute Details
#callable ⇒ Object (readonly)
Returns the value of attribute callable.
9 10 11 |
# File 'lib/google/adk/tools/function_tool.rb', line 9 def callable @callable end |
#parameters_schema ⇒ Object (readonly)
Returns the value of attribute parameters_schema.
9 10 11 |
# File 'lib/google/adk/tools/function_tool.rb', line 9 def parameters_schema @parameters_schema end |
Instance Method Details
#call(params = {}) ⇒ Object
Execute the wrapped function
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/google/adk/tools/function_tool.rb', line 27 def call(params = {}) if @callable.parameters.empty? @callable.call else # Convert hash params to keyword arguments if the callable expects them if expects_keyword_args? @callable.call(**params) else @callable.call(params) end end end |
#schema ⇒ Hash
Get parameter schema
43 44 45 |
# File 'lib/google/adk/tools/function_tool.rb', line 43 def schema @parameters_schema end |
#to_gemini_schema ⇒ Hash
Convert to Gemini API schema format
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/google/adk/tools/function_tool.rb', line 50 def to_gemini_schema # Try to infer parameters from method signature if no schema provided schema = @parameters_schema || infer_schema_from_callable { "name" => @name, "description" => @description || "Function tool", "parameters" => schema } end |