Google ADKgoogle-adk 2.8 · Python 3.10+
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
28 small wins to finish your pathNext lesson

Using a real model

Everything so far used the stand-in you wrote in lesson 4. Swapping in a real model is one line, and nothing else in any of these programs changes.

python
agent = LlmAgent(
    name="support",
    model="gemini-flash-latest",
    instruction="Help customers with their orders.",
    tools=[lookup_order],
)

A string instead of an object. ADK looks it up, builds the client, and reads the key from your environment. Everything downstream, the runner, sessions, tools, callbacks, workflow agents, was only ever talking to something with a generate_content_async method.

Setting up the key

Get a Gemini API key from Google AI Studio, then put it in a file called .env in the agent's folder, next to agent.py. That is where ADK looks, and it is why adk create generates the file for you in lesson 1.

bash
# my_agent/.env
GOOGLE_API_KEY="PASTE_YOUR_GEMINI_API_KEY_HERE"

That single line is the whole setup for the Gemini API. Nothing in your code reads it: ADK loads the file and the client picks the key up from the environment, which is why the agent above only names a model.

Or through Google Cloud

If you are going through the Gemini Enterprise Agent Platform rather than the Gemini API, the same file holds a project and a location instead of a key:

bash
# .env configuration file
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_CLOUD_LOCATION=us-central1
GOOGLE_GENAI_USE_ENTERPRISE=True
Do not commit it
Add .env to your .gitignore before you put a key in it. It sits inside the agent folder, which is exactly the folder you are most likely to commit.

There is no output on this page, because a real model needs a key and this site only shows output that came out of a program that ran here.

Three ways to reach a model

WayWhat it covers
A stringGemini through AI Studio or the agent platform, and Claude through the registry
A connectorModels outside Google: LiteLLM, Ollama, vLLM, Apigee, LiteRT
Model routingPicking between several models at runtime, with failover

LiteLLM is the one worth knowing about, because it is how ADK reaches a hundred other providers with one wrapper. Ollama and vLLM are the same idea for models you host yourself.

What changes when the model is real

  • It decides for itself. The same question can produce a different tool call twice, which is why lesson 6 taught you to read events.
  • Bad descriptions start costing you. The stand-in never misread a tool. A real model does, and lesson 9 is the fix.
  • Limits matter. The max_llm_calls from lesson 15 stops being theoretical.
  • It costs money per turn. Long sessions send the whole history, so lesson 21's advice about small state and small tool results turns into a bill.
Do not delete it
Keep the stand-in after you switch. Running your tests against a scripted model is faster, free, and gives the same answer every time, which is exactly what a test needs.
Try it yourself
  • Swap one agent to a real model and run the same question five times. Compare the events.
  • Point an agent at a local model through Ollama and see what changes.

Every expert started right here.