Home / Class/ _RootEventFilter Class — langchain Architecture

_RootEventFilter Class — langchain Architecture

Architecture documentation for the _RootEventFilter class in utils.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  faa6538b_b2d0_5c40_5455_7ff22c943215["_RootEventFilter"]
  ca66092c_447c_d201_0d3c_cfa6ca2cc9d3["utils.py"]
  faa6538b_b2d0_5c40_5455_7ff22c943215 -->|defined in| ca66092c_447c_d201_0d3c_cfa6ca2cc9d3
  40b244e3_8c75_00a5_f711_2f9525d4edf8["__init__()"]
  faa6538b_b2d0_5c40_5455_7ff22c943215 -->|method| 40b244e3_8c75_00a5_f711_2f9525d4edf8
  0f4e8ea2_eec8_9ce9_ae98_09587d1e0d68["include_event()"]
  faa6538b_b2d0_5c40_5455_7ff22c943215 -->|method| 0f4e8ea2_eec8_9ce9_ae98_09587d1e0d68

Relationship Graph

Source Code

libs/core/langchain_core/runnables/utils.py lines 673–725

class _RootEventFilter:
    def __init__(
        self,
        *,
        include_names: Sequence[str] | None = None,
        include_types: Sequence[str] | None = None,
        include_tags: Sequence[str] | None = None,
        exclude_names: Sequence[str] | None = None,
        exclude_types: Sequence[str] | None = None,
        exclude_tags: Sequence[str] | None = None,
    ) -> None:
        """Utility to filter the root event in the astream_events implementation.

        This is simply binding the arguments to the namespace to make save on
        a bit of typing in the astream_events implementation.
        """
        self.include_names = include_names
        self.include_types = include_types
        self.include_tags = include_tags
        self.exclude_names = exclude_names
        self.exclude_types = exclude_types
        self.exclude_tags = exclude_tags

    def include_event(self, event: StreamEvent, root_type: str) -> bool:
        """Determine whether to include an event."""
        if (
            self.include_names is None
            and self.include_types is None
            and self.include_tags is None
        ):
            include = True
        else:
            include = False

        event_tags = event.get("tags") or []

        if self.include_names is not None:
            include = include or event["name"] in self.include_names
        if self.include_types is not None:
            include = include or root_type in self.include_types
        if self.include_tags is not None:
            include = include or any(tag in self.include_tags for tag in event_tags)

        if self.exclude_names is not None:
            include = include and event["name"] not in self.exclude_names
        if self.exclude_types is not None:
            include = include and root_type not in self.exclude_types
        if self.exclude_tags is not None:
            include = include and all(
                tag not in self.exclude_tags for tag in event_tags
            )

        return include

Frequently Asked Questions

What is the _RootEventFilter class?
_RootEventFilter is a class in the langchain codebase, defined in libs/core/langchain_core/runnables/utils.py.
Where is _RootEventFilter defined?
_RootEventFilter is defined in libs/core/langchain_core/runnables/utils.py at line 673.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free