How do I integrate ChatOpenAI, UpstashRedisChatMessageHistory and tool calling? #28769
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.
Uh oh!
There was an error while loading. Please reload this page.
-
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 tools = ['handoff'] as DynamicTool[];
const model = new ChatOpenAI({ openAIApiKey: env.OPENAI_API_KEY }).bindTools(tools).withRetry({
stopAfterAttempt: 3,
});
const prompt = ChatPromptTemplate.fromMessages([
['system', systemPrompt],
new MessagesPlaceholder('history'),
['human', '{input}'],
]);
const chain = prompt.pipe(model);
const response = await chainWithHistory.invoke(
{
input: '...',
},
{
configurable: {
sessionId:
history:${userKey}
,},
},
);
Result: {
answer: undefined,
error: BadRequestError: 400 An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: call_2dXaMrjN7sZeyMJ3v23CA5kx
Troubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/INVALID_TOOL_RESULTS/
}
I even tried adding a
new MessagesPlaceholder('agent_scratchpad')
in my ChatPromptTemplate.fromMessages array, but I get:Error: Missing value for input variable
agent_scratchpad
Troubleshooting URL: https://js.langchain.com/docs/troubleshooting/errors/INVALID_PROMPT_INPUT/
lc_error_code: 'INVALID_PROMPT_INPUT'
Beta Was this translation helpful? Give feedback.
All reactions