## 2 Methods  
The spin-restricted DFT calculations were performed using the DMol\({}^{3}\) module [42]. The exchange-correlation function was evaluated approximately using the Perdew-Burke-Ernzerhof (PBE) method, derived from the generalized gradient approximation (GGA) [43]. The cutoff radius for all the structures was set to 5.0 A. The DFT semi-core pseudopotential (DSSP) was utilized to handle core electrons, and the double numerical polarization (DNP) basis set was employed for valence electrons. For periodic WS\({}_{2}\) structures, a Monkhorst-Pack k point grid of 10 \(\times\) 10 \(\times\) 1 was used [44]. Given the weak interactions associated with gas adsorption, the long-range forces were accounted for using the Tkatchenko-Scheffler dispersion correction [45]. Convergence in the geometric optimization process was considered achieved when the energy difference reached 10\({}^{-6}\) Ha (1 Ha = 27.21 eV), the maximum force reached 0.001 Ha/A, and the maximum displacement of all atoms reached 0.005 A. To prevent interlayer interactions, a vacuum slab of 15 A was incorporated along the \(z\)-axis. The WS\({}_{2}\) supercell was constructed using a 4 \(\times\) 4 super cell arrangement. To obtain the Ag-doped WS\({}_{2}\) monolayer, one S atom was replaced by an Ag atom, with Ag forming bonds with three adjacent W atoms. The adsorption energy (\(E_{\text{a-}Ag}\)) of the Ag atom on the defective WS\({}_{2}\) was:  
\[E_{\text{a-}Ag}=E_{\text{Ag-WS${}_{2}$}}-E_{\text{WS${}_{2}$ with S vacancy}}-E_{\text{Ag atom}} \tag{1}\]  
where \(E_{\text{Ag-WS${}_{2}$}}\), \(E_{\text{WS${}_{2}$ with S vacancy}}\), and \(E_{\text{Ag atom}}\) represent the total energy of Ag-WS\({}_{2}\) monolayer, WS\({}_{2}\) monolayer with one S vacancy, and one isolated Ag atom. In order to obtain the adsorption strength of one gas molecule (CO, NO\({}_{2}\), and SO\({}_{2}\)) on Ag-WS\({}_{2}\), the adsorption energy can be obtained by:  
\[E_{a}=E_{\text{Ag-WS${}_{2}$/gas}}-E_{\text{Ag-WS${}_{2}$}}-E_{\text{gas}} \tag{2}\]  
where \(E_{\text{Ag-WS${}_{2}$/gas}}\) and \(E_{\text{gas}}\) are the total energy of Ag-WS\({}_{2}\) after one gas molecule adsorption and the isolated gas molecule. All the charge calculations were based on Hirshfeld analysis [46]. The charge transfer (\(Q_{\text{t}}\)) of gas adsorption was:  
\[Q_{\text{t}}=Q_{\text{ads-gas}}-Q_{\text{iso-gas}} \tag{3}\]  
where \(Q_{\text{ads-gas}}\) and \(Q_{\text{iso-gas}}\) are the charges of the adsorbed gas molecule and isolated molecule. From the formula, it is found that the negative value indicates the role of the electron acceptor of the gas molecule and vice versa. The charge density difference (CDD) can be calculated as:  
\[\Delta\rho=\rho_{\text{Ag-WS${}_{2}$/gas}}-\rho_{\text{Ag-WS${}_{2}$}}-\rho_{ \text{gas}} \tag{4}\]  
where \(\rho_{\text{Ag-WS${}_{2}$/gas}}\), \(\rho_{\text{Ag-WS${}_{2}$}}\), and \(\rho_{\text{gas}}\) are the electron density of Ag-WS\({}_{2}\) monolayer after adsorption, Ag-WS\({}_{2}\) monolayer before adsorption, and isolated molecule, respectively.  
Considering the sensing properties, the work functions (\(\Phi\)) of Ag-WS\({}_{2}\) before and after adsorption was calculated as follows:  
\[\Phi=E_{\text{vacuum}}-E_{\text{Fermi level}} \tag{5}\]  
where \(E_{\text{vacuum}}\) and \(E_{\text{Fermi level}}\) are the energy of vacuum level and Fermi level of Ag-WS\({}_{2}\) before or after adsorption.