0

๐ŸŽฏ Tutorial 2: Model-Agnostic Agent

awesome-llm-apps2_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.

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

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

  1. Run the OpenAI agent and ask questions
  2. Run the Anthropic agent with the same questions
  3. Notice differences in response style and approach
  4. 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_agent for ADK to recognize it
  • Environment Variables: Each folder needs its own .env file
  • 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)