Let $\mathrm{d}r_t=\mu(t,r_t)\mathrm{d}t+\sigma(t,r_t)\mathrm{d}W_t$ be a model for the short rate under the risk-neutral measure $\mathbb{Q}$. Starting from the bond PDE
\begin{align*}
P_t + \mu(t,r) P_r + \frac{1}{2}\sigma(t,r)^2P_{rr} -rP=0,
\end{align*}
subject to $P(T,T)=1$ whose general solution is $P(t,T)=\mathbb{E}^\mathbb{Q}\left[e^{-\int_t^T r_u\mathrm{d}u}\mid\mathcal{F}_t\right]$ (siehe Feynman Kac).
To get an ATS model, you now ``guess'' that $P(t,T)=e^{A(t,T)+r_tB(t,T)}$ with
\begin{align*}
P_t(t,T) &=\big(A_t(t,T)+r_tB_t(t,T)\big)\cdot P(t,T), \\
P_r(t,T) &= B(t,T)\cdot P(t,T), \\
P_{rr}(t,T) &= B(t,T)^2\cdot P(t,T).
\end{align*}
Pluggig this into the above PDE, you get
\begin{align*}
A_t(t,T) + \mu(t,r) B(t,T) + \frac{1}{2}\sigma(t,r)^2B(t,T)^2 +(B_t(t,T)-1)r &=0.
\end{align*}
The terminal boundary condition becomes $A(T,T)=B(T,T)=0$.
In the Vasicek case, $\mu(t,r_t)=\kappa(\theta-r_t)$ and $\sigma(t,r_t)=\sigma$. Thus,
\begin{align*}
A_t(t,T) + \kappa \theta B(t,T) - \kappa r B(t,T) + \frac{1}{2}\sigma^2B(t,T)^2 +(B_t(t,T)-1)r &=0 \\
\implies A_t(t,T) + \kappa \theta B(t,T) + \frac{1}{2}\sigma^2B(t,T)^2-(1-B_t(t,T)+\kappa B(t,T))r &=0.
\end{align*}
This equation needs to be satisfies for all $r$. Thus, you obtain the following system of (first-order ordinary differential) equations
\begin{align*}
\begin{cases}
A_t(t,T) + \kappa \theta B(t,T) + \frac{1}{2}\sigma^2B(t,T)^2 &= 0, \\
1-B_t(t,T)+\kappa B(t,T) &= 0,
\end{cases}
\end{align*}
subject to $A(T,T)=B(T,T)=0$. You now solve the second equation first in closed form and then, with this result, you can solve the first equation. You then arrive at the standard Vasicek bond price formula.