Skip to content

Add Enum for agent types #2321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 4, 2023
Merged

Add Enum for agent types #2321

merged 7 commits into from
Apr 4, 2023

Conversation

Shrined
Copy link
Contributor

@Shrined Shrined commented Apr 2, 2023

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.

@sergerdn
Copy link
Contributor

sergerdn commented Apr 3, 2023

I'm sorry to be the bearer of bad news, but I need to inform you that...

 grep -r "zero-shot-react-description"  docs/
docs/ecosystem/aim_tracking.ipynb:    "    agent=\"zero-shot-react-description\",\n",
docs/ecosystem/clearml_tracking.ipynb:    "    agent=\"zero-shot-react-description\",\n",
docs/ecosystem/wandb_tracking.ipynb:    "    agent=\"zero-shot-react-description\",\n",
docs/getting_started/getting_started.md:agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
docs/getting_started/getting_started.md:Agents can also be used with chat models, you can initialize one using `"chat-zero-shot-react-description"` as the agent type.
docs/getting_started/getting_started.md:agent = initialize_agent(tools, chat, agent="chat-zero-shot-react-description", verbose=True)
docs/modules/agents/agents/agent_types.md:## `zero-shot-react-description`
docs/modules/agents/agents/examples/mrkl.ipynb:    "mrkl = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/agents/examples/mrkl_chat.ipynb:    "mrkl = initialize_agent(tools, llm, agent=\"chat-zero-shot-react-description\", verbose=True)"
docs/modules/agents/agent_executors/examples/agent_vectorstore.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/agent_executors/examples/agent_vectorstore.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/agent_executors/examples/agent_vectorstore.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/agent_executors/examples/async_agent.ipynb:    "            tools, llm, agent=\"zero-shot-react-description\", verbose=True\n",
docs/modules/agents/agent_executors/examples/async_agent.ipynb:    "            initialize_agent(async_tools, llm, agent=\"zero-shot-react-description\", verbose=True, callback_manager=manager)\n",
docs/modules/agents/agent_executors/examples/async_agent.ipynb:    "async_agent = initialize_agent(async_tools, llm, agent=\"zero-shot-react-description\", verbose=True, callback_manager=manager)\n",
docs/modules/agents/agent_executors/examples/intermediate_steps.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True, return_intermediate_steps=True)"
docs/modules/agents/agent_executors/examples/max_iterations.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/agent_executors/examples/max_iterations.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True, max_iterations=2)"
docs/modules/agents/agent_executors/examples/max_iterations.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True, max_iterations=2, early_stopping_method=\"generate\")"
docs/modules/agents/getting_started.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/how_to_guides.rst:- **Agent used**: `zero-shot-react-description`
docs/modules/agents/tools/custom_tools.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/tools/custom_tools.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/tools/custom_tools.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/tools/custom_tools.ipynb:    "agent = initialize_agent(tools, OpenAI(temperature=0), agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/tools/custom_tools.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/tools/examples/chatgpt_plugins.ipynb:    "agent_chain = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)\n",
docs/modules/agents/tools/examples/human_tools.ipynb:    "    agent=\"zero-shot-react-description\",\n",
docs/modules/agents/tools/examples/search_tools.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/tools/examples/search_tools.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/tools/examples/search_tools.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/tools/examples/search_tools.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/tools/examples/zapier.ipynb:    "agent = initialize_agent(toolkit.get_tools(), llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/agents/tools/multi_input_tool.ipynb:    "mrkl = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/models/llms/examples/fake_llm.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/modules/models/llms/examples/token_usage_tracking.ipynb:    "agent = initialize_agent(tools, llm, agent=\"zero-shot-react-description\", verbose=True)"
docs/tracing/agent_with_tracing.ipynb:    "    tools, llm, agent=\"zero-shot-react-description\", verbose=True\n",
docs/tracing/agent_with_tracing.ipynb:    "    tools, ChatOpenAI(temperature=0), agent=\"chat-zero-shot-react-description\", verbose=True\n",
docs/use_cases/evaluation/agent_benchmarking.ipynb:    "agent = initialize_agent(tools, OpenAI(temperature=0), agent=\"zero-shot-react-description\")\n"
docs/use_cases/evaluation/agent_vectordb_sota_pg.ipynb:    "agent = initialize_agent(tools, OpenAI(temperature=0), agent=\"zero-shot-react-description\", max_iterations=3)"

@Shrined
Copy link
Contributor Author

Shrined commented Apr 3, 2023

Addressed the issue where hardcoded strings instead of the AgentType enums were still being used in some of the examples within the documentation.

Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is awesome.

thinking about backwards compatibility - this will still work for people on the old version, right? because the string is still the same under the hood?

@Shrined
Copy link
Contributor Author

Shrined commented Apr 3, 2023

this is awesome.

thinking about backwards compatibility - this will still work for people on the old version, right? because the string is still the same under the hood?

Yes, exactly. Due to the AgentType class inheriting from str, the underlying string representation is maintained, ensuring backwards compatibility for users on older versions.

# Conflicts:
#	langchain/agents/initialize.py
Copy link
Contributor

@hwchase17 hwchase17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants