Only 10 percent or less of American criminal cases are resolved by trials. The criminal trial is based upon the adversary system. The defense lawyer vigorously represents his/her client, whether or not he believes him/her guilty. The prosecutor represents the state and the people, but also bears an ethical responsibility to act as a minister of justice.
The Constitution requires that, in order to find the defendant guilty, the fact-finder, whether jury or judge, must determine that the prosecution has proven every element of the offense beyond a reasonable doubt. This is the meaning of the oft-quoted maxim that the "defendant is presumed innocent."
Both sides have the right to call their own witnesses and to subpoena witnesses who will not appear voluntarily. The lawyers subject their own witnesses to direct examination and the other side's witnesses to cross-examination. The judge, but not the jurors, may ask the witnesses questions, but under the American adversary system, the lawyers ask practically all the questions and the judge acts as an impartial umpire. A witness may refuse on Fifth Amendment grounds to testify if he/she has a well-founded belief that the testimony could incriminate him/her. The prosecution may grant the witness immunity and then may compel the witness to answer every question. (The defense has no such power.) Immunity extends to any crime the witness admits to as well as to any crime that investigators uncover as a result of the witness' immunized testimony.