ERROR: Leads and lags on variables are forbidden in ‘planner_objective’
Is there a way of introducing lags in the planner objective? If not, how can I get an equivalent function?

Second, does anyone know whether it is possible to compute ramsey policy in Dynare for a model that uses external funtions? When I change the objetive equation to avoid the lags problem and use this command

Regarding the second error, I would need to see the file. Regarding the first issue: you can circumvent the problem by defining a lagged variable in the model:

cons_lag=cons(-1)
and then writing the objective as

This is a limitation of Dynare, see https://git.dynare.org/Dynare/dynare/issues/300
You are calling external functions and for this optimal policy problem, the third derivatives would be required.

Ok. So the only way would be then to compute the third derivatives by hand and then indicate to dynare in some way which they are, right? or is there an alternative?