Suppose we are given a set of equations of motion for $N$ bodies, which generically will go like this
\begin{equation} \frac{d^2\mathbf{r}_i}{dt^2}=\mathbf{F}_i \left((\mathbf{r}_i)_{1 \leq i \leq N}, (\frac{d \mathbf{r}_i}{dt})_{1 \leq i \leq N}, (\frac{d^2 \mathbf{r}_i}{dt^2})_{1 \leq i \leq N} \right) \end{equation} $\mathbf{r}_i$ is the position of body $i$ and $\mathbf{F}_i$ is just the sum of all the generalized force terms acting on it. $\mathbf{F}_i$ could depend on the positions $\mathbf{r}_i$ and velocities $\frac{d \mathbf{r}_i}{d t}$ of any of the other bodies, but also on powers of position and velocity, and even terms involving acceleration.
The question is: If we know $\mathbf{F}_i$, how can we know if this equations of motion can be derived from a lagrangian? Is there a systematic way to check that? Is there a systematic way of getting said lagrangian?