Thinking (Interactions)

Code

1import asyncio
2
3from kern.agent import Agent
4from kern.models.google import GeminiInteractions
5
6agent = Agent(
7 model=GeminiInteractions(
8 id="gemini-3-flash-preview",
9 thinking_level="high",
10 ),
11 markdown=True,
12)
13
14if __name__ == "__main__":
15 agent.print_response(
16 "Solve: If a train travels at 60 mph for 2.5 hours, then at 80 mph for 1.5 hours, what is the total distance and average speed?"
17 )
18
19 asyncio.run(
20 agent.aprint_response(
21 "Explain why the sum of angles in a triangle is always 180 degrees.",
22 stream=True,
23 )
24 )

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>=2.0" kern-ai

Run Agent

1python cookbook/90_models/google/gemini_interactions/thinking.py