A classic method to compute the mass function of dark matter halos is the excursion set method, where the density perturbation evolves stochastically with the smoothing scale, and the problem of computing the probability of halo formation is mapped into the so-called first-passage time problem in the presence of a barrier. To date, however, analytical results were only obtained assuming that the density perturbations performs a markovian random walk, which however is not the case for non-Gaussian primordial fluctuations (and in fact is not true even for Gaussian primordial fluctuations). In a recent series of papers with A. Riotto we have generalized the classical excursion set theory to non-markovian dynamics, and we have computed the halo mass function for both gaussian and non-Gaussian initial fluctuations. Our analytical results reproduce remarkably well the results of cosmological N-body simulations.