Gemini

GeminiTools are a set of tools that allow an Agent to interact with Google AI API services for generating images and videos.

Prerequisites

Before using GeminiTools, make sure to have the google-genai library installed and the credentials configured.

  1. Install dependencies:

    1uv pip install google-genai kern-ai
  2. Set your credentials:

    • For Gemini API:
      1export GOOGLE_API_KEY="your-google-genai-api-key"
    • For Vertex AI:
      1export GOOGLE_CLOUD_PROJECT="your-google-cloud-project-id"
      2export GOOGLE_CLOUD_LOCATION="your-google-cloud-location"
      3export GOOGLE_GENAI_USE_VERTEXAI=true

Initialization

Import GeminiTools and add it to your Agent's tool list.

1from kern.agent import Agent
2from kern.tools.models.gemini import GeminiTools
3
4agent = Agent(
5 tools=[GeminiTools()],
6 )

Usage Examples

GeminiTools can be used for a variety of tasks. Here are some examples:

Image Generation

1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3from kern.tools.models.gemini import GeminiTools
4from kern.utils.media import save_base64_data
5
6agent = Agent(
7 model=OpenAIResponses(id="gpt-5.2"),
8 tools=[GeminiTools()],
9 )
10
11response = agent.run("Create an artistic portrait of a cyberpunk samurai in a rainy city")
12if response.images:
13 save_base64_data(response.images[0].content, "tmp/cyberpunk_samurai.png")

Video Generation

Note

Video generation requires Vertex AI.

1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3from kern.tools.models.gemini import GeminiTools
4from kern.utils.media import save_base64_data
5
6agent = Agent(
7 model=OpenAIResponses(id="gpt-5.2"),
8 tools=[GeminiTools(vertexai=True)],
9 debug_mode=True,
10)
11
12agent.print_response(
13 "Generate a 5-second video of a kitten playing a piano",
14)
15response = agent.run("Generate a 5-second video of a kitten playing a piano")
16if response.videos:
17 for video in response.videos:
18 save_base64_data(video.content, f"tmp/kitten_piano_{video.id}.mp4")

Toolkit Params

ParameterTypeDefaultDescription
api_keyOptional[str]NoneGoogle API key for authentication. If not provided, uses GOOGLE_API_KEY environment variable.
vertexaiboolFalseWhether to use Vertex AI instead of standard Gemini API. Required for video generation.
project_idOptional[str]NoneGoogle Cloud project ID. Required when using Vertex AI.
locationOptional[str]NoneGoogle Cloud location/region. Required when using Vertex AI.
image_generation_modelstr"imagen-3.0-generate-002"Model to use for image generation.
video_generation_modelstr"veo-2.0-generate-001"Model to use for video generation.
enable_generate_imageboolTrueEnable the image generation function.
enable_generate_videoboolTrueEnable the video generation function.
allboolFalseEnable all available functions. When True, all enable flags are ignored.

Toolkit Functions

FunctionDescription
generate_imageGenerate an image based on a text prompt
generate_videoGenerate a video based on a text prompt

Developer Resources