Michael Blutrich's book Scores describes how he acted as an FBI confidential informant against the Gambino mafia family and was then screwed over by the government, ending up with a long prison sentence and no witness protection.
Mr. Blutrich was under federal investigation in Florida for a bankrupt insurance company and in New York for mob influence in the strip club Scores which he was co-owner. Read the book to see all the details, a couple things hit me about dealing with the government after reading the book.
The first comes from the Florida insurance case. When Blutrich and others were indicted he says (In think in hindsight) that the prosecutors did it too early. If he had let himself be arrested and arraigned (starting the "speedy trial" clock) the prosecution would not have been able to have its case ready in time. He instead made a deal which ended up not starting the trial clock.
The second is from the overall result of the case -- the prosecutors didn't do anything they promised and the judge didn't accept the government's plea bargain, imposing a much longer sentence.
From this, a few rules when dealing with the government:
First, get it in writing. A verbal agreement is little better than no agreement at all. Recently published plea agreement relating to the Trump / Russia scandals shows that written agreements are possible, so any plea or cooperation agreement should be in writing. It's still possible that the agreement will be ignored, but less likely than a verbal agreement.
Second, everybody needs to sign the agreement. Much of Mr. Blutrich's problem was a Florida prosecutor who didn't like confidential informants and who was never really in agreement over the deals being done. A written agreement signed by all parties might make it harder to ignore the agreement.
Third, don't delay the trial. If Mr. Blutrich had started the trial clock and opposed all attempts at delay he might have left the government in a situation of having to prosecute an incomplete case (acquittal more likely), drop the indictment, or accept a light sentence in order to avoid losing the case. The government has a lot of power and influence over individuals, rushing the government might force it to accept better terms.
Government officials, whether police, prosecutors, or judges, often make mistakes. I've seen this many times from news stories or books. I've also seen it first hand when I was chosen for a jury, then the case was plea bargained, and the judge came in and basically told us (in polite terms) why the prosecutor was an idiot.