use the addKeyToAgent method for KeyModel. Also add a check of EOF in addKeyToAgent under linux/Mac