Reagan administration and congressional negotiators are close to cementing a deal to reduce the fiscal 1988 federal deficit by about $31 billion that will include some reductions in cost-of-living increases for federal employes and retirees including Social Security beneficiaries.

The emerging agreement is expected to be completed early next week and announced by Thursday. It developed just a day after the talks appeared to founder amid partisan accusations of bad-faith bargaining.

"We're close on the numbers; they'll come together," said one congressional source yesterday after a 90-minute meeting between congressional leaders and administration officials in the Capitol.

Budget analysts from Capitol Hill and the Reagan administration were told to spend this weekend translating the overall policy agreements reached yesterday into tangible numbers to ensure that the framework produces the expected reductions in the federal deficit.

"We're talking numbers, not concepts anymore," said one participant in the talks.

The agreement would include about $10 billion in higher taxes, defense spending reductions of between $4.5 billion and $5 billion, cuts in entitlement programs such as Medicare of another $5 billion and reductions in domestic discretionary spending of $2.7 billion. The remaining savings would come from prepayment of rural electric cooperative loans, user fees, interest on the national debt and more vigorous collection of income taxes.

A key component of the $5 billion savings in entitlements -- those federal programs that automatically confer benefits based on existing law such as farm programs, veterans' benefits and student loans -- will be a $2 billion reduction in cost-of-living increases.

Among the specific mechanisms under discussion to save that $2 billion is a delay of three months in the payment of cost-of-living adjustments (COLAs) to federal employes, civilian and military retirees of the government, and Social Security recipients.

Sources said that the three principals who are key to any agreement -- President Reagan, House Speaker Jim Wright (D-Tex.) and Senate Majority Leader Robert C. Byrd (D-W.Va.) are on board. Some thought is being given to a joint announcement by the three leaders in which they could all claim bipartisan credit.

The sudden turnabout yesterday in the talks from Thursday reflected, in part, a new urgency at the White House in the wake of the Oct. 19 stock market collapse and the release of new, more favorable trade deficit figures this week. Administration figures believe that the combination of the new trade figures and a budget deal with Congess would produce a favorable response in world financial markets.

One White House official said the negotiators had missed an opportunity earlier this week "to strike an agreement when we had some good news on another front."

Yesterday's meeting followed an acrimonious session Thursday when some Democrats accused White House negotiators of suddenly reversing their bargaining position by demanding lower taxes, higher defense spending and deeper domestic cuts than they had previously indicated were acceptable. White House chief of staff Howard H. Baker Jr. vehemently denied those charges.

Against that background, yesterday's session began on a sour note that quickly turned into an opportunity, according to one congressional source.

"It started off pretty rough this morning," said the source. "But then they realized they were at the point of blowing the whole thing, that they were on the precipice. It took them getting scared out of their wits."

Officially, negotiators yesterday were upbeat but cautious. "I'm very encouraged, but there's no agreement yet," Sen. J. Bennett Johnston (D-La.) said. "I think there's real progress, there's a narrowing of the differences and a real cause for optimism."

One remaining hurdle, according to a person familiar with the talks, is devising "enforcement mechanisms" to lock in the savings in discretionary domestic and military accounts for a two-year period.

The evolving agreement calls for a two-year reduction in the deficit, with the second-year savings significantly higher than those in the first. Because Congress appropriates about half the federal budget on an annual basis, a means must be found to guarantee the second-year savings.

"If the cuts aren't real for two years, we have a problem," the source said.

Also yesterday, House Majority Leader Thomas S. Foley (D-Wash.) said that if a deal is achieved, Congress will probably postpone -- perhaps for several weeks -- the Friday deadline for the $23 billion in across-the-board spending cuts mandated by the Gramm-Rudman-Hollings balanced-budget law.

Under revisions to the law adopted in September, those cuts go into effect Nov. 20 unless Congress and the White House have agreed by that time on alternate ways to reduce the deficit by $23 billion.