Function call response should not have a user role

Why do function call responses have a user role? It’s confusing the model and making it reply to itself.

1 Like

Hello @beetroit

Welcome to the community.

  • Role Assignment:
    Function call responses are tagged with the “user” role to preserve conversation context. This design choice helps maintain a complete dialogue history.

  • Model Behavior:
    The model is trained to process conversation turns. When it sees a “user” role, it treats that message as an input from the user—even if it comes from a function call—prompting it to generate another response.

For more details about function calling you can read the documentation:

1 Like

I know about this, my prompt does nothing to prevent this behaviour unfortunately. I gave gemini 2.0 flash tools for sending a message and thinking, but it just keeps making up stuff and chatting with itself inside the tool call history.
Do you have any sample prompt that works?

Could you share more about your use case and what you’re trying to achieve?

Generally model query 2 time to answer using tools

I can vouch for that. It should definitely not have the role “user.” I had created a conversation with the model, and at one point it performed a parallel function call. After the functions were executed and the responses were added to the conversation (with the role “user”, since with the role “tool” it returns an error “Please use valid role”), the model received those calls and its literal internal reasoning text (thought summaries or whatever) was “Okay, the user has confirmed that this task has been completed with repeated responses,” and afterwards, it re-called the same functions again, causing my code to execute the functions and append the same exact responses to the conversation history a second time, and the model proceeded to re-call the functions over and over again. Why not have the role “tool”? The model is literally getting confused in its thought process