From 5c73fd5bbae4fd79cdfbee6b9276e163f8aa9d2d Mon Sep 17 00:00:00 2001
From: Bagatur <22008038+baskaryan@users.noreply.github.com>
Date: Wed, 17 Jan 2024 11:26:25 -0800
Subject: [PATCH] core[patch]: support old core namespaces (#16155)

---
 libs/core/langchain_core/load/load.py    |   4 +-
 libs/core/langchain_core/load/mapping.py | 337 ++++++++++++++++++-----
 libs/core/pyproject.toml                 |   2 +-
 3 files changed, 270 insertions(+), 73 deletions(-)

diff --git a/libs/core/langchain_core/load/load.py b/libs/core/langchain_core/load/load.py
index dbf0f2c77d94e..f10e1cb680227 100644
--- a/libs/core/langchain_core/load/load.py
+++ b/libs/core/langchain_core/load/load.py
@@ -6,7 +6,7 @@
 from langchain_core._api import beta
 from langchain_core.load.mapping import (
     _OG_SERIALIZABLE_MAPPING,
-    OLD_PROMPT_TEMPLATE_FORMATS,
+    OLD_CORE_NAMESPACES_MAPPING,
     SERIALIZABLE_MAPPING,
 )
 from langchain_core.load.serializable import Serializable
@@ -15,7 +15,7 @@
 
 ALL_SERIALIZABLE_MAPPINGS = {
     **SERIALIZABLE_MAPPING,
-    **OLD_PROMPT_TEMPLATE_FORMATS,
+    **OLD_CORE_NAMESPACES_MAPPING,
     **_OG_SERIALIZABLE_MAPPING,
 }
 
diff --git a/libs/core/langchain_core/load/mapping.py b/libs/core/langchain_core/load/mapping.py
index 755428c363ffb..7ac3c7d3e3858 100644
--- a/libs/core/langchain_core/load/mapping.py
+++ b/libs/core/langchain_core/load/mapping.py
@@ -513,102 +513,239 @@
 }
 
 # Needed for backwards compatibility for a few versions where we serialized
-# with langchain_core
-OLD_PROMPT_TEMPLATE_FORMATS: Dict[Tuple[str, ...], Tuple[str, ...]] = {
-    (
+# with langchain_core paths.
+OLD_CORE_NAMESPACES_MAPPING: Dict[Tuple[str, ...], Tuple[str, ...]] = {
+    ("langchain_core", "messages", "ai", "AIMessage"): (
         "langchain_core",
-        "prompts",
+        "messages",
+        "ai",
+        "AIMessage",
+    ),
+    ("langchain_core", "messages", "ai", "AIMessageChunk"): (
+        "langchain_core",
+        "messages",
+        "ai",
+        "AIMessageChunk",
+    ),
+    ("langchain_core", "messages", "base", "BaseMessage"): (
+        "langchain_core",
+        "messages",
         "base",
-        "BasePromptTemplate",
-    ): (
+        "BaseMessage",
+    ),
+    ("langchain_core", "messages", "base", "BaseMessageChunk"): (
         "langchain_core",
-        "prompts",
+        "messages",
         "base",
-        "BasePromptTemplate",
+        "BaseMessageChunk",
     ),
-    (
+    ("langchain_core", "messages", "chat", "ChatMessage"): (
+        "langchain_core",
+        "messages",
+        "chat",
+        "ChatMessage",
+    ),
+    ("langchain_core", "messages", "function", "FunctionMessage"): (
+        "langchain_core",
+        "messages",
+        "function",
+        "FunctionMessage",
+    ),
+    ("langchain_core", "messages", "human", "HumanMessage"): (
+        "langchain_core",
+        "messages",
+        "human",
+        "HumanMessage",
+    ),
+    ("langchain_core", "messages", "system", "SystemMessage"): (
+        "langchain_core",
+        "messages",
+        "system",
+        "SystemMessage",
+    ),
+    ("langchain_core", "messages", "tool", "ToolMessage"): (
+        "langchain_core",
+        "messages",
+        "tool",
+        "ToolMessage",
+    ),
+    ("langchain_core", "agents", "AgentAction"): (
+        "langchain_core",
+        "agents",
+        "AgentAction",
+    ),
+    ("langchain_core", "agents", "AgentFinish"): (
+        "langchain_core",
+        "agents",
+        "AgentFinish",
+    ),
+    ("langchain_core", "prompts", "base", "BasePromptTemplate"): (
         "langchain_core",
         "prompts",
-        "prompt",
-        "PromptTemplate",
-    ): (
+        "base",
+        "BasePromptTemplate",
+    ),
+    ("langchain_core", "prompts", "prompt", "PromptTemplate"): (
         "langchain_core",
         "prompts",
         "prompt",
         "PromptTemplate",
     ),
-    (
-        "langchain_core",
-        "prompts",
-        "chat",
-        "MessagesPlaceholder",
-    ): (
+    ("langchain_core", "prompts", "chat", "MessagesPlaceholder"): (
         "langchain_core",
         "prompts",
         "chat",
         "MessagesPlaceholder",
     ),
-    (
-        "langchain_core",
-        "prompts",
-        "chat",
-        "ChatPromptTemplate",
-    ): (
+    ("langchain_core", "prompts", "chat", "ChatPromptTemplate"): (
         "langchain_core",
         "prompts",
         "chat",
         "ChatPromptTemplate",
     ),
-    (
-        "langchain_core",
-        "prompts",
-        "chat",
-        "HumanMessagePromptTemplate",
-    ): (
+    ("langchain_core", "prompts", "chat", "HumanMessagePromptTemplate"): (
         "langchain_core",
         "prompts",
         "chat",
         "HumanMessagePromptTemplate",
     ),
-    (
+    ("langchain_core", "prompts", "chat", "SystemMessagePromptTemplate"): (
         "langchain_core",
         "prompts",
         "chat",
         "SystemMessagePromptTemplate",
-    ): (
+    ),
+    ("langchain_core", "agents", "AgentActionMessageLog"): (
         "langchain_core",
-        "prompts",
-        "chat",
-        "SystemMessagePromptTemplate",
+        "agents",
+        "AgentActionMessageLog",
     ),
-    (
+    ("langchain_core", "prompts", "chat", "BaseMessagePromptTemplate"): (
         "langchain_core",
         "prompts",
         "chat",
         "BaseMessagePromptTemplate",
-    ): (
+    ),
+    ("langchain_core", "outputs", "chat_generation", "ChatGeneration"): (
         "langchain_core",
-        "prompts",
-        "chat",
-        "BaseMessagePromptTemplate",
+        "outputs",
+        "chat_generation",
+        "ChatGeneration",
     ),
-    (
+    ("langchain_core", "outputs", "generation", "Generation"): (
+        "langchain_core",
+        "outputs",
+        "generation",
+        "Generation",
+    ),
+    ("langchain_core", "documents", "base", "Document"): (
+        "langchain_core",
+        "documents",
+        "base",
+        "Document",
+    ),
+    ("langchain_core", "prompts", "chat", "AIMessagePromptTemplate"): (
         "langchain_core",
         "prompts",
         "chat",
-        "BaseChatPromptTemplate",
-    ): (
+        "AIMessagePromptTemplate",
+    ),
+    ("langchain_core", "runnables", "configurable", "DynamicRunnable"): (
         "langchain_core",
-        "prompts",
+        "runnables",
+        "configurable",
+        "DynamicRunnable",
+    ),
+    ("langchain_core", "prompt_values", "PromptValue"): (
+        "langchain_core",
+        "prompt_values",
+        "PromptValue",
+    ),
+    ("langchain_core", "runnables", "base", "RunnableBinding"): (
+        "langchain_core",
+        "runnables",
+        "base",
+        "RunnableBinding",
+    ),
+    ("langchain_core", "runnables", "branch", "RunnableBranch"): (
+        "langchain_core",
+        "runnables",
+        "branch",
+        "RunnableBranch",
+    ),
+    ("langchain_core", "runnables", "fallbacks", "RunnableWithFallbacks"): (
+        "langchain_core",
+        "runnables",
+        "fallbacks",
+        "RunnableWithFallbacks",
+    ),
+    ("langchain_core", "output_parsers", "string", "StrOutputParser"): (
+        "langchain_core",
+        "output_parsers",
+        "string",
+        "StrOutputParser",
+    ),
+    ("langchain_core", "output_parsers", "list", "CommaSeparatedListOutputParser"): (
+        "langchain_core",
+        "output_parsers",
+        "list",
+        "CommaSeparatedListOutputParser",
+    ),
+    ("langchain_core", "runnables", "base", "RunnableParallel"): (
+        "langchain_core",
+        "runnables",
+        "base",
+        "RunnableParallel",
+    ),
+    ("langchain_core", "outputs", "chat_generation", "ChatGenerationChunk"): (
+        "langchain_core",
+        "outputs",
+        "chat_generation",
+        "ChatGenerationChunk",
+    ),
+    ("langchain_core", "messages", "chat", "ChatMessageChunk"): (
+        "langchain_core",
+        "messages",
         "chat",
-        "BaseChatPromptTemplate",
+        "ChatMessageChunk",
     ),
-    (
+    ("langchain_core", "messages", "human", "HumanMessageChunk"): (
+        "langchain_core",
+        "messages",
+        "human",
+        "HumanMessageChunk",
+    ),
+    ("langchain_core", "messages", "function", "FunctionMessageChunk"): (
+        "langchain_core",
+        "messages",
+        "function",
+        "FunctionMessageChunk",
+    ),
+    ("langchain_core", "messages", "system", "SystemMessageChunk"): (
+        "langchain_core",
+        "messages",
+        "system",
+        "SystemMessageChunk",
+    ),
+    ("langchain_core", "messages", "tool", "ToolMessageChunk"): (
+        "langchain_core",
+        "messages",
+        "tool",
+        "ToolMessageChunk",
+    ),
+    ("langchain_core", "outputs", "generation", "GenerationChunk"): (
+        "langchain_core",
+        "outputs",
+        "generation",
+        "GenerationChunk",
+    ),
+    ("langchain_core", "prompts", "chat", "BaseChatPromptTemplate"): (
         "langchain_core",
         "prompts",
         "chat",
-        "ChatMessagePromptTemplate",
-    ): (
+        "BaseChatPromptTemplate",
+    ),
+    ("langchain_core", "prompts", "chat", "ChatMessagePromptTemplate"): (
         "langchain_core",
         "prompts",
         "chat",
@@ -625,48 +762,108 @@
         "few_shot_with_templates",
         "FewShotPromptWithTemplates",
     ),
-    (
-        "langchain_core",
-        "prompts",
-        "pipeline",
-        "PipelinePromptTemplate",
-    ): (
+    ("langchain_core", "prompts", "pipeline", "PipelinePromptTemplate"): (
         "langchain_core",
         "prompts",
         "pipeline",
         "PipelinePromptTemplate",
     ),
-    (
+    ("langchain_core", "prompts", "string", "StringPromptTemplate"): (
         "langchain_core",
         "prompts",
         "string",
         "StringPromptTemplate",
-    ): (
+    ),
+    ("langchain_core", "prompt_values", "StringPromptValue"): (
         "langchain_core",
-        "prompts",
-        "string",
-        "StringPromptTemplate",
+        "prompt_values",
+        "StringPromptValue",
     ),
-    (
+    ("langchain_core", "prompts", "chat", "BaseStringMessagePromptTemplate"): (
         "langchain_core",
         "prompts",
         "chat",
         "BaseStringMessagePromptTemplate",
-    ): (
+    ),
+    ("langchain_core", "prompt_values", "ChatPromptValue"): (
         "langchain_core",
-        "prompts",
-        "chat",
-        "BaseStringMessagePromptTemplate",
+        "prompt_values",
+        "ChatPromptValue",
+    ),
+    ("langchain_core", "prompt_values", "ChatPromptValueConcrete"): (
+        "langchain_core",
+        "prompt_values",
+        "ChatPromptValueConcrete",
+    ),
+    ("langchain_core", "runnables", "base", "RunnableBindingBase"): (
+        "langchain_core",
+        "runnables",
+        "base",
+        "RunnableBindingBase",
+    ),
+    ("langchain_core", "runnables", "router", "RouterRunnable"): (
+        "langchain_core",
+        "runnables",
+        "router",
+        "RouterRunnable",
+    ),
+    ("langchain_core", "runnables", "passthrough", "RunnablePassthrough"): (
+        "langchain_core",
+        "runnables",
+        "passthrough",
+        "RunnablePassthrough",
+    ),
+    ("langchain_core", "runnables", "base", "RunnableSequence"): (
+        "langchain_core",
+        "runnables",
+        "base",
+        "RunnableSequence",
+    ),
+    ("langchain_core", "runnables", "base", "RunnableEach"): (
+        "langchain_core",
+        "runnables",
+        "base",
+        "RunnableEach",
+    ),
+    ("langchain_core", "runnables", "base", "RunnableEachBase"): (
+        "langchain_core",
+        "runnables",
+        "base",
+        "RunnableEachBase",
     ),
     (
         "langchain_core",
-        "prompts",
-        "chat",
-        "AIMessagePromptTemplate",
+        "runnables",
+        "configurable",
+        "RunnableConfigurableAlternatives",
     ): (
         "langchain_core",
-        "prompts",
-        "chat",
-        "AIMessagePromptTemplate",
+        "runnables",
+        "configurable",
+        "RunnableConfigurableAlternatives",
+    ),
+    ("langchain_core", "runnables", "configurable", "RunnableConfigurableFields"): (
+        "langchain_core",
+        "runnables",
+        "configurable",
+        "RunnableConfigurableFields",
+    ),
+    ("langchain_core", "runnables", "history", "RunnableWithMessageHistory"): (
+        "langchain_core",
+        "runnables",
+        "history",
+        "RunnableWithMessageHistory",
+    ),
+    ("langchain_core", "runnables", "passthrough", "RunnableAssign"): (
+        "langchain_core",
+        "runnables",
+        "passthrough",
+        "RunnableAssign",
+    ),
+    ("langchain_core", "runnables", "retry", "RunnableRetry"): (
+        "langchain_core",
+        "runnables",
+        "retry",
+        "RunnableRetry",
     ),
 }
diff --git a/libs/core/pyproject.toml b/libs/core/pyproject.toml
index caed8502ee1bc..72b7db2bf7584 100644
--- a/libs/core/pyproject.toml
+++ b/libs/core/pyproject.toml
@@ -1,6 +1,6 @@
 [tool.poetry]
 name = "langchain-core"
-version = "0.1.11"
+version = "0.1.12-rc.1"
 description = "Building applications with LLMs through composability"
 authors = []
 license = "MIT"