|
|
Testing ADK Agent Streaming Responses
Author: Venkata Sudhakar
ShopMax India uses ADK streaming responses to show customers a live typing effect as the agent generates order status updates and product recommendations, reducing perceived wait time. Testing streaming agents requires verifying that chunks arrive in order, that the concatenated stream equals the expected full response, that the first chunk arrives within an acceptable latency, and that the stream closes cleanly without partial or duplicate tokens.
To test ADK agent streaming, replace the LLM with an async generator mock that yields a fixed sequence of chunks. Collect all chunks, assert on their order and content, and verify the assembled response matches the expected final text. Test edge cases: a single-chunk stream, an empty stream, and a stream that raises an error mid-way. These tests run fast and deterministically without real LLM calls.
The example below mocks a streaming ADK agent for ShopMax India that yields order status in three chunks. Tests verify chunk order, the assembled response, and a mid-stream error path where the consumer receives all chunks delivered before the error.
It gives the following output,
... (3 passed in 0.02s)
In production, ShopMax India should set a maximum stream duration and a maximum total token count per stream to prevent the agent from generating indefinitely long responses. Buffer chunks on the client side and flush to the UI every 50ms to balance responsiveness against render overhead. Monitor first-chunk latency as a separate metric from total response latency, since customers perceive the stream as starting as soon as the first token arrives.
|
|