Skip to main content
The Advanced Agent API can stream responses. This allows you to process data incrementally as it becomes available, rather than waiting for the full payload. This tutorial section describes how to make an API call enabling the stream response in Python.

Prerequisites and Requirements

To reproduce this tutorial, you need: Suppose you name your folder advanced-agent-stream-response/. At the end of this step, the folder will have the following structure:
advanced-agent-stream-response/
Where:
  • advanced-agent-stream-response.py is the Python file that contains the coding logic.
  • venv/ contains the virtual environment.
Based on your operating system, create and activate the virtual environment. In the activated environment, install the needed libraries:
The sseclient-py library allows you to manage stream responses.

Manage The Stream Response With the Advanced Agent API

To manage the stream response with the Advanced Agent API, write the following code in the advanced-agent-stream-response.py file:
advanced-agent-stream-response.py
WARNING: Based on your specific query, the agent may take up to 5 minutes to stream the entire response.
Suppose your query is Write a report about Obama. When launching the advanced-agent-stream-response.py file, the result will be similar to the following: