Using chat instead of llm will not answer questions which chat can answer itself #4660
-
#Here's what I did, if i use agent =initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True), it will work fine. from langchain.agents import load_tools
During handling of the above exception, another exception occurred: Traceback (most recent call last): |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The problem is that with the agents If you want an agent that can use its tools and talk to you like a normal chat bot, then use the 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.memory import ConversationBufferMemory # Import memory
chat = ChatOpenAI(temperature=0)
llm = OpenAI(temperature=0)
tools = load_tools(["llm-math", "searx-search"], searx_host="http://localhost:8080/", llm=llm)
# Add memory object
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
agent = initialize_agent(tools, chat, agent=AgentType.CHAT_CONVERSATIONAL_REACT_DESCRIPTION, verbose=True, memory=memory)
agent.run("how are you today") |
Beta Was this translation helpful? Give feedback.
The problem is that with the agents
CHAT_ZERO_SHOT_REACT_DESCRIPTION
andZERO_SHOT_REACT_DESCRIPTION
, if you were to ask it something that it cannot use a tool to answer, theOutputParser
will raise an error because it expects the LLM to use a tool, but when you asked it how it was, it couldn't use itsllm-math
tool orsearx-search
tool to answer because it doesn't need to. If you run your code again, but ask it to do a maths problem (so it uses the maths tool), it will work.If you want an agent that can use its tools and talk to you like a normal chat bot, then use the
CHAT_CONVERSATIONAL_REACT_DESCRIPTION
agent. The link to the documentation is here. All you will need to do in your cod…