diff --git a/libs/langchain/langchain/memory/combined.py b/libs/langchain/langchain/memory/combined.py index 1c46c184d4..80316755ae 100644 --- a/libs/langchain/langchain/memory/combined.py +++ b/libs/langchain/langchain/memory/combined.py @@ -61,10 +61,12 @@ class CombinedMemory(BaseMemory): # Collect vars from all sub-memories for memory in self.memories: data = memory.load_memory_variables(inputs) - memory_data = { - **memory_data, - **data, - } + for key, value in data.items(): + if key in memory_data: + raise ValueError( + f"The variable {key} is repeated in the CombinedMemory." + ) + memory_data[key] = value return memory_data