Skip to content
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

ChatCohere with Agentic RAG and Langgraph #28630

Open
5 tasks done
jimmyshah83 opened this issue Dec 9, 2024 · 1 comment
Open
5 tasks done

ChatCohere with Agentic RAG and Langgraph #28630

jimmyshah83 opened this issue Dec 9, 2024 · 1 comment

Comments

@jimmyshah83
Copy link

Checked other resources

  • I added a very descriptive title to this issue.
  • 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

@keenborder786
Copy link
Contributor

I have created the following PR which will migrate ChatCohere to V2 and will take care of it.

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

No branches or pull requests

2 participants