Agent-based models (ABMs) are a new and increasingly popular class of simulation software in natural and social sciences. They combine state-based and behaviour-based modelling paradigms for empirical phenomena in an unorthodox way that currently has no sound theoretical foundation. As we have demonstrated in previous work, the state/behaviour dichotomy can be formalized as algebraic/coalgebraic reasoning, respectively. In the present work we reformulate agent-based models in terms of an established theory that combines algebraic and coalgebraic perspectives, namely the theory of bialgebras induced by a categorical distributive law. This has a number of interesting consequences: 1.) From the viewpoint of software engineering, it allows the rigorous derivation of a clear and modular design for agent-based models in a functional programming language. 2.) From the viewpoint of (co)algebra theory, it opens a wide field of hitherto unknown real-world applications. 3.) From the viewpoint of software semantics, it allows to postulate a theoretical criterion for well-behaved ABMs. 4.) Last but not least, from the viewpoint of critical science, it allows to elucidate the way the modelling paradigms are mixed, and possibly confused, in ABM literature. We present the results of our work in progress in terms of a theoretically guided re-implementation of a published ecological ABM (Jovani and Grimm: "Breeding synchrony in colonial birds: from local stress to global harmony." Proc.R.Soc.B 2008) in the programming language Haskell.