Allow cloning an existing agent.

This is an implementation of #270.