Skip to content

Commit

Permalink
langchain[patch]: deprecate old agent classes and methods (#15558)
Browse files Browse the repository at this point in the history
  • Loading branch information
baskaryan authored Jan 5, 2024
1 parent 9b94497 commit 68eb305
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 0 deletions.
17 changes: 17 additions & 0 deletions libs/langchain/langchain/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)

import yaml
from langchain_core._api import deprecated
from langchain_core.agents import AgentAction, AgentFinish, AgentStep
from langchain_core.exceptions import OutputParserException
from langchain_core.language_models import BaseLanguageModel
Expand Down Expand Up @@ -486,6 +487,14 @@ async def aplan(
return output


@deprecated(
"0.1.0",
alternative=(
"Use new agent constructor methods like create_react_agent, create_json_agent, "
"create_structured_chat_agent, etc."
),
removal="0.2.0",
)
class LLMSingleActionAgent(BaseSingleActionAgent):
"""Base class for single action agents."""

Expand Down Expand Up @@ -568,6 +577,14 @@ def tool_run_logging_kwargs(self) -> Dict:
}


@deprecated(
"0.1.0",
alternative=(
"Use new agent constructor methods like create_react_agent, create_json_agent, "
"create_structured_chat_agent, etc."
),
removal="0.2.0",
)
class Agent(BaseSingleActionAgent):
"""Agent that calls the language model and deciding the action.
Expand Down
10 changes: 10 additions & 0 deletions libs/langchain/langchain/agents/agent_types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
"""Module definitions of agent types together with corresponding agents."""
from enum import Enum

from langchain_core._api import deprecated


@deprecated(
"0.1.0",
alternative=(
"Use new agent constructor methods like create_react_agent, create_json_agent, "
"create_structured_chat_agent, etc."
),
removal="0.2.0",
)
class AgentType(str, Enum):
"""An enum for agent types.
Expand Down
2 changes: 2 additions & 0 deletions libs/langchain/langchain/agents/chat/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, List, Optional, Sequence, Tuple

from langchain_core._api import deprecated
from langchain_core.agents import AgentAction
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts import BasePromptTemplate
Expand All @@ -24,6 +25,7 @@
from langchain.chains.llm import LLMChain


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

Expand Down
2 changes: 2 additions & 0 deletions libs/langchain/langchain/agents/conversational/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from typing import Any, List, Optional, Sequence

from langchain_core._api import deprecated
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts import PromptTemplate
from langchain_core.pydantic_v1 import Field
Expand All @@ -17,6 +18,7 @@
from langchain.chains import LLMChain


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

Expand Down
2 changes: 2 additions & 0 deletions libs/langchain/langchain/agents/conversational_chat/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from typing import Any, List, Optional, Sequence, Tuple

from langchain_core._api import deprecated
from langchain_core.agents import AgentAction
from langchain_core.language_models import BaseLanguageModel
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
Expand All @@ -29,6 +30,7 @@
from langchain.chains import LLMChain


@deprecated("0.1.0", alternative="create_json_chat_agent", removal="0.2.0")
class ConversationalChatAgent(Agent):
"""An agent designed to hold a conversation in addition to using tools."""

Expand Down
9 changes: 9 additions & 0 deletions libs/langchain/langchain/agents/initialize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Load agent."""
from typing import Any, Optional, Sequence

from langchain_core._api import deprecated
from langchain_core.language_models import BaseLanguageModel
from langchain_core.tools import BaseTool

Expand All @@ -10,6 +11,14 @@
from langchain.callbacks.base import BaseCallbackManager


@deprecated(
"0.1.0",
alternative=(
"Use new agent constructor methods like create_react_agent, create_json_agent, "
"create_structured_chat_agent, etc."
),
removal="0.2.0",
)
def initialize_agent(
tools: Sequence[BaseTool],
llm: BaseLanguageModel,
Expand Down
3 changes: 3 additions & 0 deletions libs/langchain/langchain/agents/loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any, List, Optional, Union

import yaml
from langchain_core._api import deprecated
from langchain_core.language_models import BaseLanguageModel
from langchain_core.utils.loading import try_load_from_hub

Expand All @@ -30,6 +31,7 @@ def _load_agent_from_tools(
return agent_cls.from_llm_and_tools(llm, tools, **combined_config)


@deprecated("0.1.0", removal="0.2.0")
def load_agent_from_config(
config: dict,
llm: Optional[BaseLanguageModel] = None,
Expand Down Expand Up @@ -85,6 +87,7 @@ def load_agent_from_config(
return agent_cls(**combined_config) # type: ignore


@deprecated("0.1.0", removal="0.2.0")
def load_agent(
path: Union[str, Path], **kwargs: Any
) -> Union[BaseSingleActionAgent, BaseMultiActionAgent]:
Expand Down
3 changes: 3 additions & 0 deletions libs/langchain/langchain/agents/mrkl/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from typing import Any, Callable, List, NamedTuple, Optional, Sequence

from langchain_core._api import deprecated
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts import PromptTemplate
from langchain_core.pydantic_v1 import Field
Expand Down Expand Up @@ -32,6 +33,7 @@ class ChainConfig(NamedTuple):
action_description: str


@deprecated("0.1.0", alternative="create_react_agent", removal="0.2.0")
class ZeroShotAgent(Agent):
"""Agent for the MRKL chain."""

Expand Down Expand Up @@ -137,6 +139,7 @@ def _validate_tools(cls, tools: Sequence[BaseTool]) -> None:
super()._validate_tools(tools)


@deprecated("0.1.0", removal="0.2.0")
class MRKLChain(AgentExecutor):
"""[Deprecated] Chain that implements the MRKL system."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Any, List, Optional, Sequence, Tuple, Union

from langchain_community.tools.convert_to_openai import format_tool_to_openai_function
from langchain_core._api import deprecated
from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.language_models import BaseLanguageModel
from langchain_core.messages import (
Expand Down Expand Up @@ -30,6 +31,7 @@
from langchain.callbacks.manager import Callbacks


@deprecated("0.1.0", alternative="create_openai_functions_agent", removal="0.2.0")
class OpenAIFunctionsAgent(BaseSingleActionAgent):
"""An Agent driven by OpenAIs function powered API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from json import JSONDecodeError
from typing import Any, List, Optional, Sequence, Tuple, Union

from langchain_core._api import deprecated
from langchain_core.agents import AgentAction, AgentActionMessageLog, AgentFinish
from langchain_core.exceptions import OutputParserException
from langchain_core.language_models import BaseLanguageModel
Expand Down Expand Up @@ -93,6 +94,7 @@ def _parse_ai_message(message: BaseMessage) -> Union[List[AgentAction], AgentFin
)


@deprecated("0.1.0", alternative="create_openai_tools_agent", removal="0.2.0")
class OpenAIMultiFunctionsAgent(BaseMultiActionAgent):
"""An Agent driven by OpenAIs function powered API.
Expand Down
5 changes: 5 additions & 0 deletions libs/langchain/langchain/agents/react/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Chain that implements the ReAct paper from https://arxiv.org/pdf/2210.03629.pdf."""
from typing import Any, List, Optional, Sequence

from langchain_core._api import deprecated
from langchain_core.documents import Document
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts import BasePromptTemplate
Expand All @@ -17,6 +18,7 @@
from langchain.docstore.base import Docstore


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

Expand Down Expand Up @@ -63,6 +65,7 @@ def llm_prefix(self) -> str:
return "Thought:"


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

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


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

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


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

Expand Down
3 changes: 3 additions & 0 deletions libs/langchain/langchain/agents/self_ask_with_search/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from langchain_community.utilities.google_serper import GoogleSerperAPIWrapper
from langchain_community.utilities.searchapi import SearchApiAPIWrapper
from langchain_community.utilities.serpapi import SerpAPIWrapper
from langchain_core._api import deprecated
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts import BasePromptTemplate
from langchain_core.pydantic_v1 import Field
Expand All @@ -19,6 +20,7 @@
from langchain.agents.utils import validate_tools_single_input


@deprecated("0.1.0", alternative="create_self_ask_with_search", removal="0.2.0")
class SelfAskWithSearchAgent(Agent):
"""Agent for the self-ask-with-search paper."""

Expand Down Expand Up @@ -61,6 +63,7 @@ def llm_prefix(self) -> str:
return ""


@deprecated("0.1.0", removal="0.2.0")
class SelfAskWithSearchChain(AgentExecutor):
"""[Deprecated] Chain that does self-ask with search."""

Expand Down
2 changes: 2 additions & 0 deletions libs/langchain/langchain/agents/structured_chat/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
from typing import Any, List, Optional, Sequence, Tuple

from langchain_core._api import deprecated
from langchain_core.agents import AgentAction
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts import BasePromptTemplate
Expand All @@ -27,6 +28,7 @@
HUMAN_MESSAGE_TEMPLATE = "{input}\n\n{agent_scratchpad}"


@deprecated("0.1.0", alternative="create_structured_chat_agent", removal="0.2.0")
class StructuredChatAgent(Agent):
"""Structured Chat Agent."""

Expand Down
2 changes: 2 additions & 0 deletions libs/langchain/langchain/agents/xml/base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, List, Sequence, Tuple, Union

from langchain_core._api import deprecated
from langchain_core.agents import AgentAction, AgentFinish
from langchain_core.language_models import BaseLanguageModel
from langchain_core.prompts.base import BasePromptTemplate
Expand All @@ -16,6 +17,7 @@
from langchain.tools.render import render_text_description


@deprecated("0.1.0", alternative="create_xml_agent", removal="0.2.0")
class XMLAgent(BaseSingleActionAgent):
"""Agent that uses XML tags.
Expand Down

0 comments on commit 68eb305

Please sign in to comment.