A U.S. District Court judge yesterday cleared the way for the federal government to try to seize all profits earned by former CIA agent Philip Agee from publication of two books which the government says violated Agee's secrecy agreement with the agency.

Judge Gerhard Gesell upheld the Justice Department's move to get at Agee through a Freedom of Information lawsuit that Agee himself filed in federal court here last October. The government had contended that by filing that suit, Agee had put himself within reach of U.S. courts for the first time since he left this country 11 years ago.

Agee's lawyers tried unsuccessfully to convince Gesell to allow them to abandon that suit and thus leave the government without a way to go after Agee for the profits from the books, "Dirty Work: The CIA in Western Europe" and "Dirty Work II: The CIA in Africa."

Agee's efforts to avoid the government's action came at about the same time the Supreme Court ruled that the government could collect the same kind of profits from former CIA officer Frank Snepp, who had signed a secrecy agreement similar to Agee's. The government alleged that Snepp published his book, "Decent Interval" without first submitting the manuscript to the CIA for pre-publication screening, as required under the agreement.

Gesell said yesterday that Agee's "change of heart resulting from the Snepp decision came too late." Gesell said that Agee could withdraw his lawsuit, but the government could still go ahead with its claim for his profits from the two books.

Agee's lawyer, Melvin L. Wulf, said in a telephone interview yesterday that there were "no profits" from the two books. Agee was the editor of the first book and a contributor to the second, Wulf said.

"They're [the government] not going to get rich off this case," Wulf said. He added that Agee would now not withdraw his Freedom of Information Act request. In that request, Agee is seeking all government records about him held by the CIA, the FBI, the State Department and other government agencies. Wulf said earlier that Agee wants the documents to prepare his autobiography.

Agee's lawyers had argued that it was against the public interest to allow the government to use a Freedom of Information Act request as a vehicle to press other claims against the person who filed the request.

Gesell noted however, that the government had argued that Agee wanted the court's help with his document request against the government agencies "so that he can further flout his continuing legal responsibility under the secrecy agreement." The government's move to stop Agee from further disclosures without CIA approval serves the public interest, Gesell said.

Agee's efforts to block the government's move became caught up in a procedural error when his lawyers failed to file appropriate notice with Gesell that they wanted to oppose the government's move to intervene in the Freedom of Information Act case. As a result, Gesell went ahead, on Feb. 21, to grant the government's request, and Agee followed with his action to abandon the lawsuit. Agee had also asked Gesell to vacate the Feb. 21 order, but Gesell refused the request yesterday.

Gesell said yesterday that it would be unfair to allow Agee to abandon his Freedom of Information Act request and thus "frustrate" the government's right to intervene in the case, which has been under way either in the agencies or at the judicial level for more than 26 months.