Async Basic Streaming Agent

Code

1import asyncio
2
3from kern.agent import Agent
4from kern.models.litellm import LiteLLM
5
6openai_agent = Agent(
7 model=LiteLLM(
8 id="gpt-5-mini",
9 name="LiteLLM",
10 ),
11 markdown=True,
12)
13
14# Print the response in the terminal
15asyncio.run(
16 openai_agent.aprint_response("Share a 2 sentence horror story", stream=True)
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 LITELLM_API_KEY=xxx

Install dependencies

1uv pip install -U litellm kern-ai

Run Agent

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