In what was loosely called a "historic occasion," four former secretaries of agriculture yesterday were asked for their advice on what to do about the nation's farm problems.

The four, who served under six presidents, clearly enjoyed the momentary return to the spotlight. Charles F. Brannan, an elegant man in his 70s who served under Harry S. Truman, said he couldn't remember anyone ever gathering as many agriculture secretaries together at one time.

Three told the Joint Economic subcommittee on agriculture that the nation's current farm problems are not susceptible to government solution, but are also temporary. The fourth, Brannan, said they may not be temporary but long-term, in that the marketplace now seems unable to give farmers a fair return.

"There's no quick fix. There's no instant cure," said Bob Bergland, who served under Jimmy Carter. "In the short run, I don't think that anything government can do will change matters."

He also said the commodity price support program pushed through Congress by the Reagan administration last year is "probably about on track," and that there is a need to change the government's rural farm credit programs as Ronald Reagan has proposed.

"In times like these, there's a temptation to panic, a temptation to yield to pressure," said Earl Butz, who served in the administrations of Richard M. Nixon and Gerald R. Ford. "I think we're on the right track . . . . I think we're doing precisely the right thing, holding the line and being tough."

The joint appearance came at a time of monumental farm problems. Sen. James Abdnor (R-S.D.), chairman of the subcommittee, said projected farm income for this year is at its lowest point in history after adjustment for inflation, that farm debt has doubled during the last five years, and that thousands of farmers are experiencing severe cash flow problems.

Brannan, a Denver lawyer and counsel to the National Farmers Union, said farm conditions are "in almost as tragic circumstances as in the early 1930s" and more farms may be lost to foreclosure this year than any time since the Depression.

Brannan and Orville Freeman, who served under John F. Kennedy and Lyndon B. Johnson, said that extension of subsidized credit may be the only short-term salvation for many farmers. They also urged Congress to enact strict acreage limitations to force a reduction in agriculture production, a policy abandoned years ago because of strong opposition from farmers.

"Credit is essential if we're going to save many good, efficient farmers," said Brannan, adding that he thought grants should be made to cover the high cost of borrowing money to stay in business.

Freeman, a former Minnesota governor who now heads an international consulting firm, said that John R. Block, the current agriculture secretary, "ought to tell the Farmers Home Administration to take on a case-by-case basis the liberal side and not the collection side" on all loans because "we've got a rural emergency."

In some ways, yesterday was a showcase for the past. Brannan dusted off a crop support program he had recommended in 1949 for discussion. Butz brought a loaf of bread to the hearing, just as he did while in office to dramatize his contention that too much of the food dollar goes to middlemen and not enough to farmers.

But each of the former secretaries admitted things weren't like they used to be.

Butz, for example, complained he no longer had a staff to prepare written testimony for the hearing. Brannan said it was the first time he could recall going before a congressional panel when "I didn't fear my testimony would affect my appropriation."