on_stream_event(
self,
event: MessagesData,
*,
run_id: UUID,
parent_run_id: UUID Run on each protocol event produced by stream_v2 / astream_v2.
Fires once per MessagesData event — message-start, per-block
content-block-start / content-block-delta /
content-block-finish, and message-finish. Analogous to
on_llm_new_token in v1 streaming, but at event granularity rather
than chunk: a single chunk can map to multiple events (e.g. a
content-block-start plus its first content-block-delta), and
lifecycle boundaries are explicit.
Fires uniformly whether the provider emits events natively via
_stream_chat_model_events or goes through the chunk-to-event
compat bridge. Observers see the same event stream regardless of
how the underlying model produces output.
Not fired from v1 stream() / astream(); for those, keep using
on_llm_new_token. Purely additive — on_chat_model_start,
on_llm_end, and on_llm_error still fire around a v2 call as
they do around a v1 call.
The tags.
Additional keyword arguments.