Added error handling to agents.