The "spy" from Texas was shoved out into the cold after his camp learned about the 5 a.m. phone calls from the enemy. Maybe now Phil Gramm and David Stockman can talk about budget strategy at a normal hour.

Democrats on the House Budget Committee say they first became suspicious of Gramm when their confidential tactics started showing up in Office of Management and Budget director Stockman's briefing papers within hours of committee caucus meetings. Soon after, it appeared that Gramm was becoming as much of an outspoken booster of President Reagan's program as Stockman himself.

Finally Rep. Tom Downey (D-N.Y.) did the unthinkable: Last year he politely asked Gramm, a Democrat from Texas, to leave a closed meeting of the committee, accusing him of spying for the Republicans. Gramm was never invited back.

"We spend so much time being polite in the House that we were ignoring the fact that this guy was really harmful," said Downey. "Almost every step of the way he was acting as a Republican spy and obviously we were anxious not to let them know what we were doing. I said as long as he's working with the other side he has no right being in the caucus."

Last week the Democrats took their protests a dramatic step further.

For the first time in 70 years, the Democratic leadership voted to strip a member of his committee seat because of party disloyalty. Gramm, 40, was dumped from the powerful Budget Committee. He had been preparing to switch parties for the past six months and promptly resigned his seat to seek re-election as a Republican.

"Anyone who has ever watched a James Bond movie knows that to be a spy, you have to have a secret identity and I seem to fail on that count," said Gramm Saturday on the campaign trail in Dallas.

"It's all theatrics," said Stockman yesterday of the move by the Democrats. "Obviously they had to make a gesture to show that discipline was required. They didn't have discipline in the last Congress."

Often described as arrogant and headstrong by his detractors, Gramm is now also assailed as being a turncoat and attempting to use the situation for a lavish display of martyrdom. He says he is simply principled and is being chastised for following his own mind.

"The speaker said I cohorted with the enemy," said Gramm. "I never knew the president of the United States was the enemy. My high school civics class didn't teach me that."

Indeed, Gramm's patriotism seems to date back to his youth in Columbus, Ga.

One of his hobbies was collecting pigeons and dogs. So upset was young Gramm when one of his pets died that he would often give them formal military burials. Gramm would say the prayer service over the little graves while his stepbrothers fired BB-shot salutes into the air.

"Yes, that's true," said Gramm. "I did do that."

An honors graduate with a Ph.D. from the University of Georgia, Gramm was an economics professor at Texas A&M before entering Congress. But he wasn't always an achiever. He failed third, seventh and ninth grades.

"He's one of the smartest guys in Congress when it comes to understanding the budget," says Stockman. "He understands it better than anybody."

It was no secret that Gramm, the most strident of the "Boll Weevil" Democrats, and Stockman were old friends. The two even had co-authored budget resolutions when they served in the House together.

In fact, when Gramm angled to get on the Budget Committee, the Democrats thought it would help dialogue with the administration. After all, he and Stockman conferred often, sometimes daily, long into the evening and early morning hours.

Stockman called Gramm's reputation as a spy "absolute nonsense."

"They knew he was involved publicly and visibly; from the very beginning he supported the president's program. He brought 50 members down to the White House. He was working with us for the budget resolution . . ."

But Democrats argue that when Gramm wanted to get on the committee during the last Congress, he wrote letters to anyone who would listen, promising to support the final budget proposed by the Democrats.

Instead, Gramm joined forces with a Republican on the committee, Rep. Delbert Latta (Ohio), and together they offered a substitute budget, which passed on the House floor. Democrats sarcastically refer to it as the Stockman-Gramm bill.

"We won . . . we beat their ears back," said Latta, "and they didn't like it."

"My crime in the eyes of the leadership of the House was that I was trying to win, not just protest," says Gramm in his hard Texas drawl. "I was shooting with real bullets."

Soon it became apparent to the Democrats that there was too much dialogue between Stockman and Gramm. In the now famous Atlantic article, "The Education of David Stockman," the budget director indicated that Gramm was indeed his spy on the committee. Did Budget chairman Jim Jones (D-Okla.) know that one of his Democratic committee members was really on the other side, Stockman was asked? "No," he told reporter William Greider. "That's how I know what's in Jones' budget."

"From day one, he caucused with the Republicans and passed on confidential information," says Rep. Gillis Long (D-La.), chairman of the Democratic Caucus. "Now suppose Mr. Gramm was in the Dallas Cowboys' huddle and he told the opposing team what play was being called? Do you think they'd invite him to huddle again?"

"Gramm is now putting on this martyr act," says Downey. "He's not being punished for being a conservative. He used a position of privilege against his own party, actively and zealously. He served the interests of the other side as though the Republicans had planted a microphone in the meetings. But they didn't need to. They planted Phil Gramm instead . . . Phil should have always been a Republican."

The Republicans seem to think so, too.

"I feel he has been extremely loyal to the president and the first and foremost quality I look for is loyalty," says Lee Atwater of the White House political office. "I wouldn't say he was the most loyal member to Reagan, but he'd be tied for it. I can't think of anyone more loyal. I feel he's owed a debt of gratitude from here."

"I find what was done to him by the Democrats disgusting," says Atwater, "disgusting that there's no room for disagreements in that party."

Atwater said he cautioned Gramm about giving up his seat to run as a Republican at a time when the "Republican party is not at its zenith in Texas." Political observers note that Gramm's decision to run was based on the fact that, if re-elected, he would have greater credibility in Congress as a Republican. They are holding a budget committee seat open for him on the Republican side.

"I'm still going to be the same old dull person as a Republican--there's no difference," said Gramm. "I was a Democrat because my family were Democrats. But I was unwilling to let partisanship stand between me and what the people in my district elected me three times to do."

His district stretches from the suburbs of Dallas to the suburbs of Houston. In the 1982 election, Gramm triumphed in a three-way primary fight with 60 percent of the vote. He won with 94 percent of the vote against a Libertarian candidate in the general election.

Gramm first tried elected office in 1976 when he challenged Lloyd Bentsen for the Democratic nomination for the Senate and lost with 28 percent of the vote. But when Olin Teague retired from the House two years later, Gramm's profile was sufficiently high to make a run for the seat worthwhile.

Both friends and detractors say Gramm was never a team player, never one of Congress' good ol' boys. Two high-ranking Hill aides said Gramm always tried to give the impression of knowing more than anyone else about economics. Several years ago, when he was testifying before the Rules Committee, he made the mistake of telling the committee he was the only formally trained economist in Congress. Then committee chairman Rep. Dick Bolling (D-Mo.) promptly listed the other in-House economists.

"I find Phil consistent and honest," said Rep. Buddy Roemer (D-La.), a fellow Boll Weevil, "but he is not a very good politician in the sense that he had no time for handshaking and backslapping. It was refreshing that he was so nonpolitical, but it always hurt him. One person can never do important legislation alone . . . Phil spent more time on the principles and particulars than on team development. That hurt him when it came to feeling of camaraderie with the other members."

But Gramm has always been something of a rebel. When he was 15 his mother sent him away to the Georgia Military Academy after he and some friends took her Plymouth on a joy ride.

His wife Wendy is an economist for the Federal Trade Commission and they have two young sons.

They have always been Democrats.

"Oh, I'm going to stay a Democrat," says Wendy Gramm. "I'm going to vote Democrat in the primary. But I think it's safe to say I'll vote for Phil in the general election."