langchain icon indicating copy to clipboard operation
langchain copied to clipboard

[structure][agent class] Move Overlapping Methods to a Shared Base Class

Open skcoirz opened this issue 2 years ago β€’ 4 comments

  • BaseSingleActionAgent and BaseMultiActionAgent are pretty much the same. In the original PR where MultiActionAgent was introduced, @hwchase17 shared the worry that MultiActionAgent is so under-explored that it would potentially be really different from the SingleActionAgent. It could still be true when the autonomous agent grows.
  • Given the above, this PR still keeps the strict distinguishing between these two classes and at the same time reduce the duplicate logics as much as possible. It’s still very convenient to change any of the methods and make them as different as we want.

Test:

  • as the logic is so deep and core, all existing integration test should be able to cover it.
  • I’ll add additional integration tests in following PRs when we start ramping up on concrete business inheritance. :)
  • Tested additionally by calling an agent directly with 2 provided tools and then confirm all functionality the same
def test_agent_chain_chat_bot():
	from langchain.agents import load_tools
	from langchain.agents import initialize_agent
	from langchain.agents import AgentType
	from langchain.chat_models import ChatOpenAI
	from langchain.llms import OpenAI
	from langchain.utilities.duckduckgo_search import DuckDuckGoSearchAPIWrapper

	chat = ChatOpenAI(temperature=0)
	llm = OpenAI(temperature=0)
	tools = load_tools(["ddg-search", "llm-math"], llm=llm)

	agent = initialize_agent(tools, chat, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
	agent.run("Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?")
test_agent_chain_chat_bot()
Screenshot 2023-05-01 at 8 17 01 PM

skcoirz avatar Apr 29 '23 18:04 skcoirz

@vowelparrot , please take a look when you have time. Thank you so much. :)

skcoirz avatar May 02 '23 03:05 skcoirz

Will sync with @hwchase17 on this one and review tomorrow

vowelparrot avatar May 02 '23 03:05 vowelparrot

Will sync with @hwchase17 on this one and review tomorrow

Thank you so much. Really appreciate it. :) (let me quickly rebase now to make it easier for you.)

skcoirz avatar May 02 '23 03:05 skcoirz

@vowelparrot please lmk what is your discussion result with Harrison. Thank you so much!

skcoirz avatar May 02 '23 18:05 skcoirz

some feedback we've gotten from users is theres a lot of inheritance already and it can make it tricky to understand whats going on. although this may save code, i think this contributes to that problem. therefor, i dont think we want to do this at the moment

hwchase17 avatar May 03 '23 22:05 hwchase17