Nano Banana

Generate images with Google's Nano Banana model, including custom aspect ratios and saving output to disk.

Enable Agno agents to generate images with Google's Nano Banana (gemini-2.5-flash-image) model.

The toolkit currently accepts only gemini-2.5-flash-image. Google lists October 2, 2026 as its earliest shutdown date in the deprecation schedule. For the newer image model, use the native Gemini image-generation example; passing its ID to NanoBananaTools fails the toolkit’s model validation.

The outer agent uses the default OpenAI model, independently of the Google image tool. Export OPENAI_API_KEY as well as GOOGLE_API_KEY.

Prerequisites

  • Set your Google API key as environment variable: export GOOGLE_API_KEY="your_api_key"
  • Run uv pip install agno openai google-genai Pillow to install dependencies

from pathlib import Path

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

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

# 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

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    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 succesfully generated and saved to: {output_path}")

Run the Example

# Clone and setup repo
git clone https://github.com/agno-agi/agno.git
cd agno
git checkout d703c34f3abf3c41275d3fb2da6e0518a8881f24

# Create and activate virtual environment
./scripts/demo_setup.sh
source .venvs/demo/bin/activate

# Export relevant API keys
export GOOGLE_API_KEY="your_google_api_key"
export OPENAI_API_KEY="your_openai_api_key"

python cookbook/91_tools/nano_banana_tools.py

For details, see Nano Banana cookbook.