live_search_agent_stream.py
Run the Example
1
Set up your virtual environment
2
Install dependencies
3
Export your xAI API key
4
Run the example
Save the code above as
live_search_agent_stream.py, then run:Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Stream a world news digest from Grok using xAI Live Search with citations.
"""
Xai Live Search Agent Stream
============================
Cookbook example for `xai/live_search_agent_stream.py`.
"""
from agno.agent import Agent
from agno.models.xai.xai import xAI
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=xAI(
id="grok-3",
search_parameters={
"mode": "on",
"max_search_results": 20,
"return_citations": True,
},
),
markdown=True,
)
agent.print_response(
"Provide me a digest of world news in the last 24 hours.", stream=True
)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
pass
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
Install dependencies
uv pip install -U agno openai
Export your xAI API key
export XAI_API_KEY="your_xai_api_key_here"
$Env:XAI_API_KEY="your_xai_api_key_here"
Run the example
live_search_agent_stream.py, then run:python live_search_agent_stream.py
Was this page helpful?