How to solve a model with heterogeneous agents?

I was wondering if Dynare itself can solve a model with a distribution of heterogeneous agents, without the help of external files. If so, could you recommend an example to learn fro?

Say individual’s state variable includes their wealth, like asset or capital holdings. And every agent faces a probability of dying. So their assets evolve over time. And their decision rules depend on assets, maybe in a non-linear way. I notice there are some coded purely in dynare but focused on the aggregate variables. If I want to track individual’s behaviour, how can I do it? Sorry for an abstract description.

The general answer is: No. If there is heterogeneity, you need to become creative. You may want to take a look at the JEDC special issue at The Kim/Kollmann/Kim approach is easily implementable in Dynare.

I want to take a step back. How is heterogeneity defined? I am actually asking which aspect of heterogeneous agents makes it hard to solve the model. Except purely for tracking individuals’ paths, is it because discontinuity in policy functions and law of motion, e.g. default, that also makes solving aggregate variables complicated?

It’s about whether aggregation is possible or not. If you cannot easily aggregate up, you need to keep track of the distribution (typically the wealth distribution). Distributions are infinite dimensional objects (you need all moments from 1 to infinity to fully characterize a distribution). Dealing with this infinite dimensional object is what makes it so hard.
In many representative agent models, there is a continuum of agents, but their consumption and thus wealth is perfectly insured via Arrow-Debreu securities. In this case, every agent will always have the same wealth at the end of the period, even if there are idiosyncratic shocks that only hit some agents. Take away complete markets and some agents will have positive shocks while other will have negative ones. In this case, they will choose different assets at the end of the period. You would need to keep track of this. If you only assume two types, this is doable. If there are infinitely many, it quickly becomes intractable.