Getting Started with Gemini
Introduction & Goals
Welcome to your first lesson in building effective agents with Gemini! You'll learn how to send messages using the Google Gen AI Python SDK (google.genai) and master the structure of Gemini's responses.
By the end, you'll be able to create a Python script that communicates with Gemini and inspects the full response object—a foundation for the advanced agent workflows we'll build later.
Setting Up the Client
To use Gemini, you must initialize the Gen AI client. In this environment, we use a custom base URL to route requests correctly.
Model Selection
You can choose different models based on your needs:
models/gemini-flash-latest: Points to the latest Gemini Flash model, optimized for speed, efficiency, and high-volume tasks.models/gemini-pro-latest: Points to the latest Gemini Pro model, designed for complex reasoning and large contexts.
For this lesson, we'll use the Flash model for simplicity. See the Gemini API models documentation for the full list of available models.
How Gemini Messaging Works
Gemini uses a conversational pattern. Each interaction consists of a list of messages. Every message is a dictionary with a role ("user" or "model") and a list of parts containing the content.
Example structure:
The System Instruction
A system instruction defines the model's persona or behavioral constraints. It guides Gemini's logic throughout the entire session.
While user messages provide the task, the system instruction sets the "rules of engagement."
