Action and Perception in Agent Programming Languages: From Exogenous to Endogenous Environments