Learn how to create agents that work with different AI models using OpenRouter. This example shows how ADK can use OpenAI and Anthropic models through separate agent implementations.
Sign in to save downloads to your library and vote.
Preview
๐ฏ Tutorial 2: Model-Agnostic Agent
Learn how to create agents that work with different AI models using OpenRouter. This example shows how ADK can use OpenAI and Anthropic models through separate agent implementations.
๐ฏ What You'll Learn
- OpenRouter Integration: Use one API key for multiple model providers
- Separate Agent Implementations: Compare different models side-by-side
- Tool Integration: Add simple tools to your agents
- Root Agent Pattern: Proper ADK agent naming convention
๐ง Core Concept: One API, Many Models
OpenRouter provides a unified API to access multiple AI models:
- โ Single API Key: Access OpenAI and Anthropic with one key
- โ Easy Comparison: Run different agents to compare responses
- โ Cost Effective: Pay-per-use pricing
- โ No Vendor Lock-in: Switch providers anytime
๐ Project Structure
2_model_agnostic_agent/
โโโ README.md # This overview
โโโ requirements.txt # Shared dependencies
โโโ 2_1_openai_adk_agent/ # OpenAI GPT-4 agent
โ โโโ agent.py # Agent implementation
โโโ 2_2_anthropic_adk_agent/ # Anthropic Claude agent
โโโ agent.py # Agent implementation
๐ง Available Agents
OpenAI Agent (2_1_openai_adk_agent/)
- Model: GPT-4 via OpenRouter
- Agent Name:
root_agent(required by ADK) - Features: Fun fact tool with OpenAI personality
Anthropic Agent (2_2_anthropic_adk_agent/)
- Model: Claude 4 Sonnet via OpenRouter
- Agent Name:
root_agent(required by ADK) - Features: Fun fact tool with Claude personality
๐ ๏ธ Setup & Usage
1. Get OpenRouter API Key
- Visit: https://openrouter.ai/keys
- Sign up and get your API key
2. Set Environment Variable
Create a .env file in each agent folder:
In 2_1_openai_adk_agent/.env:
OPENROUTER_API_KEY=your_openrouter_api_key_here
In 2_2_anthropic_adk_agent/.env:
OPENROUTER_API_KEY=your_openrouter_api_key_here
3. Install Dependencies
# From the 2_model_agnostic_agent directory
pip install -r requirements.txt
4. Test OpenAI Agent
adk web
Then select the 2_1_openai_adk_agent in the ADK web UI
- Try asking: "Tell me a fun fact!"
- Notice the OpenAI GPT-4 response style
5. Test Anthropic Agent
adk web
Then select the 2_2_anthropic_adk_agent in the ADK web UI
- Try asking: "Tell me a fun fact!"
- Compare with the GPT-4 response style
๐ก Key Code Pattern
Each agent follows the same pattern:
from google.adk.agents import Agent
from google.adk.models.lite_llm import LiteLlm
import os
# Create model via OpenRouter
model = LiteLlm(
model="openrouter/openai/gpt-4", # or claude model
api_key=os.getenv("OPENROUTER_API_KEY"),
base_url="https://openrouter.ai/api/v1"
)
# Create root_agent (required name for ADK)
root_agent = Agent(
name="agent_name",
model=model,
instruction="Your instructions here...",
tools=[your_tool_function],
)
๐ฏ Learning Objectives
By the end of this tutorial, you'll understand:
- โ How to use OpenRouter with ADK
- โ How to create separate agents for different models
- โ How to compare responses from different AI providers
- โ
How to properly structure ADK agents with
root_agent
๐ Comparing Models
- Run the OpenAI agent and ask questions
- Run the Anthropic agent with the same questions
- Notice differences in response style and approach
- Experiment with different types of prompts
๐ฐ Cost Information
- OpenRouter charges per token usage
- GPT-4o: More expensive but very capable
- Claude 4 Sonnet: Balanced cost and performance
- You can set spending limits in your OpenRouter dashboard
- Free tier available for testing
๐จ Important Notes
- Root Agent: Each agent must be named
root_agentfor ADK to recognize it - Environment Variables: Each folder needs its own
.envfile - API Key: The same OpenRouter key works for both agents
- Comparison: Run agents separately to compare model behaviors
Ingestion metadata
- Source catalog
- awesome-llm-apps
- Repository
- Shubhamsaboo/awesome-llm-apps ยท main
- File path
- ai_agent_framework_crash_course/google_adk_crash_course/2_model_agnostic_agent/README.md
- Last refreshed
- 7/23/2026, 10:39:09 PM (4h ago)
- Refresh schedule
- Daily ยท 03:00 UTC
- Dedupe status
- Unique ยท deduped by (source, url)