@@ -142,26 +142,28 @@ def _format_request_content_part(self, content: ContentBlock) -> genai.types.Par
142142 )
143143
144144 if "toolUse" in content :
145- thought_signature_b64 = cast ( Optional [ str ], content ["toolUse" ].get ("thoughtSignature" ) )
145+ thought_signature_b64 = content ["toolUse" ].get ("thoughtSignature" )
146146
147- thought_signature = None
147+ tool_use_thought_signature : Optional [ bytes ] = None
148148 if thought_signature_b64 :
149149 try :
150- thought_signature = base64 .b64decode (thought_signature_b64 )
150+ tool_use_thought_signature = base64 .b64decode (thought_signature_b64 )
151151 except Exception as e :
152- logger .error ("toolUseId=<%s> | failed to decode thoughtSignature: %s" , content ["toolUse" ].get ("toolUseId" ), e )
152+ tool_use_id = content ["toolUse" ].get ("toolUseId" )
153+ logger .error ("toolUseId=<%s> | failed to decode thoughtSignature: %s" , tool_use_id , e )
153154 else :
154155 # thoughtSignature is now preserved by the Strands framework (as of v1.18+)
155156 # If missing, it means the model didn't provide one (e.g., older Gemini versions)
156- logger .debug ("toolUseId=<%s> | no thoughtSignature in toolUse (model may not require it)" , content ["toolUse" ].get ("toolUseId" ))
157+ tool_use_id = content ["toolUse" ].get ("toolUseId" )
158+ logger .debug ("toolUseId=<%s> | no thoughtSignature in toolUse (model may not require it)" , tool_use_id )
157159
158160 return genai .types .Part (
159161 function_call = genai .types .FunctionCall (
160162 args = content ["toolUse" ]["input" ],
161163 id = content ["toolUse" ]["toolUseId" ],
162164 name = content ["toolUse" ]["name" ],
163165 ),
164- thought_signature = thought_signature ,
166+ thought_signature = tool_use_thought_signature ,
165167 )
166168
167169 raise TypeError (f"content_type=<{ next (iter (content ))} > | unsupported type" )
0 commit comments