Engineering12 min read

How to Build an AI Agent with Gemini: SDK, Tools, ADK

Build an AI agent with Gemini in 2026: the google-genai SDK (google-generativeai is deprecated), current model IDs, function calling, and Google's ADK.

Tega Adeyemi
Tega Adeyemi
Getting Started with Gemini Pro 2.5: Build a Simple AI Agent

To build an AI agent with Gemini in 2026 you install the google-genai package (the google-generativeai package this post was written with is deprecated), pick a current model ID such as gemini-2.5-pro or gemini-3.8-flash, and give the model tools through function calling. For anything beyond a single request-response loop, Google's Agent Development Kit (ADK) is the official agent framework: pip install google-adk, one Agent definition, adk run. This guide keeps the original Gemini 2.5 Pro walkthrough as the basic version and adds the current SDK, a function-calling example and an ADK agent on top. For the model itself, the official developer documentation is the reference.

Updated September 2026: SDK and model names checked against the Gemini API docs, "what changed" notes above the code that no longer runs as written, a function-calling example, an ADK section, FAQ. The original walkthrough and code are kept below.

Model choice is the easy decision; the agent harness around it (gates, observability, recovery) is the harder work we cover in Cohorte's Building Accountable AI Agents course (E3).

Presentation of the Framework

Gemini Pro 2.5 is part of Google’s Gemini family of models, known for their extensive reasoning capabilities. Key features include:

These features make Gemini Pro 2.5 a robust tool for developers, researchers, and content creators looking to tackle complex challenges.

Benefits of Using Gemini Pro 2.5

Leveraging Gemini Pro 2.5 provides several advantages:

Getting Started

Prerequisites

Before diving in, ensure you have:

Installation and Setup

1. Create a Virtual Environment and Install Dependencies:

Open your terminal and run:

What changed since this was written: google-generativeai is the legacy SDK. Google's libraries page lists it as deprecated as of November 30, 2025, and its PyPI page marks the repository legacy (last release 0.8.6, December 2025). Install the current SDK instead and skip the last line of the block below:

pip install -U google-genai
python -m venv gemini_env
source gemini_env/bin/activate  # On Windows, use: gemini_env\Scripts\activate
pip install google-generativeai

2. Configure Your API Key and Import the Library:

In your Python script, set up the Gemini client:

What changed: the current SDK has no genai.configure and no GenerativeModel. You create one Client (it reads GEMINI_API_KEY from the environment, or takes api_key=) and pass the model ID on every call. The experimental ID gemini-2.5-pro-exp-03-25 used below is no longer listed on the models page; the stable ID is gemini-2.5-pro.

from google import genai

client = genai.Client()  # or genai.Client(api_key="YOUR_API_KEY")
MODEL = "gemini-2.5-pro"
import google.generativeai as genai

# Replace 'YOUR_API_KEY' with your actual Gemini API key.
genai.configure(api_key="YOUR_API_KEY")
model = genai.GenerativeModel("gemini-2.5-pro-exp-03-25")

This snippet imports the necessary library, configures the API key, and sets the model to Gemini Pro 2.5 Experimental.

First Steps & First Run

Before building a full agent, test the model with a simple prompt:

What changed: with google-genai the call moves to the client and takes the model ID as an argument. Same prompt, same .text:

response = client.models.generate_content(model=MODEL, contents=prompt)
print(response.text)
# A simple test prompt
prompt = "Explain the significance of Occam's Razor in simple terms."

response = model.generate_content(prompt)
print(response.text)

Run this script by executing:

python your_script.py

You should receive a clear, concise explanation of Occam's Razor—a great sign that your Gemini setup is working correctly.

Step-by-Step Example: Building a Simple Agent

Let’s build a simple agent that can answer user queries. This agent will:

Step 1: Define the Agent’s Purpose

For this example, our agent will function as a basic conversational assistant.

Step 2: Write the Agent Code

Below is a complete Python script that sets up and runs a basic conversational loop:

What changed: here is the same script on the current SDK. The loop is identical; only the import, the client and the model ID moved. The original version follows for reference.

from google import genai

# The client reads GEMINI_API_KEY from the environment.
client = genai.Client()
MODEL = "gemini-2.5-pro"


def ask_agent(prompt):
    """Send a prompt to Gemini and return the response text."""
    response = client.models.generate_content(model=MODEL, contents=prompt)
    return response.text


def run_agent():
    print("Welcome to the Gemini Agent!")
    print("Type 'exit' to quit.\n")
    while True:
        user_input = input("You: ")
        if user_input.lower() == "exit":
            print("Agent: Goodbye!")
            break
        answer = ask_agent(user_input)
        print(f"Agent: {answer}\n")


if __name__ == "__main__":
    run_agent()
import google.generativeai as genai

# Configure the Gemini API with your API key
genai.configure(api_key="YOUR_API_KEY")
model = genai.GenerativeModel("gemini-2.5-pro-exp-03-25")

def ask_agent(prompt):
    """Send a prompt to Gemini Pro 2.5 and return the response."""
    response = model.generate_content(prompt)
    return response.text

def run_agent():
    print("Welcome to the Gemini Pro 2.5 Agent!")
    print("Type 'exit' to quit.\n")
    while True:
        user_input = input("You: ")
        if user_input.lower() == "exit":
            print("Agent: Goodbye!")
            break
        # Process the user input and generate a response
        answer = ask_agent(user_input)
        print(f"Agent: {answer}\n")

if __name__ == "__main__":
    run_agent()

Code Explanation

This step-by-step example demonstrates how to integrate Gemini Pro 2.5 into your application to build an autonomous agent capable of handling user queries.

Which SDK and model to use in 2026

Two things in the original walkthrough no longer match the docs: the package and the model ID. Everything else (the loop, the prompt, .text) still holds.

The SDK. The current Python package is google-genai (pip install -U google-genai, from google import genai). The package this post was written with, google-generativeai, is listed on Google's libraries page as not actively maintained and deprecated as of November 30, 2025; the PyPI page calls the repository legacy and points to google-genai. Nothing you install today should import google.generativeai.

Inside google-genai there are now two ways to call a model. client.models.generate_content(...) is the direct successor of the generate_content in this post; Google says it remains fully supported but is now considered legacy. client.interactions.create(...), the Interactions API, is what Google recommends for all new projects and where new models, tools and agentic features land first; it needs google-genai 2.3.0 or newer. Our rule: migrating an old script, use generate_content and be done in five minutes; starting an agent, use the Interactions API, because tool calls and multi-step state are designed around it.

The model. On the models page today, gemini-2.5-pro is stable and the deprecations page shows no shutdown date for it. The experimental ID in the original code, gemini-2.5-pro-exp-03-25, is gone, and the three 2.5 Pro previews (-preview-03-25, -05-06, -06-05) were shut down on December 2, 2025. The lesson is not about 2.5 Pro; it is that experimental and preview IDs die within months, so pin a stable ID.

Model IDStatus (Sept 2026)Note
gemini-2.5-proStableThe model this post is about; no shutdown date announced
gemini-2.5-flash, gemini-2.5-flash-liteStableCheaper and faster; the ADK docs default to 2.5 Flash
gemini-3.8-flashStable (newest)Used in every 2026 Gemini API example; 3.7, 3.6 and 3.5 Flash are also stable
gemini-3.1-pro-previewPreviewThe 3.x Pro line; not for production pins
gemini-2.0-flash, gemini-2.0-flash-liteShut downRetired June 1, 2026; requests fail

Whatever you pick, read the model ID from configuration, not from a string literal buried in the agent, and check the deprecations page in your release checklist.

Give the agent tools: function calling with Gemini

The script above is a chatbot, not an agent: it can talk, it cannot act. Function calling is the step that changes that. You describe a function in a JSON schema, the model decides when to call it and with which arguments, you run it and hand the result back. The model never executes anything; every side effect goes through your code, which is exactly where the checks belong.

This is the pattern from the function-calling docs, on the Interactions API, condensed into one runnable file:

import json
from google import genai

client = genai.Client()
MODEL = "gemini-3.8-flash"  # the model the function-calling docs use; gemini-2.5-pro also works

# 1. Describe the tool. The model never runs it; you do.
weather_function = {
    "type": "function",
    "name": "get_current_temperature",
    "description": "Gets the current temperature for a given location.",
    "parameters": {
        "type": "object",
        "properties": {
            "location": {"type": "string", "description": "The city name, e.g. San Francisco"},
        },
        "required": ["location"],
    },
}

def get_current_temperature(location: str) -> dict:
    return {"location": location, "temperature_c": 18}  # replace with a real lookup

# 2. Ask. The model answers with a function_call step instead of text.
interaction = client.interactions.create(
    model=MODEL,
    input="What's the temperature in London?",
    tools=[weather_function],
)
fc_step = next(s for s in interaction.steps if s.type == "function_call")
print("Function to call:", fc_step.name, fc_step.arguments)

# 3. Run the function yourself and send the result back on the same interaction.
result = get_current_temperature(**fc_step.arguments)
final = client.interactions.create(
    model=MODEL,
    input=[{
        "type": "function_result",
        "name": fc_step.name,
        "call_id": fc_step.id,
        "result": [{"type": "text", "text": json.dumps(result)}],
    }],
    tools=[weather_function],
    previous_interaction_id=interaction.id,
)
print(final.output_text)

Three things worth knowing before you build on it. First, the docs show one round trip; a real agent wraps steps 2 and 3 in a loop that runs until the interaction has no more function_call steps. Second, the arguments come from the model, so validate them before they reach anything that writes, pays or deletes. Third, Google also hosts tools on its side (Google Search, code execution, file search) that you enable in the same tools list without writing the function; check the function-calling and tools pages for the current list.

Agent Development Kit: Google's official agent framework

At some point the hand-written loop grows a memory, a second agent, an evaluation set and a deployment target, and you are maintaining a framework you did not mean to write. Google's answer is the Agent Development Kit (ADK): in its own words, an open-source, code-first Python framework for building, evaluating, and deploying sophisticated AI agents. It is available in Python, TypeScript, Go, Java and Kotlin, works with Gemini out of the box and with other models through adapters, and deploys to Agent Runtime, Cloud Run, GKE or your own containers. The Python package is google-adk (version 2.8.0 as of August 26, 2026, Python 3.10 or newer).

pip install google-adk

An agent is a Python object. Tools are plain typed Python functions passed in tools=[...]; the example below follows the shape used in the ADK LLM-agent docs:

# my_agent/agent.py
from google.adk.agents import LlmAgent


def get_capital_city(country: str) -> str:
    """Returns the capital city of the given country."""
    capitals = {"france": "Paris", "morocco": "Rabat", "japan": "Tokyo"}
    return capitals.get(country.lower(), f"I do not know the capital of {country}.")


root_agent = LlmAgent(
    name="capital_agent",
    model="gemini-2.5-flash",  # any current Gemini ID; the ADK docs use 2.5 Flash
    description="Answers user questions about the capital city of a given country.",
    instruction="You are an agent that provides the capital city of a country. Use the tool.",
    tools=[get_capital_city],
)

Run it from the parent folder with adk run my_agent for a terminal chat or adk web for the local dev UI (the quickstart has the exact folder layout and the .env file for the API key). Compared with the loop above you get for free: session state, the multi-step tool loop, multi-agent orchestration, an evaluation harness and a deployment path.

When to use which. The plain SDK when you have one model, a handful of tools, and you want to own every line of the loop (which is a legitimate choice for a small internal tool). ADK when you need more than one agent, want evaluations in CI, or will deploy to Google Cloud and prefer the supported path. Either way the harness around the model (gates, logs, recovery) is where the work is, and that part does not come from any package.

FAQ

Can Gemini build AI agents?

Yes, at two levels. The Gemini API gives you function calling (your own tools) plus Google-hosted tools such as Google Search, code execution and file search through the Interactions API, which is enough for a single-model agent loop you write yourself. For multi-agent systems, evaluation and deployment, Google ships the Agent Development Kit (ADK), an open-source framework with Gemini as the default model.

Which Gemini model should I use for agents in 2026?

gemini-2.5-pro is still a stable model with no shutdown date announced on the deprecations page as of September 2026, so the walkthrough above keeps working. The 2026 docs use gemini-3.8-flash in every example (listed as the newest stable model); the 3.x Pro line is gemini-3.1-pro-preview, which is preview, not stable. Pin an exact ID, not an experimental one, and check the models page before a release.

google-generativeai or google-genai?

google-genai. The google-generativeai package (import google.generativeai) is the legacy SDK: Google lists it as deprecated as of November 30, 2025, and its PyPI page marks the repository legacy. The replacement is pip install -U google-genai with from google import genai and a single Client object.

Does Gemini support function calling?

Yes. You pass tool declarations in tools=[...], the model returns a function_call step with the name and arguments, you execute the function and send a function_result back on the same interaction (previous_interaction_id). The model never runs your code; the loop and its guardrails are yours.

What is Google ADK (Agent Development Kit)?

An open-source, code-first framework from Google for building, evaluating and deploying AI agents, available in Python, TypeScript, Go, Java and Kotlin. In Python: pip install google-adk (Python 3.10 or newer; version 2.8.0 was released on August 26, 2026), define an Agent with a model, an instruction and a list of Python functions as tools, then run it with adk run or adk web.

Is there a free tier for building agents with Gemini?

Yes. On September 3, 2026 the Gemini API pricing page says you can "start building free of charge with generous limits", and both gemini-2.5-pro and gemini-2.5-flash show "Free of charge" for input and output tokens on the free tier, with the note that free-tier content is used to improve Google products. Limits and eligibility change; check the pricing page before you plan on it.

Final Thoughts

Gemini Pro 2.5 represents a significant leap forward in AI model capabilities, thanks to its advanced “thinking” mechanism, multimodal support, and extended context window. Whether you’re a developer looking to automate coding tasks, a researcher analyzing large datasets, or a content creator exploring new frontiers, this model offers unprecedented power and flexibility.

By following this guide—from installation to building a basic agent—you now have the foundation to experiment further. Leverage the official Gemini presentation and consult the Developer Documentation for additional insights and advanced use cases.

Until the next one,

Tega AdeyemiMarch 26, 2025

The script works. Production is a different sport.

The AI OS letter covers the part tutorials skip: verification, trust, what breaks with real users. One idea, every Saturday, from CM, Cohorte's founder, who has shipped 60+ AI systems.

Free weekly. No spam. Unsubscribe in one click.

Subscribed ✓

The next letter arrives Saturday. Go finish the build.