Skip to main content
Google’s Gemini models work in Swarms through the same Agent interface as every other provider. Gemini’s massive context windows (up to 2M tokens) and strong multimodal support make it a natural fit for long-document analysis, video understanding, and image-heavy workflows.

Installation

Environment Setup

Or in a .env file:
Get your API key at aistudio.google.com. The free tier is generous and great for prototyping.

Quick Start

The minimum needed to run a Gemini agent:

Model Names

Gemini models are prefixed with gemini/ for LiteLLM routing:

Gemini 2.5 Pro — Frontier Reasoning

The right pick for hard reasoning tasks, long-document analysis, or anything where you need the full 2M-token context window.

Gemini 2.5 Flash — The Workhorse

Flash is the right default for most production agents. Strong quality, fast, and cheap.

Gemini 2.5 Flash-Lite — Triage & High-Volume

For classification, routing, and high-volume workloads where cost matters most.

Vision

Gemini’s vision capabilities are excellent. Pass an image path, URL, or base64 string:

Long-Context Document Analysis

Gemini 2.5 Pro’s massive context window lets you drop entire books, codebases, or document sets into a single prompt:

Streaming

Stream tokens straight to stdout:
Or pipe tokens through your own callback:

Tool Use

Gemini handles tool calls fluently. Define plain Python functions with docstrings:

Mixing Models in a Workflow

Different Gemini models for different jobs in the same workflow:

Production Defaults

For Gemini agents in production:

Next Steps