Basic Stream
Stream a synchronous Agno agent's response from a local Ollama llama3.1:8b model with stream=True.
Code
from typing import Iterator # noqa
from agno.agent import Agent, RunOutputEvent # noqa
from agno.models.ollama import Ollama
agent = Agent(model=Ollama(host="http://localhost:11434", api_key=None, id="llama3.1:8b"), 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)
Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateStart the local Ollama service
Install Ollama and start its desktop app or service on http://localhost:11434. If you start it manually with ollama serve, keep that process running in a separate terminal.
In the terminal where you will pull models and run Python, select that server and clear the direct-cloud key. The native Ollama client also reads this key independently of Agno.
export OLLAMA_HOST=http://localhost:11434
unset OLLAMA_API_KEYPull the model
ollama pull llama3.1:8bInstall dependencies
uv pip install -U ollama agnoRun Agent
Save the code above as basic.py, then run:
python basic.pyCloud Alternative
For easier setup without local installation, use Ollama Cloud with your API key:
from agno.agent import Agent
from agno.models.ollama import Ollama
# No local setup required - just set OLLAMA_API_KEY
agent = Agent(model=Ollama(id="gpt-oss:120b"))
agent.print_response("Share a 2 sentence horror story", stream=True)