DP4.0 how to add customized algorithm and model into the existing pipeline

say if we have a caffe model about predicting the age of a human face , where should we modify in the pipeline and the files , should we modify the ds-example or write a new gie to replace the existing one .

No.
You can use deepstream-app, pgie for face detection, sgie for predicting the age. You can define your own tensor output parser sources/libs/nvdsinfer_customparser.