Concept #172Mediumpython-for-gen-aigoogle-adk

How to use different LLM models (Gemini, OpenAI, Anthropic, Ollama) in Google ADK?

#google-adk#models#gemini#openai#anthropic#ollama#vllm#litellm

Answer

Using Different LLM Models in Google ADK

Google ADK is model-agnostic - while optimized for Gemini, it supports 100+ LLMs through multiple connectors.


Model Support Overview


1. Gemini Models (Direct)

python
from google.adk.agents import Agent

# Google AI Studio
agent = Agent(
    name="gemini_agent",
    model="gemini-2.5-flash",
    instruction="You are a helpful assistant.",
)

# Available Gemini models
# gemini-2.5-flash  - Fast, cost-effective
# gemini-2.5-pro    - Most capable
# gemini-2.0-flash  - Previous generation

Environment:

bash
# .env
GOOGLE_API_KEY=your-google-api-key

2. OpenAI Models (via LiteLLM)

python
from google.adk.agents import Agent
from google.adk.models.lite_llm import LiteLlm

agent = Agent(
    name="openai_agent",
    model=LiteLlm(model="openai/gpt-4o"),
    instruction="You are a helpful assistant.",
)

# Other OpenAI models
# openai/gpt-4o          - Latest GPT-4o
# openai/gpt-4-turbo     - GPT-4 Turbo
# openai/gpt-3.5-turbo   - Fast, affordable

Environment:

bash
OPENAI_API_KEY=sk-your-openai-key

3. Anthropic Claude (via Vertex AI)

python
from google.adk.agents import Agent
from google.adk.models.anthropic_llm import Claude
from google.adk.models.registry import LLMRegistry

# Register Claude model provider
LLMRegistry.register(Claude)

agent = Agent(
    name="claude_agent",
    model="claude-sonnet-4-6",
    instruction="You are a helpful assistant.",
)

Via LiteLLM (alternative)

python
from google.adk.models.lite_llm import LiteLlm

agent = Agent(
    name="claude_agent",
    model=LiteLlm(model="anthropic/claude-3-haiku-20240307"),
    instruction="You are a helpful assistant.",
)

Environment:

bash
ANTHROPIC_API_KEY=your-anthropic-key

4. Ollama (Local Models)

python
import os
from google.adk.agents import Agent
from google.adk.models.lite_llm import LiteLlm

os.environ["OLLAMA_API_BASE"] = "http://localhost:11434"

agent = Agent(
    name="local_agent",
    model=LiteLlm(model="ollama_chat/gemma3:latest"),
    instruction="You are a helpful assistant.",
)

# Other Ollama models
# ollama_chat/llama3:latest
# ollama_chat/mistral:latest
# ollama_chat/phi3:latest
bash
# Start Ollama first
ollama serve
ollama pull gemma3

5. vLLM (Self-Hosted)

python
from google.adk.agents import Agent
from google.adk.models.lite_llm import LiteLlm

agent = Agent(
    name="vllm_agent",
    model=LiteLlm(model="hosted_vllm/google/gemma-3-4b-it"),
    instruction="You are a helpful assistant.",
)
bash
# Start vLLM server
vllm serve google/gemma-3-4b-it --port 8000

Environment:

bash
HOSTED_VLLM_API_BASE=http://localhost:8000/v1

6. Vertex AI Model Garden

python
from google.adk.agents import Agent

# Llama 3 via Vertex AI
agent = Agent(
    name="llama_agent",
    model="vertex_ai/meta/llama-4-scout-17b-16e-instruct-maas",
    instruction="You are a helpful assistant.",
)

Model Comparison in ADK

ProviderConnectionLatencyCostBest For
GeminiDirectLowLowDefault, full ADK features
OpenAILiteLLMMediumMediumGPT-4o quality
AnthropicVertex/LiteLLMMediumMediumLong context tasks
OllamaLiteLLMLocalFreePrivacy, offline
vLLMLiteLLMSelf-hostedComputeCustom models

Pro tip: Gemini models get the deepest ADK integration (streaming, code execution, grounding). Third-party models may have limited feature support.

Learn more at Models Overview and LiteLLM.