Vertex AI Basic Reasoning Stream

Stream Gemini 2.5 Flash reasoning on Vertex AI with a fixed 1,024-token thinking budget and thought summaries.

basic_reasoning_stream.py
"""
Basic Reasoning Stream
======================

Demonstrates this reasoning cookbook example.
"""

import asyncio

from agno.agent import Agent
from agno.models.google import Gemini
from agno.run.agent import RunEvent  # noqa


# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------
def run_example() -> None:
    async def streaming_reasoning():
        """Test streaming reasoning with a VertexAI with Gemini model."""
        # Create an agent with reasoning enabled
        agent = Agent(
            reasoning_model=Gemini(
                id="gemini-2.5-flash",
                vertexai=True,
                thinking_budget=1024,  # Required to enable thinking mode
                include_thoughts=True,  # Include thought summaries in response
            ),
            instructions="Think step by step about the problem.",
        )

        prompt = "What is 25 * 37? Show your reasoning."

        await agent.aprint_response(prompt, stream=True, stream_events=True)

        # Use manual event loop to see all events
        # async for run_output_event in agent.arun(
        #     prompt,
        #     stream=True,
        #     stream_events=True,
        # ):
        #     if run_output_event.event == RunEvent.run_started:
        #         print(f"\nEVENT: {run_output_event.event}")

        #     elif run_output_event.event == RunEvent.reasoning_started:
        #         print(f"\nEVENT: {run_output_event.event}")
        #         print("Reasoning started...\n")

        #     elif run_output_event.event == RunEvent.reasoning_content_delta:
        #         # This is the NEW streaming event for reasoning content
        #         print(run_output_event.reasoning_content, end="", flush=True)

        #     elif run_output_event.event == RunEvent.reasoning_step:
        #         print(f"\nEVENT: {run_output_event.event}")

        #     elif run_output_event.event == RunEvent.reasoning_completed:
        #         print(f"\n\nEVENT: {run_output_event.event}")

        #     elif run_output_event.event == RunEvent.run_content:
        #         if run_output_event.content:
        #             print(run_output_event.content, end="", flush=True)

        #     elif run_output_event.event == RunEvent.run_completed:
        #         print(f"\n\nEVENT: {run_output_event.event}")

    if __name__ == "__main__":
        asyncio.run(streaming_reasoning())


# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    run_example()

Before authenticating, choose a Google Cloud project with billing enabled, enable the Vertex AI API, and grant the calling identity the required Vertex AI permissions (for example, roles/aiplatform.user). Select a location where the model is available. Application Default Credentials select an identity; login alone does not provision the project or grant access. Follow the Google project setup.

Google lists this hosted gemini-2.5-flash version for retirement on October 20, 2026. Check the hosted model lifecycle before migrating. The 1,024-token setting controls the thinking budget; this model supports dynamic thinking without an explicit budget. include_thoughts=True requests summaries, not the complete internal trace.

The program omits the final model, so the answer uses Agno's default OpenAI model and still needs the separate OPENAI_API_KEY.

Run the Example

Set up your virtual environment

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

Install dependencies

uv pip install -U agno google-genai openai

Export environment variables

export GOOGLE_CLOUD_LOCATION="your_google_cloud_location_here"
export GOOGLE_CLOUD_PROJECT="your_google_cloud_project_here"
export OPENAI_API_KEY="your_openai_api_key_here"

Authenticate with Google Cloud

Install the Google Cloud CLI, then sign in with Application Default Credentials:

gcloud auth application-default login

Run the example

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

python basic_reasoning_stream.py

Full source: cookbook/10_reasoning/models/vertex_ai/basic_reasoning_stream.py