Skip to main content
NanoBananaTools enables an Agent to generate images using Google’s Gemini 2.5 Flash Image model (Nano Banana).

Prerequisites

You need to install the google-genai and Pillow libraries.
pip install google-genai Pillow
Set the GOOGLE_API_KEY environment variable. You can obtain an API key from Google AI Studio.
export GOOGLE_API_KEY=****

Example

The following agent will use Nano Banana to generate an image based on a text prompt.
nano_banana_tools.py
from pathlib import Path

from agno.agent import Agent
from agno.tools.nano_banana import NanoBananaTools

# Example 1: Basic NanoBanana agent with default settings
agent = Agent(tools=[NanoBananaTools()], name="NanoBanana Image Generator")

# Example 2: Custom aspect ratio generator
portrait_agent = Agent(
    tools=[
        NanoBananaTools(
            aspect_ratio="2:3"  # Portrait orientation
        )
    ],
    name="Portrait NanoBanana Generator",
)

# Example 3: Widescreen generator for panoramic images
widescreen_agent = Agent(
    tools=[
        NanoBananaTools(
            aspect_ratio="16:9"  # Widescreen format
        )
    ],
    name="Widescreen NanoBanana Generator",
)

# Test basic generation
agent.print_response(
    "Generate an image of a futuristic city with flying cars",
    markdown=True,
)

# Generate and save an image
response = widescreen_agent.run(
    "Create a panoramic nature scene with mountains and a lake at sunset",
    markdown=True,
)

# Save the generated image if available
if response.images and response.images[0].content:
    output_path = Path("generated_image.png")
    with open(output_path, "wb") as f:
        f.write(response.images[0].content)

    print(f"Image was successfully generated and saved to: {output_path}")

Toolkit Params

ParameterTypeDefaultDescription
modelstr"gemini-2.5-flash-image"The Nano Banana model to use
aspect_ratiostr"1:1"Image aspect ratio. Supported: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
api_keystrNoneThe Google API key for authentication
enable_create_imageboolTrueEnable the create image functionality

Toolkit Functions

FunctionDescription
create_imageGenerates an image based on a text prompt

Developer Resources