In the standard excursion set model for the growth of structure, the statistical properties of haloes are governed by the halo mass and are independent of the larger scale environment in which the haloes reside. Numerical simulations, however, have found the spatial distributions of haloes to depend not only on their mass but also on the details of their assembly history and environment. Here we present a theoretical framework for incorporating this "assembly bias" into the excursion set model. Our derivations are based on modifications of the path integral approach of Maggiore & Riotto (2010) that models halo formation as a non-Markovian random walk process. The perturbed density field is assumed to evolve stochastically with the smoothing scale and exhibits correlated walks in the presence of a density barrier. We write down conditional probabilities for multiple barrier crossings, and derive from them analytic expressions for descendant and progenitor halo mass functions and halo merger rates as a function of both halo mass and the linear overdensity of the larger-scale environment of the halo. Our results predict a higher halo merger rate and higher progenitor halo mass function in regions of higher overdensity, consistent with the behavior seen in N-body simulations.