BaseStreamEvent#
- class langchain_core.runnables.schema.BaseStreamEvent[source]#
Streaming event.
Schema of a streaming event which is produced from the astream_events method.
Example
from langchain_core.runnables import RunnableLambda async def reverse(s: str) -> str: return s[::-1] chain = RunnableLambda(func=reverse) events = [event async for event in chain.astream_events("hello")] # will produce the following events # (where some fields have been omitted for brevity): [ { "data": {"input": "hello"}, "event": "on_chain_start", "metadata": {}, "name": "reverse", "tags": [], }, { "data": {"chunk": "olleh"}, "event": "on_chain_stream", "metadata": {}, "name": "reverse", "tags": [], }, { "data": {"output": "olleh"}, "event": "on_chain_end", "metadata": {}, "name": "reverse", "tags": [], }, ]
- event: str#
on_[runnable_type]_(start|stream|end).
Runnable types are one of:
llm - used by non chat models
chat_model - used by chat models
prompt – e.g., ChatPromptTemplate
- tool – from tools defined via @tool decorator or inheriting
from Tool/BaseTool
chain - most Runnables are of this type
Further, the events are categorized as one of:
start - when the Runnable starts
stream - when the Runnable is streaming
**end* - when the Runnable ends
start, stream and end are associated with slightly different data payload.
Please see the documentation for EventData for more details.
- Type:
Event names are of the format
- run_id: str#
An randomly generated ID to keep track of the execution of the given Runnable.
Each child Runnable that gets invoked as part of the execution of a parent Runnable is assigned its own unique ID.
- tags: NotRequired[list[str]]#
Tags associated with the Runnable that generated this event.
Tags are always inherited from parent Runnables.
Tags can either be bound to a Runnable using .with_config({“tags”: [“hello”]}) or passed at run time using .astream_events(…, {“tags”: [“hello”]}).
- metadata: NotRequired[dict[str, Any]]#
Metadata associated with the Runnable that generated this event.
Metadata can either be bound to a Runnable using
.with_config({“metadata”: { “foo”: “bar” }})
or passed at run time using
.astream_events(…, {“metadata”: {“foo”: “bar”}}).
- parent_ids: Sequence[str]#
A list of the parent IDs associated with this event.
Root Events will have an empty list.
For example, if a Runnable A calls Runnable B, then the event generated by Runnable B will have Runnable A’s ID in the parent_ids field.
The order of the parent IDs is from the root parent to the immediate parent.
Only supported as of v2 of the astream events API. v1 will return an empty list.