Skip to content

Invalid argument provided to Gemini: 400 Please ensure that function call turn comes immediately after a user turn or after a function response turn. #27137

Discussion options

You must be logged in to vote

I've resolved this myself, after tracking it properly and storing every state and comparing i figured out that due to the param n_messages=5 previous messages gets cleared due to which any type of message like HumanMessage, AIMessage and ToolMessage can become first but gemini needs messages to be started with HumanMessage and for tool calling we need fucntion call messages as well. So because of all these i think there was the error and now everything working fine without that params.

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@dosubot
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Divyanshu9822
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant