How do I integrate ChatOpenAI, UpstashRedisChatMessageHistory and tool calling? #28769
-
Here's an overview of my current implementation and below the error I am getting everytime the AI calls a tool. How do I fix this tool calling? I DON'T WANT TO USE LANGGRAPH. There must be a solution using LCEL, for example.const systemPrompt = '...'; const prompt = ChatPromptTemplate.fromMessages([ const chain = prompt.pipe(model);
const response = await chainWithHistory.invoke(
Result: { Troubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/INVALID_TOOL_RESULTS/
}I even tried adding a
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
To resolve the tool calling issue in your implementation, ensure that each tool call is followed by a corresponding response message. Here's how you can address the problem:
Regarding the To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
Beta Was this translation helpful? Give feedback.
-
@dosu, I am calling the chain only once, I though RunnableWithMessageHistory handled saving context to memory automatically. Do I really have to save tool responses manually? If so, how do I do this with UpstashRedisChatMessageHistory? It only has these options:
Also, BaseMessage doesn't seem to allow me to set a role for the message I am inserting so I could use the 'tool' role. |
Beta Was this translation helpful? Give feedback.
To resolve the tool calling issue in your implementation, ensure that each tool call is followed by a corresponding response message. Here's how you can address the problem:
Capture Tool Responses: After making a tool call, capture the response and append it to the chat history. This ensures that each tool call has a corresponding response message.
Update Chat History: Make sure to update the chat history with both the tool call and its response before invoking the model again. This maintains the correct sequence of messages.
Example Implementation: