This paper presents a concrete software architecture dedicated to ambient intelligence (AmI) features and requirements. The proposed behavioral model, called Higher-order Agent (HoA) captures the evolution of the mental representation of the agent and the one of its plan simultaneously. Plan expressions are written and composed using a formal algebraic language, namely AgLOTOS, so that plans are built automatically and on the fly, as a system of concurrent processes. Based on a specific semantics, a guidance service is also proposed to assist the agent in its execution. Moreover due to the specific structure of AgLOTOS expressions, the update of sub-plans is realized automatically accordingly to the revising of intentions, hence maintaining the consistency of the agent.