Basic Streaming Agent

Stream a SiliconFlow agent's response with stream=True.

Code

from agno.agent import Agent, RunOutputEvent  # noqa
from agno.models.siliconflow import Siliconflow

agent = Agent(model=Siliconflow(id="openai/gpt-oss-120b", base_url="https://api.siliconflow.com/v1"), markdown=True)

# Get the response in a variable
# run_response: Iterator[RunOutputEvent] = agent.run("Share a 2 sentence horror story", stream=True)
# for chunk in run_response:
#     print(chunk.content)

# Print the response in the terminal
agent.print_response("Share a 2 sentence horror story", stream=True)

These examples use the SiliconFlow global service: create a key in the global console and use https://api.siliconflow.com/v1. Choose a model available to that account. For a China-region account, use its key, model catalog and https://api.siliconflow.cn/v1 instead. The Agno adapter defaults to the China endpoint when base_url is omitted.

Usage

Set up your virtual environment

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

Set your API key

export SILICONFLOW_API_KEY=xxx

Install dependencies

uv pip install -U agno openai

Run Agent

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

python basic.py