The observation of gamma ray bursts and terrestrial gamma-ray flashes with AGILE