Fixed function to find existing agent, passing list to function and filtering it properly