Table of Contents

Configuring Gemini Image Generation for an Agent

This guide walks through enabling Gemini image generation on an agent, from configuring the Google API endpoint and AI model to adding the tool and testing it in the User Portal.

Overview

The Gemini Image Generation tool (Platform-Tool-Gemini-Image-Generation, in the Google tool family) generates and edits images using Google's Gemini image models (the Nano Banana family). Generated images are stored through the Context API and shown inline in the User Portal chat.

The feature has three configuration layers:

  1. API Endpoint — Connection to Google with service account credentials
  2. AI Model — An image generation model that references the endpoint and the Gemini deployment
  3. Agent Tool — The Gemini Image Generation tool on the agent, with the AI model as its Main Model

Prerequisites

  • Access to the Management Portal with permission to manage API endpoints, AI models, and agents
  • A Google Cloud project with the Gemini (Vertex AI) API enabled
  • A service account JSON key that can invoke Gemini models, stored as a Key Vault secret and referenced by an App Configuration key
  • The Context API running (required for image storage)

Supported Gemini Models

The tool works with Gemini models that support native image generation. The following have been tested:

Model Deployment Name Nano Banana Name Optimized For Resolution
gemini-3.1-flash-image-preview Nano Banana 2 Speed and high-volume developer use cases Up to 4K
gemini-2.5-flash-image Nano Banana High-volume, low-latency tasks 1K

Note: gemini-3-pro-image-preview (Nano Banana Pro) should also be compatible but has not been tested with this tool.

You can switch models at any time by selecting a different Main Model on the tool.

Step 1: Configure the Google API Endpoint

If you already have a Google endpoint (check Platform > API Endpoints), skip to Step 2.

  1. In the sidebar, select Platform > API Endpoints, and then select Create API Endpoint.
  2. Configure the following settings:
Field Value
Resource name / Display name A descriptive name, for example GoogleVertexAI
Provider Google Agent Platform (the older Google VertexAI provider uses the same handler)
Category General
Subcategory AIModel. The model editor lists only endpoints with this category and subcategory.
Endpoint URL Required by the form. The Google handler authenticates with the service account and does not call this URL directly.
Project, Location Optional. When set, they are passed to Gemini to pin the project and region.
Authentication type Google Service Account
Authentication parameters Add service_account_credentials with the App Configuration key that holds the service account JSON, for example FoundationaLLM:APIEndpoints:GoogleVertexAI:ServiceAccountCredentials
  1. Select Create API Endpoint.

Important: Store the service account JSON as a Key Vault secret and reference it through App Configuration. The JSON contains the project_id, private_key, client_email, and the other fields the tool needs to authenticate.

Step 2: Create a Gemini Image Generation AI Model

  1. In the sidebar, select Agents > Models, and then select Create Model.
  2. Configure the following settings:
Field Value
Display name / Name For example Gemini31FlashImagePreview or Gemini25FlashImage
Model Type ImageGeneration
Model Endpoint The endpoint from Step 1
Model deployment name The Gemini model ID, for example gemini-3.1-flash-image-preview or gemini-2.5-flash-image
Model version Required by the form, for example the release you deployed
  1. Select Create Model.

Tip: Create one AI model per Gemini deployment, then switch the tool's Main Model to compare quality and speed.

Step 3: Add the Tool to an Agent

The agent needs a function-calling workflow.

  1. In the sidebar, select Agents > Agents, and then select the pencil icon for the agent (or select Create Agent).
  2. On the Basic Settings tab, choose a chat Main model for reasoning and tool routing (for example a Gemini Pro or GPT model). This is separate from the image model.
  3. On the Workflow tab, select the workflow, and set:
Field Value
Workflow package name foundationallm_agent_plugins
Workflow class name FoundationaLLMFunctionCallingWorkflow
Workflow host LangChain
  1. On the Tools tab, select Add Tool.
  2. Expand the Google folder, select Select on Gemini Image Generation, and then select Add to Agent. The Edit Agent Tool dialog opens with the agent tool name GeminiImageGen.
  3. Under Resource References:
    • Main Prompt defaults to Platform-Agent-Tool-GeminiImageGen-Main.
    • Router Prompt defaults to Platform-Agent-Tool-GeminiImageGen-Router.
    • Main Model: select the AI model from Step 2. Adjust Temperature if needed.
  4. Select Save changes, and then select Save Changes (or Create Agent) on the agent.

To switch models later, open the tool from the agent's Tools tab, select a different Main Model, and save the tool and the agent. The new model is used on the next request.

Step 4: Test in the User Portal

  1. Open the User Portal and start a new chat with the agent.
  2. Enter an image prompt, such as Draw a cute cat or Create a futuristic city skyline at sunset.
  3. The agent calls the image generation tool and shows the result inline.

What to Expect

  • A "Running agent tools..." status appears while the image is generated.
  • The image appears inline, along with a short text response.

Current Capabilities

Text-to-image generation

Aspect Ratio Identifier Use Case
1:1 (Square, default) SQUARE Profile images, icons, social posts
16:9 LANDSCAPE Wallpapers, presentations
9:16 PORTRAIT Mobile wallpapers, stories
4:3 WIDE Standard photos, documents
3:4 TALL Portrait photos, posters

Image editing and reference images

The tool accepts up to 14 images from the conversation's files (for example images the user uploaded) as grounding input. Use this to edit an existing image, combine several images, or transfer a style or subject from reference images. Extra images beyond 14 are dropped.

Automatic file storage

Generated images are uploaded to the Context API, stored with the conversation and agent, and rendered inline in the chat.

Not Yet Supported

These Gemini capabilities are not exposed by the tool yet:

  • Output resolution (image_size: 512, 1K, 2K, 4K) for Gemini 3 models
  • Thinking level control (thinkingLevel) for Gemini 3 models
  • Grounding with Google Search for image generation. For text answers grounded on the web, use Gemini Web Grounding. Do not assign an image model as that tool's main model.
  • Additional aspect ratios supported by Gemini 3.1 Flash (for example 1:4, 4:1, 2:3, 3:2, 4:5, 5:4, 21:9)

Troubleshooting

Image does not appear in the User Portal

  • Verify the Context API is running; the tool uploads images to it.
  • Check the LangChain API logs for upload errors.
  • Start a new chat to get a fresh conversation.

The tool has no model

The tool needs a Main Model. Open the tool from the agent's Tools tab, select a model in Resource References, and save the tool and the agent.

"Failed to retrieve service account credentials" error

  • The service_account_credentials authentication parameter is missing, or its App Configuration key is wrong.
  • Verify the Key Vault secret exists and contains valid service account JSON.

The endpoint is not listed in Model Endpoint

The model editor lists only endpoints with Category General and Subcategory AIModel. Update the endpoint on Platform > API Endpoints.

The agent does not call the image tool

  • Try an explicit prompt, such as Generate an image of....
  • Verify the tool appears in the agent's Tools available to the agent table.
  • Check that the workflow class is FoundationaLLMFunctionCallingWorkflow.

Image generation takes a long time

Generation typically takes 10–30 seconds. gemini-2.5-flash-image is optimized for low latency; gemini-3.1-flash-image-preview can take longer because of its thinking process but produces higher quality.