In this paper, we describe how SMARTBASEG, a knowledge-based architecture, can optimize dynamically data mining (DM) applications for the Grid. SMARTBASEG can be seen as a layer that intercepts the submission of a DM application to the Grid, identifies the procedures to be paralleled and optimizes the composition of the job to be submitted to the Grid. The job composition process is done by means of a problem solving method (PSM) of configuration that adopts a propose-and-revise strategy. We present our approach by describing formally the implementation of the PSM in SMARTBASEG and by exemplifying the representation of heuristics for DM application optimization by means of constraints and repairs. Finally, we show the preliminary results we have obtained in some experiments.