Basic Streaming Agent

Stream a CometAPI response in the terminal with stream=True.

Code

from typing import Iterator

from agno.agent import Agent, RunOutputEvent  # noqa
from agno.models.cometapi import CometAPI

agent = Agent(model=CometAPI(id="gpt-5.2"), markdown=True)

# Get the response in a variable
# run_response: Iterator[RunOutputEvent] = agent.run("Explain quantum computing in simple terms", stream=True)
# for chunk in run_response:
#     print(chunk.content)

# Print the response in the terminal
agent.print_response("Explain quantum computing in simple terms", stream=True)

Usage

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Set your API key

export COMETAPI_KEY=xxx

Install dependencies

uv pip install -U agno openai

Run Agent

Save the code above as basic.py, then run:

python basic.py