Gemini
Use Google’s Gemini models through Google AI Studio or Google Cloud Vertex AI - platforms that provide access to large language models and other services.
We recommend experimenting to find the best-suited model for your use case. Here are some general recommendations in the Gemini 2.x
family of models:
gemini-2.0-flash
is good for most use-cases.gemini-2.0-flash-lite
is the most cost-effective model.gemini-2.5-pro-exp-03-25
is the strongest multi-modal model.
Refer to the Google AI Studio documentation and the Vertex AI documentation for information on available model versions.
Authentication
You can use Gemini models through either Google AI Studio or Google Cloud’s Vertex AI:
Google AI Studio
Set the GOOGLE_API_KEY
environment variable. You can get one from Google AI Studio.
Vertex AI
To use Vertex AI in Google Cloud:
-
Refer to the Vertex AI documentation to set up a project and development environment.
-
Install the
gcloud
CLI and authenticate (refer to the quickstart for more details):
- Enable Vertex AI API and set the project ID environment variable (alternatively, you can set
project_id
in theAgent
config):
Export the following variables:
Or update your Agent configuration:
Example
Use Gemini
with your Agent
:
Grounding and Search
Gemini models support grounding and search capabilities through optional parameters. This automatically sends tools for grounding or search to Gemini. See more details here.
To enable these features, set the corresponding parameter when initializing the Gemini model:
To use grounding:
To use search:
Set show_tool_calls=True
in your Agent configuration to see the grounding or search results in the output.
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
id | str | "gemini-2.0-flash-exp" | The specific Gemini model ID to use. |
name | str | "Gemini" | The name of this Gemini model instance. |
provider | str | "Google" | The provider of the model. |
function_declarations | Optional[List[FunctionDeclaration]] | None | List of function declarations for the model. |
generation_config | Optional[Any] | None | Configuration for text generation. |
safety_settings | Optional[Any] | None | Safety settings for the model. |
generative_model_kwargs | Optional[Dict[str, Any]] | None | Additional keyword arguments for the generative model. |
grounding | bool | False | Whether to use grounding. |
search | bool | False | Whether to use search. |
grounding_dynamic_threshold | Optional[float] | None | The dynamic threshold for grounding. |
api_key | Optional[str] | None | API key for authentication. |
vertexai | bool | False | Whether to use Vertex AI instead of Google AI Studio. |
project_id | Optional[str] | None | Google Cloud project ID for Vertex AI. |
location | Optional[str] | None | Google Cloud region for Vertex AI. |
client_params | Optional[Dict[str, Any]] | None | Additional parameters for the client. |
client | Optional[GeminiClient] | None | The underlying generative model client. |
temperature | Optional[float] | None | Controls randomness in the output. Higher values (e.g., 0.8) make the output more random, while lower values (e.g., 0.2) make it more focused and deterministic. |
top_p | Optional[float] | None | Nucleus sampling parameter. Only consider tokens whose cumulative probability exceeds this value. |
top_k | Optional[int] | None | Only consider the top k tokens for text generation. |
max_output_tokens | Optional[int] | None | The maximum number of tokens to generate in the response. |
stop_sequences | Optional[list[str]] | None | List of sequences where the model should stop generating further tokens. |
logprobs | Optional[bool] | None | Whether to return log probabilities of the output tokens. |
presence_penalty | Optional[float] | None | Penalizes new tokens based on whether they appear in the text so far. |
frequency_penalty | Optional[float] | None | Penalizes new tokens based on their frequency in the text so far. |
seed | Optional[int] | None | Random seed for deterministic text generation. |
request_params | Optional[Dict[str, Any]] | None | Additional parameters for the request. |
Gemini
is a subclass of the Model class and has access to the same params.