Skip to content

Commit

Permalink
langchain[patch]: update deprecation message for agent classes and co…
Browse files Browse the repository at this point in the history
…nstructors (#28369)
  • Loading branch information
ccurme authored Nov 26, 2024
1 parent ec205fc commit 8adc4a5
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 24 deletions.
13 changes: 13 additions & 0 deletions libs/langchain/langchain/_api/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
warn_deprecated,
)

AGENT_DEPRECATION_WARNING = (
"LangChain agents will continue to be supported, but it is recommended for new "
"use cases to be built with LangGraph. LangGraph offers a more flexible and "
"full-featured framework for building agents, including support for "
"tool-calling, persistence of state, and human-in-the-loop workflows. See "
"LangGraph documentation for more details: "
"https://langchain-ai.github.io/langgraph/. Refer here for its pre-built "
"ReAct agent: "
"https://langchain-ai.github.io/langgraph/how-tos/create-react-agent/"
)


__all__ = [
"AGENT_DEPRECATION_WARNING",
"LangChainDeprecationWarning",
"LangChainPendingDeprecationWarning",
"deprecated",
Expand Down
11 changes: 3 additions & 8 deletions libs/langchain/langchain/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from pydantic import BaseModel, ConfigDict, model_validator
from typing_extensions import Self

from langchain._api.deprecation import AGENT_DEPRECATION_WARNING
from langchain.agents.agent_iterator import AgentExecutorIterator
from langchain.agents.agent_types import AgentType
from langchain.agents.tools import InvalidTool
Expand Down Expand Up @@ -633,10 +634,7 @@ async def aplan(

@deprecated(
"0.1.0",
message=(
"Use new agent constructor methods like create_react_agent, create_json_agent, "
"create_structured_chat_agent, etc."
),
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class LLMSingleActionAgent(BaseSingleActionAgent):
Expand Down Expand Up @@ -724,10 +722,7 @@ def tool_run_logging_kwargs(self) -> Dict:

@deprecated(
"0.1.0",
message=(
"Use new agent constructor methods like create_react_agent, create_json_agent, "
"create_structured_chat_agent, etc."
),
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class Agent(BaseSingleActionAgent):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
since="0.2.13",
removal="1.0",
message=(
"This function will continue to be supported, but it is recommended for new "
"use cases to be built with LangGraph. LangGraph offers a more flexible and "
"full-featured framework for building agents, including support for "
"tool-calling, persistence of state, and human-in-the-loop workflows. "
"See API reference for this function for a replacement implementation: "
"https://api.python.langchain.com/en/latest/agents/langchain.agents.agent_toolkits.vectorstore.base.create_vectorstore_agent.html " # noqa: E501
"Read more here on how to create agents that query vector stores: "
Expand Down Expand Up @@ -109,6 +113,10 @@ def create_vectorstore_agent(
since="0.2.13",
removal="1.0",
message=(
"This function will continue to be supported, but it is recommended for new "
"use cases to be built with LangGraph. LangGraph offers a more flexible and "
"full-featured framework for building agents, including support for "
"tool-calling, persistence of state, and human-in-the-loop workflows. "
"See API reference for this function for a replacement implementation: "
"https://api.python.langchain.com/en/latest/agents/langchain.agents.agent_toolkits.vectorstore.base.create_vectorstore_router_agent.html " # noqa: E501
"Read more here on how to create agents that query vector stores: "
Expand Down
7 changes: 3 additions & 4 deletions libs/langchain/langchain/agents/agent_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

from langchain_core._api import deprecated

from langchain._api.deprecation import AGENT_DEPRECATION_WARNING


@deprecated(
"0.1.0",
message=(
"Use new agent constructor methods like create_react_agent, create_json_agent, "
"create_structured_chat_agent, etc."
),
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class AgentType(str, Enum):
Expand Down
7 changes: 6 additions & 1 deletion libs/langchain/langchain/agents/chat/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from langchain_core.tools import BaseTool
from pydantic import Field

from langchain._api.deprecation import AGENT_DEPRECATION_WARNING
from langchain.agents.agent import Agent, AgentOutputParser
from langchain.agents.chat.output_parser import ChatOutputParser
from langchain.agents.chat.prompt import (
Expand All @@ -25,7 +26,11 @@
from langchain.chains.llm import LLMChain


@deprecated("0.1.0", alternative="create_react_agent", removal="1.0")
@deprecated(
"0.1.0",
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class ChatAgent(Agent):
"""Chat Agent."""

Expand Down
7 changes: 6 additions & 1 deletion libs/langchain/langchain/agents/conversational/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from langchain_core.tools import BaseTool
from pydantic import Field

from langchain._api.deprecation import AGENT_DEPRECATION_WARNING
from langchain.agents.agent import Agent, AgentOutputParser
from langchain.agents.agent_types import AgentType
from langchain.agents.conversational.output_parser import ConvoOutputParser
Expand All @@ -19,7 +20,11 @@
from langchain.chains import LLMChain


@deprecated("0.1.0", alternative="create_react_agent", removal="1.0")
@deprecated(
"0.1.0",
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class ConversationalAgent(Agent):
"""An agent that holds a conversation in addition to using tools."""

Expand Down
6 changes: 2 additions & 4 deletions libs/langchain/langchain/agents/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
from langchain_core.language_models import BaseLanguageModel
from langchain_core.tools import BaseTool

from langchain._api.deprecation import AGENT_DEPRECATION_WARNING
from langchain.agents.agent import AgentExecutor
from langchain.agents.agent_types import AgentType
from langchain.agents.loading import AGENT_TO_CLASS, load_agent


@deprecated(
"0.1.0",
alternative=(
"Use new agent constructor methods like create_react_agent, create_json_agent, "
"create_structured_chat_agent, etc."
),
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
def initialize_agent(
Expand Down
13 changes: 11 additions & 2 deletions libs/langchain/langchain/agents/mrkl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from langchain_core.tools.render import render_text_description
from pydantic import Field

from langchain._api.deprecation import AGENT_DEPRECATION_WARNING
from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser
from langchain.agents.agent_types import AgentType
from langchain.agents.mrkl.output_parser import MRKLOutputParser
Expand All @@ -34,7 +35,11 @@ class ChainConfig(NamedTuple):
action_description: str


@deprecated("0.1.0", alternative="create_react_agent", removal="1.0")
@deprecated(
"0.1.0",
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class ZeroShotAgent(Agent):
"""Agent for the MRKL chain.
Expand Down Expand Up @@ -168,7 +173,11 @@ def _validate_tools(cls, tools: Sequence[BaseTool]) -> None:
super()._validate_tools(tools)


@deprecated("0.1.0", removal="1.0")
@deprecated(
"0.1.0",
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class MRKLChain(AgentExecutor):
"""Chain that implements the MRKL system."""

Expand Down
25 changes: 21 additions & 4 deletions libs/langchain/langchain/agents/react/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from langchain_core.tools import BaseTool, Tool
from pydantic import Field

from langchain._api.deprecation import AGENT_DEPRECATION_WARNING
from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser
from langchain.agents.agent_types import AgentType
from langchain.agents.react.output_parser import ReActOutputParser
Expand All @@ -22,7 +23,11 @@
from langchain_community.docstore.base import Docstore


@deprecated("0.1.0", removal="1.0")
@deprecated(
"0.1.0",
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class ReActDocstoreAgent(Agent):
"""Agent for the ReAct chain."""

Expand Down Expand Up @@ -69,7 +74,11 @@ def llm_prefix(self) -> str:
return "Thought:"


@deprecated("0.1.0", removal="1.0")
@deprecated(
"0.1.0",
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class DocstoreExplorer:
"""Class to assist with exploration of a document store."""

Expand Down Expand Up @@ -119,7 +128,11 @@ def _paragraphs(self) -> List[str]:
return self.document.page_content.split("\n\n")


@deprecated("0.1.0", removal="1.0")
@deprecated(
"0.1.0",
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class ReActTextWorldAgent(ReActDocstoreAgent):
"""Agent for the ReAct TextWorld chain."""

Expand All @@ -139,7 +152,11 @@ def _validate_tools(cls, tools: Sequence[BaseTool]) -> None:
raise ValueError(f"Tool name should be Play, got {tool_names}")


@deprecated("0.1.0", removal="1.0")
@deprecated(
"0.1.0",
message=AGENT_DEPRECATION_WARNING,
removal="1.0",
)
class ReActChain(AgentExecutor):
"""[Deprecated] Chain that implements the ReAct paper."""

Expand Down

0 comments on commit 8adc4a5

Please sign in to comment.