Skip to contents

A specialized AgentDriver for the Google Gemini API (AI Studio / Vertex AI).

Value

A GeminiAPIDriver R6 object.

Details

Setup: Requires the GOOGLE_API_KEY environment variable to be set. Add it to your .Renviron: GOOGLE_API_KEY="AIza..."

Super class

HydraR::AgentDriver -> GeminiAPIDriver

Public fields

api_base

String. Base URL.

Methods

Inherited methods


Method new()

Initialize GeminiAPIDriver

Usage

GeminiAPIDriver$new(
  id = "gemini_api",
  model = "gemini-3.1-flash-lite-preview",
  validation_mode = "warning",
  working_dir = NULL
)

Arguments

id

String. Unique identifier for this driver.

model

String. Google model ID (e.g., "gemini-1.5-flash").

validation_mode

String. Controls schema enforcement behavior.

working_dir

String. Optional path for isolated execution.

Returns

A new GeminiAPIDriver object. Get Capabilities


Method get_capabilities()

Usage

GeminiAPIDriver$get_capabilities()

Returns

A list of capabilities supported by the Gemini API. Call Gemini API


Method call()

Usage

GeminiAPIDriver$call(
  prompt,
  model = NULL,
  system_prompt = NULL,
  cli_opts = list(),
  ...
)

Arguments

prompt

String. The prompt or query provided by the user.

model

String. Optional override for the model ID.

system_prompt

String. Optional system-level instructions for the model.

cli_opts

List. Advanced API parameters (e.g., generationConfig).

...

Additional arguments passed to the requester.

Returns

String. The text response generated by Gemini.


Method clone()

The objects of this class are cloneable with this method.

Usage

GeminiAPIDriver$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

if (FALSE) { # \dontrun{
# 1. Initialize Gemini Pro API
driver <- GeminiAPIDriver$new(model = "gemini-1.5-pro")

# 2. Advanced call with custom generation config and safety filtering
response <- driver$call(
  prompt = "Write a high-performance R function for matrix multiplication.",
  cli_opts = list(
    generationConfig = list(
      temperature = 0.9,
      topP = 0.8,
      topK = 40,
      maxOutputTokens = 2048
    ),
    safetySettings = list(
      list(category = "HARM_CATEGORY_HARASSMENT", threshold = "BLOCK_LOW_AND_ABOVE")
    )
  )
)
} # }