Live Search Agent Stream

Stream a Grok response using native web and X search through xAIResponses.

Native web search and X search use the Responses API. Pass web_search and x_search tool dictionaries to the agent with xAIResponses; the legacy xAI.search_parameters option targets Chat Completions and does not enable these Responses tools.

Code

from agno.agent import Agent
from agno.models.xai import xAIResponses

agent = Agent(
    model=xAIResponses(id="grok-4.5"),
    tools=[{"type": "web_search"}, {"type": "x_search"}],
    markdown=True,
)
agent.print_response(
    "Provide me a digest of world news in the last 24 hours.", stream=True
)

Usage

Set up your virtual environment

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

Set your API key

export XAI_API_KEY=xxx

Install dependencies

uv pip install -U openai agno

Run Agent

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

python live_search_agent_stream.py