BaseStreamEvent Class — langchain Architecture
Architecture documentation for the BaseStreamEvent class in schema.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD c60b06a0_9f02_2896_e0fd_9bacf9546931["BaseStreamEvent"] 8fc54027_af2e_acf9_1479_472ebaa69eb5["schema.py"] c60b06a0_9f02_2896_e0fd_9bacf9546931 -->|defined in| 8fc54027_af2e_acf9_1479_472ebaa69eb5
Relationship Graph
Source Code
libs/core/langchain_core/runnables/schema.py lines 56–161
class BaseStreamEvent(TypedDict):
"""Streaming event.
Schema of a streaming event which is produced from the `astream_events` method.
Example:
```python
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
"""Event names are of the format: `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 `Runnable` objects 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.
"""
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 `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"]})`.
Defined In
Source
Frequently Asked Questions
What is the BaseStreamEvent class?
BaseStreamEvent is a class in the langchain codebase, defined in libs/core/langchain_core/runnables/schema.py.
Where is BaseStreamEvent defined?
BaseStreamEvent is defined in libs/core/langchain_core/runnables/schema.py at line 56.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free