Invalid parameter: messages with role 'tool' must be a response to a preceeding message with 'tool_calls' . #8419
-
Can someone please tell me where can be the issue which is causing this issue? `
} private static void ManageChatHistory(ChatHistory _chatHistory, string query, AuthorRole authorRole)
} private async Task ExecuteWithRetryAsync(Func<Task> action, int maxRetryAttempts, TimeSpan delayBetweenRetries)
}
} private static bool ContainsRelevantKeywords(string content) private async Task ExecuteChatCompletionAsync(ChatHistory chatHistory, string query, AuthorRole authorRole, OpenAIPromptExecutionSettings settings)
}` |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @msajjadariqt, the error in your subject "messages with role For example, with function calling enabled: if a user asks the model a question: Can you please double check what you have included as part of your chat history? You may be missing adding the response from the model that contains the tool_calls that are processed in SK. |
Beta Was this translation helpful? Give feedback.
Hi @msajjadariqt, the error in your subject "messages with role
tool
must be a response to a preceding message withtool_calls
" occurs because the chat history seems to be misconfigured. When dealing with tool calls, and the model, the chat history needs to have the messages in the proper order (with the proper roles) otherwise it throws this error.For example, with function calling enabled: if a user asks the model a question:
What is 10101+1001?
the model returns a finish_reason=tool_calls
, and then it expects the next message to contain the tool_calls response(s) with the role='tool'. You can see this represented in the screenshot (you'll want to click on it so you can zoom in).Can …