mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-16 23:13:31 +00:00
Add Enum for agent types (#2321)
This pull request adds an enum class for the various types of agents used in the project, located in the `agent_types.py` file. Currently, the project is using hardcoded strings for the initialization of these agents, which can lead to errors and make the code harder to maintain. With the introduction of the new enums, the code will be more readable and less error-prone. The new enum members include: - ZERO_SHOT_REACT_DESCRIPTION - REACT_DOCSTORE - SELF_ASK_WITH_SEARCH - CONVERSATIONAL_REACT_DESCRIPTION - CHAT_ZERO_SHOT_REACT_DESCRIPTION - CHAT_CONVERSATIONAL_REACT_DESCRIPTION In this PR, I have also replaced the hardcoded strings with the appropriate enum members throughout the codebase, ensuring a smooth transition to the new approach.
This commit is contained in:
@@ -5,6 +5,7 @@ from typing import Any, List, Mapping, Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
from langchain.agents import AgentExecutor, initialize_agent
|
||||
from langchain.agents.agent_types import AgentType
|
||||
from langchain.agents.tools import Tool
|
||||
from langchain.callbacks.base import CallbackManager
|
||||
from langchain.llms.base import LLM
|
||||
@@ -55,7 +56,11 @@ def _get_agent(**kwargs: Any) -> AgentExecutor:
|
||||
),
|
||||
]
|
||||
agent = initialize_agent(
|
||||
tools, fake_llm, agent="zero-shot-react-description", verbose=True, **kwargs
|
||||
tools,
|
||||
fake_llm,
|
||||
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
||||
verbose=True,
|
||||
**kwargs,
|
||||
)
|
||||
return agent
|
||||
|
||||
@@ -98,7 +103,7 @@ def test_agent_with_callbacks_global() -> None:
|
||||
agent = initialize_agent(
|
||||
tools,
|
||||
fake_llm,
|
||||
agent="zero-shot-react-description",
|
||||
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
||||
verbose=True,
|
||||
callback_manager=manager,
|
||||
)
|
||||
@@ -144,7 +149,7 @@ def test_agent_with_callbacks_local() -> None:
|
||||
agent = initialize_agent(
|
||||
tools,
|
||||
fake_llm,
|
||||
agent="zero-shot-react-description",
|
||||
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
||||
verbose=True,
|
||||
callback_manager=manager,
|
||||
)
|
||||
@@ -191,7 +196,7 @@ def test_agent_with_callbacks_not_verbose() -> None:
|
||||
agent = initialize_agent(
|
||||
tools,
|
||||
fake_llm,
|
||||
agent="zero-shot-react-description",
|
||||
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
||||
callback_manager=manager,
|
||||
)
|
||||
|
||||
@@ -223,7 +228,7 @@ def test_agent_tool_return_direct() -> None:
|
||||
agent = initialize_agent(
|
||||
tools,
|
||||
fake_llm,
|
||||
agent="zero-shot-react-description",
|
||||
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
||||
)
|
||||
|
||||
output = agent.run("when was langchain made")
|
||||
@@ -249,7 +254,7 @@ def test_agent_tool_return_direct_in_intermediate_steps() -> None:
|
||||
agent = initialize_agent(
|
||||
tools,
|
||||
fake_llm,
|
||||
agent="zero-shot-react-description",
|
||||
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
||||
return_intermediate_steps=True,
|
||||
)
|
||||
|
||||
@@ -280,7 +285,7 @@ def test_agent_with_new_prefix_suffix() -> None:
|
||||
agent = initialize_agent(
|
||||
tools=tools,
|
||||
llm=fake_llm,
|
||||
agent="zero-shot-react-description",
|
||||
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
||||
agent_kwargs={"prefix": prefix, "suffix": suffix},
|
||||
)
|
||||
|
||||
@@ -307,7 +312,7 @@ def test_agent_lookup_tool() -> None:
|
||||
agent = initialize_agent(
|
||||
tools=tools,
|
||||
llm=fake_llm,
|
||||
agent="zero-shot-react-description",
|
||||
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
|
||||
)
|
||||
|
||||
assert agent.lookup_tool("Search") == tools[0]
|
||||
|
Reference in New Issue
Block a user