Perhaps one consistent aspect of the human condition is the innate struggle to achieve an idealized mental state. At each point in our consciousness, we have a goal, and we seek to meet that goal. The problem is that we always never meet those goals. There is always error, and we cannot stand it.
Our minds then try to reduce this error through adaptation. One method of adaptation is to change the goal so that it is closer to what we can achieve. This can be realized by having a modified goal, or a completely new goal. Interestingly, having a "no goal" state is in itself an idealized goal which can result in error when we seek to achieve it. Another adaptative method is to change the way we achieve the goal. We can re-analyze our previous behavior to reason which actions led to more or less error, and modify those behaviors accordingly.
Formal representations of this heuristics can easily be implemented. However, the question remains as to how the goals come to be about. Contribution from environmental and genetic forces can then be considered this level.
Final resolutions will either be that no error, or goal-relative perfection, is achieved, or else the ability to adapt is halted.