Agent with URL Context and Search

Code

1"""Combine URL context with Google Search for comprehensive web analysis.
2
3"""
4
5from kern.agent import Agent
6from kern.models.google import Gemini
7
8# Create agent with both Google Search and URL context enabled
9agent = Agent(
10 model=Gemini(id="gemini-2.5-flash", search=True, url_context=True),
11 markdown=True,
12)
13
14# The agent will first search for relevant URLs, then analyze their content in detail
15agent.print_response(
16 "Analyze the content of the following URL: https://kern.ndx.rocks/introduction and also give me latest updates on AI agents"
17)

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_with_search.py