mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-12 20:57:52 +02:00
62 lines
1.4 KiB
Python
62 lines
1.4 KiB
Python
from abc import ABC, abstractmethod
|
|
from contextlib import asynccontextmanager, contextmanager
|
|
from typing import (
|
|
Any,
|
|
AsyncGenerator,
|
|
Generator,
|
|
Generic,
|
|
Optional,
|
|
Sequence,
|
|
TypeVar,
|
|
)
|
|
|
|
from typing_extensions import Self
|
|
|
|
Value = TypeVar("Value")
|
|
Update = TypeVar("Update")
|
|
|
|
|
|
class EmptyChannelError(Exception):
|
|
pass
|
|
|
|
|
|
class InvalidUpdateError(Exception):
|
|
pass
|
|
|
|
|
|
class Channel(Generic[Value, Update], ABC):
|
|
@property
|
|
@abstractmethod
|
|
def ValueType(self) -> Any:
|
|
"""The type of the value stored in the channel."""
|
|
|
|
@property
|
|
@abstractmethod
|
|
def UpdateType(self) -> Any:
|
|
"""The type of the update received by the channel."""
|
|
|
|
@contextmanager
|
|
@abstractmethod
|
|
def empty(self, checkpoint: Optional[str] = None) -> Generator[Self, None, None]:
|
|
"""Return a new identical channel, optionally initialized from a checkpoint."""
|
|
|
|
@asynccontextmanager
|
|
async def aempty(
|
|
self, checkpoint: Optional[str] = None
|
|
) -> AsyncGenerator[Self, None]:
|
|
"""Return a new identical channel, optionally initialized from a checkpoint."""
|
|
with self.empty(checkpoint) as value:
|
|
yield value
|
|
|
|
@abstractmethod
|
|
def update(self, values: Sequence[Update]) -> None:
|
|
...
|
|
|
|
@abstractmethod
|
|
def get(self) -> Value:
|
|
...
|
|
|
|
@abstractmethod
|
|
def checkpoint(self) -> str | None:
|
|
...
|