American Telephone & Telegraph Co. and the Reagan administration announced yesterday that they have agreed to change their divestiture plan for the Bell System to meet the objections of a federal judge.

The announcement means that the largest corporate breakup in U.S. history will take place within 18 months, with AT&T spinning off its 22 local operating companies -- about two-thirds of its $138 billion in assets. In return, AT&T will be allowed to enter the computer business from which it has been barred for the past 26 years.

Both AT&T and the Justice Department said they will accept the ruling of U.S. District Court Judge Harold H. Greene ordering major changes in the divestiture plan signed by AT&T and the Justice Department on Jan. 8.

Greene, who must approve the historic agreement, said last week that he would not sign the divestiture plan unless the parties made several changes to give AT&T's emerging competitors a fairer chance in the telecommuncations market and to protect telephone customers from steep local rate increases and a decline in service. Greene said that, if both sides failed to agree to his changes, he would resume the government's eight-year-old antitrust suit, which the agreement was designed to end.

"Because the alternatives available would pose unacceptable costs to the public interest, including delay in the reorganization process, the United States is prepared to agree to the court's revisions," the Justice Department said.

Even so, the department urged Greene to change his order to bar the divested local companies from selling sophisticated business telephone equipment.

Under the initial divestiture plan, the local phone companies would have been barred from selling any telephone equipment. Greene, however, ordered that this restriction be lifted, saying that competition would be so great that the local companies would be hard-pressed to use their monopoly over local phone lines to keep competing equipment suppliers out of the market.

Justice Department officials disagree, however, saying "there is a very substantial competitive danger in allowing" the local telephone companies to sell sophisticated telephone equipment.

They argue that the local phone companies would be able to thwart installation, maintenance and repair of the complex telephone equipment sold by their competitors. Additionally, they contend that the local companies could raise local rates to subsidize the sales of telephone equipment in an effort to undercut competitors.

As a result, the Justice Department is asking that Greene bar the local companies from selling sophisticated equipment until the local companies prove that their entrance into this business activity would not hurt competition. However, the department said that it still would permit the local companies to sell the simple phone used in most homes and many small businesses.

The Justice Department's request immediately was praised by telephone equipment manufacturers, who last week faulted Greene for allowing the local companies to continue selling equipment. "This would help correct a big error" that could have threatened to drive many small equipment companies out of business, said Walter Loewenstern, a vice president of Rolm Corp.

However, state regulators said they were opposed to the Justice Department's proposal because it could hurt the local companies' financial viability because it would reduce the amount of revenue they would receive -- and thereby could result in higher local rates for local users.

Justice Department officials said that, even though they regard this change as significant, they still would sign the settlement if Greene ruled against them. "Whatever the judge's decision as to this requested change . . . we would, in any event, accept the revisions" ordered by the judge, said Deputy Assistant Attorney General Ronald G. Carr.

AT&T also said it could live with whatever the judge decided on this issue, although it does not support the restriction on equipment sales sought by the Justice Department.

There was no indication from Greene on just how soon he would act on the Justice Department's request. However, last week he said he would sign the agreement and drop the government's antitrust suit immediately after a revised divestiture plan was submitted to him.