Streaming events
Watch work happen as server-sent events.
A streaming request answers with server-sent events: a series of small typed messages as the work happens, ending in done. Chat streams by default over HTTP; for Wave and Composer pass stream: true.
with catalyst.chat.stream("Make the footsteps louder") as stream:
for text in stream.text():
print(text, end="")
final = stream.get_final() # the same envelope a normal call returnsEvents
| Event | Meaning |
|---|---|
started | The request was accepted. |
progress | What it is doing now. |
narration, message | Text from the agent. |
plan | A proposed plan. |
sound, file | A sound or file is ready. |
tool_call | The agent asks your app to run a registered tool. |
needs_video | The agent needs a video to continue. |
usage | What the request cost. |
done | The end. error and cancelled also end a stream. |
A stream is never silently repeated. If the connection drops, resume with the request's event stream and the last event id you saw: nothing is missed or repeated. Break out of the loop (or abort) to stop reading.