LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corerunnablesschemaBaseStreamEvent
    Class●Since v0.2

    BaseStreamEvent

    Streaming event.

    Schema of a streaming event which is produced from the astream_events method.

    Copy
    BaseStreamEvent()

    Bases

    TypedDict

    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": [],
        },
    ]

    Constructors

    constructor
    __init__
    NameType
    eventstr
    run_idstr
    tagsNotRequired[list[str]]
    metadataNotRequired[dict[str, Any]]
    parent_idsSequence[str]

    Attributes

    attribute
    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.

    attribute
    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.

    attribute
    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"]}).

    attribute
    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"}})`.
    
    attribute
    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.

    View source on GitHub