- 
                Notifications
    
You must be signed in to change notification settings  - Fork 318
 
Labels
Description
When a LangChain ToolMessage is translated to a Content, it is assigned the role function in chatmodels.py. This role does not exist, only user and model are valid values. This applies to both v1 and v1beta1.
Interestingly, this appears to throw no API error by itself, but if the Content sent to the API is malformed (e. g. by adding an invalid field to it before sending it to Gemini), the API returns
WARNING  - langchain_core.language_models.llms - Retrying langchain_google_vertexai.chat_models._acompletion_with_retry.<locals>._completion_with_retry_inner in 4.0 seconds as it raised BadRequest: 400 POST https://.../models/gemini-2.5-flash:generateContent: Please use a valid role: user, model..
Either way, setting the role to function results in undefined behavior. Google's docs suggest to use the user role instead.