The only man convicted of espionage while serving as an agent of the Federal Bureau of Investigation was sentenced today to 20 years in Federal prison.

In sentencing the former agent, Richard Miller, Judge Robert Takasugi of United States District Court also criticized the agency for allowing Mr. Miller to stay in his post when he showed clear weaknesses.

"Mr. Miller betrayed the national trust placed upon him in his duty with the foreign counterintelligence squad of the F.B.I.," Judge Takasugi said. "Yet I wonder why the agency allowed him to serve in that capacity when it knew of his susceptible qualities." 'Totally Out of Control'

Judge Takasugi said Mr. Miller "was clearly out of control."

"In fact," he added, "Mr. Miller was totally out of control."