We propose a general mathematical methodology for studying the dynamics of multiagent systems in which complex collective behavior arises out of local interactions between many simple agents. The mathematical model is composed of a system of coupled differential equations describing the macroscopic, or collective, dynamics of an agent-based system. We illustrate our approach by applying it to analyze several agent-based systems, including coalition formation in an electronic marketplace, and foraging and collaboration in a group of robots.