xAI Live Search Agent Stream
Stream a news digest using the current xAI Responses web search tool.
The preserved source uses legacy Chat search_parameters. Use the current Responses program below for xAI web search.
"""
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__":
passCurrent Example
The model can call xAI's server-side web search tool. Citations depend on the searches and results returned by the provider. Legacy mode, max_search_results and return_citations are not copied to this API.
from agno.agent import Agent
from agno.models.xai import xAIResponses
agent = Agent(
model=xAIResponses(id="grok-4.6"),
tools=[{"type": "web_search"}],
markdown=True,
)
agent.print_response("Provide me a digest of world news in the last 24 hours.", stream=True)Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno openaiExport your xAI API key
export XAI_API_KEY="your_xai_api_key_here"Run the example
Save the Current Example as live_search_agent_stream.py, then run:
python live_search_agent_stream.pyFull source: cookbook/90_models/xai/live_search_agent_stream.py