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.

live_search_agent_stream.py
"""
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

Current 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.

live_search_agent_stream.py
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/activate

Install dependencies

uv pip install -U agno openai

Export 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.py

Full source: cookbook/90_models/xai/live_search_agent_stream.py