Streaming
Streaming allows you to start displaying the agent’s response as it is being generated, rather than waiting for the entire response to be completed. This significantly reduces latency, potentially from seconds to milliseconds, enhancing the user experience.
While streaming might seem daunting, we’ve simplified the process.
Though we provide streaming hooks that work on the client-side,
this page focuses on displaying responses to users in real-time with React and how streamPlaceholder
works.
When you call newRequest
and send a message, like this:
Instead of waiting for the entire agent response, you can start displaying it as soon as the first token is received.
The messages
property contains all the completed messages in the session and does not
include the ongoing response. To handle this, we use streamPlaceholder
.
The streamPlaceholder
property holds the state of the response being generated,
including text, audio, and tool calls made during the run.
Once the response is finished, it’s moved to the finished messages list (under the messages
property).
Example
Here’s an example to illustrate how it works:
Was this page helpful?