You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
I am sure that this is a bug in LangChain rather than my code.
The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
def agent(state):
"""
Invokes the agent model to generate a response based on the current state. Given
the question, it will decide to retrieve using the retriever tool, or simply end.
Args:
state (messages): The current state
Returns:
dict: The updated state with the agent response appended to messages
"""
print("---CALL AGENT---")
messages = state["messages"]
model = AzureChatOpenAI(model="gpt-4o", temperature=0, streaming=True)
# model = ChatCohere(model="command-r-plus-08-2024", temperature=0, streaming=True)
model = model.bind_tools(tools)
response = model.invoke(messages)
# We return a list, because this will get added to the existing list
return {"messages": [response]}
Error Message and Stack Trace (if applicable)
The last message is not an ToolMessage or HumanMessage
Description
I am building an Agentic RAG system with ChatCohere but when the agent tries to Transform a query, it keeps failing with the below error:
The last message is not an ToolMessage or HumanMessage
Looking at the class ChatCohere, it seems like it might be a design choice:
check if the last message is a tool message or human message
if not (
isinstance(messages[-1], ToolMessage) or isinstance(messages[-1], HumanMessage)
):
raise ValueError("The last message is not an ToolMessage or HumanMessage")
Does anyone know why is this the case? In terms of Agentic AI, the agent should have the ability to rewrite the question to generate a more optimal output but this code base does not allow rewrites.
Note that it works perfectly fine with AzureChatOpenAI
System Info
System Info
python-dotenv
pandas
langchain
langchainhub
langchain-cohere
azure-search-documents==11.6.0b7
azure-identity
langgraph
langchain_openai
cohere
The text was updated successfully, but these errors were encountered:
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
The last message is not an ToolMessage or HumanMessage
Description
I am building an Agentic RAG system with ChatCohere but when the agent tries to Transform a query, it keeps failing with the below error:
The last message is not an ToolMessage or HumanMessage
Looking at the class ChatCohere, it seems like it might be a design choice:
check if the last message is a tool message or human message
Does anyone know why is this the case? In terms of Agentic AI, the agent should have the ability to rewrite the question to generate a more optimal output but this code base does not allow rewrites.
Note that it works perfectly fine with AzureChatOpenAI
System Info
System Info
python-dotenv
pandas
langchain
langchainhub
langchain-cohere
azure-search-documents==11.6.0b7
azure-identity
langgraph
langchain_openai
cohere
The text was updated successfully, but these errors were encountered: