Streaming event.
Schema of a streaming event which is produced from the astream_events method.
BaseStreamEvent()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 names are of the format: on_[runnable_type]_(start|stream|end).
Runnable types are one of:
ChatPromptTemplate@tool decorator or inheriting
from Tool/BaseToolRunnable objects are of this typeFurther, the events are categorized as one of:
Runnable startsRunnable is streamingRunnable endsstart, stream and end are associated with slightly different data payload.
Please see the documentation for EventData for more details.
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 associated with the Runnable that generated this event.
Tags are always inherited from parent Runnable objects.
Tags can either be bound to a Runnable using .with_config({"tags": ["hello"]})
or passed at run time using .astream_events(..., {"tags": ["hello"]}).
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"}})`.
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.