Basic Streaming Agent
Stream a Nexus agent's response with stream=True.
Code
from agno.agent import Agent
from agno.models.nexus import Nexus
agent = Agent(model=Nexus(id="anthropic/claude-sonnet-4-6"), markdown=True)
# Get the response in a variable
# run_response = 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/activateInstall dependencies
uv pip install -U agno openaiConfigure Nexus
Install Nexus, then create nexus.toml in the directory where you will start the gateway:
[server]
listen_address = "127.0.0.1:8000"
[llm]
enabled = true
[llm.protocols.openai]
enabled = true
path = "/llm"
[llm.providers.anthropic]
type = "anthropic"
api_key = "{{ env.ANTHROPIC_API_KEY }}"
[llm.providers.anthropic.models."claude-sonnet-4-6"]The Nexus model sends OpenAI-compatible requests to http://localhost:8000/llm/v1/ by default. Nexus requires every model to be declared in nexus.toml.
Start Nexus
In a dedicated server terminal, set the provider key and start the gateway from the directory that contains nexus.toml:
export ANTHROPIC_API_KEY="your-anthropic-api-key"
nexusLeave this terminal running. The provider key belongs to the Nexus process. Open a second terminal in your example directory, activate the Python virtual environment there, and run the Agno client. Exporting the key only in that client terminal does not configure the gateway.
Run Agent
In the second terminal with your virtual environment activated, save the code above as basic.py, then run:
python basic.py