diff --git a/langchain/callbacks/base.py b/langchain/callbacks/base.py index 69ba0f1a7c..d9f63b73ee 100644 --- a/langchain/callbacks/base.py +++ b/langchain/callbacks/base.py @@ -1,7 +1,6 @@ """Base callback handler that can be used to handle callbacks in langchain.""" from __future__ import annotations -import copy from typing import Any, Dict, List, Optional, Union from uuid import UUID @@ -367,15 +366,3 @@ class BaseCallbackManager(CallbackManagerMixin): def set_handler(self, handler: BaseCallbackHandler, inherit: bool = True) -> None: """Set handler as the only handler on the callback manager.""" self.set_handlers([handler], inherit=inherit) - - def __copy__(self) -> "BaseCallbackManager": - return self.__class__( - self.handlers.copy(), self.inheritable_handlers.copy(), self.parent_run_id - ) - - def __deepcopy__(self, memo: dict) -> "BaseCallbackManager": - return self.__class__( - [copy.deepcopy(handler, memo) for handler in self.handlers], - [copy.deepcopy(handler, memo) for handler in self.inheritable_handlers], - self.parent_run_id, - ) diff --git a/langchain/callbacks/manager.py b/langchain/callbacks/manager.py index 2a2e7b6e5e..f67298856d 100644 --- a/langchain/callbacks/manager.py +++ b/langchain/callbacks/manager.py @@ -1,7 +1,6 @@ from __future__ import annotations import asyncio -import copy import functools import os import warnings @@ -700,8 +699,8 @@ def _configure( if isinstance(inheritable_callbacks, list) or inheritable_callbacks is None: inheritable_callbacks_ = inheritable_callbacks or [] callback_manager = callback_manager_cls( - handlers=inheritable_callbacks_, - inheritable_handlers=inheritable_callbacks_, + handlers=inheritable_callbacks_.copy(), + inheritable_handlers=inheritable_callbacks_.copy(), ) else: callback_manager = callback_manager_cls( @@ -709,14 +708,13 @@ def _configure( inheritable_handlers=inheritable_callbacks.inheritable_handlers, parent_run_id=inheritable_callbacks.parent_run_id, ) - callback_manager = copy.deepcopy(callback_manager) local_handlers_ = ( local_callbacks if isinstance(local_callbacks, list) else (local_callbacks.handlers if local_callbacks else []) ) for handler in local_handlers_: - callback_manager.add_handler(copy.deepcopy(handler), False) + callback_manager.add_handler(handler, False) tracer = tracing_callback_var.get() open_ai = openai_callback_var.get() @@ -734,7 +732,6 @@ def _configure( for handler in callback_manager.handlers ): callback_manager.add_handler(StdOutCallbackHandler(), False) - if tracing_enabled_ and not any( isinstance(handler, LangChainTracer) for handler in callback_manager.handlers @@ -750,5 +747,4 @@ def _configure( for handler in callback_manager.handlers ): callback_manager.add_handler(open_ai, True) - return callback_manager