The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
refactor(core): Use duck typing for `_StreamingCallbackHandler` (#32535)
William FHb470c79f1d30
diff --git a/libs/core/langchain_core/tracers/_streaming.py b/libs/core/langchain_core/tracers/_streaming.pyindex ca50213d88..7ac1eb7c05 100644--- a/libs/core/langchain_core/tracers/_streaming.py+++ b/libs/core/langchain_core/tracers/_streaming.py@@ -1,15 +1,16 @@"""Internal tracers used for stream_log and astream events implementations."""-import abc+import typingfrom collections.abc import AsyncIterator, Iterator-from typing import TypeVarfrom uuid import UUID-T = TypeVar("T")+T = typing.TypeVar("T")-class _StreamingCallbackHandler(abc.ABC):- """For internal use.+# THIS IS USED IN LANGGRAPH.[email protected]_checkable+class _StreamingCallbackHandler(typing.Protocol[T]):+ """Types for streaming callback handlers.This is a common mixin that the callback handlersfor both astream events and astream log inherit from.@@ -18,13 +19,11 @@ class _StreamingCallbackHandler(abc.ABC):to produce callbacks for intermediate results."""- @abc.abstractmethoddef tap_output_aiter(self, run_id: UUID, output: AsyncIterator[T]) -> AsyncIterator[T]:"""Used for internal astream_log and astream events implementations."""- @abc.abstractmethoddef tap_output_iter(self, run_id: UUID, output: Iterator[T]) -> Iterator[T]:"""Used for internal astream_log and astream events implementations."""