langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Agent react cannot accept gpt4 or gpt 4o as input model

Open HelloWorldLTY opened this issue 1 year ago • 4 comments

Checked other resources

  • [X] I added a very descriptive title to this issue.
  • [X] I searched the LangChain documentation with the integrated search.
  • [X] I used the GitHub search to find a similar question and didn't find it.
  • [X] I am sure that this is a bug in LangChain rather than my code.
  • [X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

The mimial reproduce code is:

from langchain import hub
from langchain.agents import AgentExecutor, create_react_agent
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_openai import OpenAI

tools = []

# Get the prompt to use - you can modify this!
prompt = hub.pull("hwchase17/react")

# Choose the LLM to use
llm = ChatOpenAI(temperature=0, model="gpt-4o")

# Construct the ReAct agent
agent = create_react_agent(llm, tools, prompt)



# Create an agent executor by passing in the agent and tools
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

agent_executor.invoke({"input": "what is LangChain?"})

Error Message and Stack Trace (if applicable)

ile /home/tl688/.conda/envs/cell2sentence/lib/python3.10/site-packages/langchain/agents/output_parsers/react_single_input.py:75, in ReActSingleInputOutputParser.parse(self, text) 74 if not re.search(r"Action\s*\d*\s*:[\s](.?)", text, re.DOTALL): ---> 75 raise OutputParserException( 76 f"Could not parse LLM output: {text}", 77 observation=MISSING_ACTION_AFTER_THOUGHT_ERROR_MESSAGE, 78 llm_output=text, 79 send_to_llm=True, 80 ) 81 elif not re.search( 82 r"[\s]Action\s\d*\sInput\s\d*\s*:[\s](.)", text, re.DOTALL 83 ):

OutputParserException: Could not parse LLM output: LangChain is a framework designed to facilitate the development of applications powered by language models. It provides a suite of tools and components that help developers build applications that can interact with language models in a structured and efficient manner. LangChain is particularly useful for creating applications that require complex language processing tasks, such as chatbots, virtual assistants, and other AI-driven communication tools. It supports integration with various language models and offers features for managing conversations, handling inputs and outputs, and maintaining context across interactions. For troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/OUTPUT_PARSING_FAILURE

Description

This error only happended in gpt4 and gpt4o model, not in 3.5. Replacing it with OpenAI can work.

System Info

The updated version of langchain.

HelloWorldLTY avatar Dec 16 '24 19:12 HelloWorldLTY

@HelloWorldLTY, which version of langchain are you using. Can you uprade to the latest version. Since I tested the same code and everything seems to be working.

keenborder786 avatar Dec 17 '24 12:12 keenborder786

But @HelloWorldLTY if you are facing this error then do the following:


agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, handle_parsing_errors=True)

Making handle_parsing_errors=True will make sure that agent executor takes care of any parsing error by feeding the parsing error back to llm.

keenborder786 avatar Dec 17 '24 12:12 keenborder786

Hi, I have tried handle_parsing_errors=True but it will repeat error information for me. I think I have updated my longchain. Here is my info:

kiwisolver==1.4.7 langchain==0.3.7 langchain-anthropic==0.3.0 langchain-community==0.3.5 langchain-core==0.3.24 langchain-experimental==0.3.3 langchain-huggingface==0.1.2 langchain-ollama==0.2.0 langchain-openai==0.2.5 langchain-text-splitters==0.3.2 langgraph==0.2.44 langgraph-checkpoint==2.0.2 langgraph-sdk==0.1.35 langsmith==0.1.139

HelloWorldLTY avatar Dec 17 '24 13:12 HelloWorldLTY

Hi, does it mean I can try reactgpt4 or gpt4o with the referred comments? Thanks.

HelloWorldLTY avatar Dec 19 '24 04:12 HelloWorldLTY

Hi, @HelloWorldLTY. I'm Dosu, and I'm helping the LangChain team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • You reported a bug where the ReAct agent cannot process "gpt-4o" as an input model, resulting in an OutputParserException.
  • Keenborder786 suggested upgrading LangChain and using handle_parsing_errors=True.
  • You noted that the suggested solution only repeats the error information and provided your package versions.
  • You are seeking clarification on using "reactgpt4" or "gpt4o" with the suggested adjustments.

Next Steps:

  • Could you confirm if this issue is still relevant with the latest version of LangChain? If so, please comment to keep the discussion open.
  • If there is no further activity, this issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar Mar 20 '25 16:03 dosubot[bot]