code: def sum_fields(layer, output_field_key, input_fields):
      
      field_definition = definition(output_field_key)
      output_field_name = field_definition['field_name']
      # If the fields only has one element
      if len(input_fields) == 1:
          # Name is different, copy it
          if input_fields[0] != output_field_name:
              to_rename = {input_fields[0]: output_field_name}
              # We copy only, it will be deleted later.
              # We can't rename the field, we need to copy it as the same
              # field might be used many times in the FMT tool.
              copy_fields(layer, to_rename)
          else:
              # Name is same, do nothing
              return
      else:
          # Creating expression
          # Put field name in a double quote. See #4248
          input_fields = ['"%s"' % f for f in input_fields]
          string_expression = ' + '.join(input_fields)
          sum_expression = QgsExpression(string_expression)
          context = QgsExpressionContext()
          context.setFields(layer.fields())
          sum_expression.prepare(context)
  
          # Get the output field index
          output_idx = layer.fields().lookupField(output_field_name)
          # Output index is not found
          layer.startEditing()
          if output_idx == -1:
              output_field = create_field_from_definition(field_definition)
              layer.addAttribute(output_field)
              output_idx = layer.fields().lookupField(output_field_name)
  
          # Iterate to all features
          for feature in layer.getFeatures():
              context.setFeature(feature)
              result = sum_expression.evaluate(context)
              feature[output_idx] = result
              layer.updateFeature(feature)
  
          layer.commitChanges()
docs: Sum the value of input_fields and put it as output_field.
  
      :param layer: The vector layer.
      :type layer: QgsVectorLayer
  
      :param output_field_key: The output field definition key.
      :type output_field_key: basestring
  
      :param input_fields: List of input fields' name.
      :type input_fields: list