Agent with URL Context

Code

1from kern.agent import Agent
2from kern.models.google import Gemini
3
4agent = Agent(
5 model=Gemini(id="gemini-2.5-flash", url_context=True),
6 markdown=True,
7)
8
9url1 = "https://www.foodnetwork.com/recipes/ina-garten/perfect-roast-chicken-recipe-1940592"
10url2 = "https://www.allrecipes.com/recipe/83557/juicy-roasted-chicken/"
11
12agent.print_response(
13 f"Compare the ingredients and cooking times from the recipes at {url1} and {url2}"
14)

Usage

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your API key

1export GOOGLE_API_KEY=xxx

Install dependencies

1uv pip install -U google-genai kern-ai

Run Agent

1python cookbook/11_models/google/gemini/url_context.py