|
|
ADK Streaming Responses
Author: Venkata Sudhakar
By default, ADK agents return a complete response only after the model finishes generating the full output. For long responses - detailed reports, multi-step analyses, or verbose explanations - this creates a noticeable wait. Streaming solves this by delivering tokens to the client as they are produced, so users see text appearing in real time rather than waiting for a single large block.
ShopMax India customer service agents sometimes generate lengthy responses for product comparisons, warranty explanations, and order summaries. Enabling streaming in these agents makes the interface feel significantly faster and more interactive, even when the total generation time is the same.
The below example shows how to run an ADK agent in streaming mode and print tokens as they arrive for a ShopMax India product comparison query.
It gives the following output,
Customer: Compare Samsung Galaxy S24 and iPhone 15 Pro for a business user in India.
Agent: [tokens stream in real time as generated]
Samsung Galaxy S24 vs iPhone 15 Pro - ShopMax India Business Comparison
Price (ShopMax India):
Samsung Galaxy S24 - Rs 74,999
iPhone 15 Pro 128GB - Rs 1,29,900
Battery:
Galaxy S24: 4000mAh, 25W wired - good all-day usage
iPhone 15 Pro: 3274mAh, 27W - optimised by iOS, similar real-world endurance
Camera:
Galaxy S24: 50MP main, excellent low-light, versatile zoom
iPhone 15 Pro: 48MP main, ProRAW, superior video for content creators
Recommendation for business users:
Galaxy S24 offers better value at nearly half the price with strong
Android productivity features. Choose iPhone 15 Pro if your team
is already in the Apple ecosystem.
The below example shows how to build a simple FastAPI streaming endpoint that delivers ADK agent output as Server-Sent Events to a web frontend for ShopMax India.
It gives the following output,
ShopMax streaming chat API ready on port 8000
INFO: Uvicorn running on http://0.0.0.0:8000
# Browser SSE output (GET /chat?query=Compare+Galaxy+S24+vs+iPhone+15+Pro)
data: Samsung
data: Galaxy
data: S24
data: vs
data: iPhone
data: 15
data: Pro...
[tokens delivered as SSE events in real time]
data: [DONE]
Streaming transforms the ShopMax India customer experience for complex queries. Users see the agent thinking and responding in real time rather than staring at a blank screen. The FastAPI SSE pattern integrates directly with React or Vue frontends using the browser EventSource API, making it straightforward to add streaming to any existing ShopMax web application.
|
|