Skip to main content

What this snippet demonstrates

Most chat applications need two things simultaneously: real-time streaming (so users see text as it’s generated) and memory continuity (so the agent remembers previous turns). This snippet shows how to combine run_stream() with thread_id to build a multi-turn streaming chat handler.

Full example

Key patterns

Thread ID connects turns

Pass the same thread_id across run_stream() calls to maintain conversation context:

Access the result after streaming

The handle.result is available after the stream completes:

Cancel mid-stream

If the user navigates away or clicks “stop”: