Streaming Agent

Code

1from kern.agent import Agent
2from kern.models.litellm import LiteLLM
3
4openai_agent = Agent(
5 model=LiteLLM(
6 id="gpt-5-mini",
7 name="LiteLLM",
8 ),
9 markdown=True,
10)
11
12openai_agent.print_response("Share a 2 sentence horror story", stream=True)

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 LITELLM_API_KEY=xxx

Install dependencies

1uv pip install -U litellm openai kern-ai

Run Agent

1python cookbook/11_models/litellm/basic_stream.py