It's a matter of state law, but in general sentencing is left to the court. The prosecution and defense can reach an agreement on regarding what the defendant will plea (i.e., guilty) and what charges will be brought (e.g., battery, but not a more serious charge). The deal can make a recommendation as to sentencing, but the judge is not bound by it. Typically (though it may vary by state) a judge will explain this to a defendant before the plea is entered. Basically the judge will say something along the lines of "you understand that while you are pleading guilty and the prosecution is recommending sentence X, I am not bound to impose sentence X and can, in fact, impose a greater sentence."