At the crucial hours of Bendix Corp.'s fight to escape the trap its takeover war had become, the closest adviser at the side of Bendix Chairman William Agee was his wife, Mary E. Cunningham, sources say.

Cunningham, a vice president of Joseph E. Seagram and Sons and Agee's former assistant and confidante at Bendix, was with Agee in the final negotiations with the leaders of Martin Marietta Corp. in Bethesda earlier this week, when both companies were trying to find a painless way out of their mutual takeover struggle, sources said.

Those negotiations broke down abruptly about midnight Tuesday, when some Martin Marietta directors concluded they were legally obligated to go ahead with their offer to buy half of Bendix shares. The breakdown apparently left Agee with no alternative but to sell Bendix to Allied Corp., according to sources close to the merger fight.

Cunningham's presence reportedly irritated the Martin Marietta side, sources said, whether or not it was a factor in the final outcome. "Marietta resented it deeply," said one source. "I understand they weren't pleased," said another. A first-hand reaction of the Marietta principals could not be determined yesterday, as the major players remained out of reach.

Some close to the negotiations say the outcome is a devastating failure of a dream shared by Agee and Cunningham -- to run a major corporation together as husband and wife.

Cunningham, who married Agee last June, had discussed her hopes for herself and Agee in an interview in Parade magazine in April. She recalled her teamwork with Agee at Bendix, where she was vice president for planning until the controversy about their relationship caused her to resign in October 1980.

"I'd love to share that with Bill again, and the one question we have is: Shouldn't it be our own company this time, because we bring so much to the situation?"

For more than two years, Agee had been preparing to launch Bendix on a major acquisition program. He had gathered more than $500 million in cash and securities by selling off Bendix businesses that no longer fit in with his long-term plans and held that ready to finance new corporate purchases. Many observers gave Agee credit for a skillful redirecting of Bendix's lines of business.

Then came the move to take over Martin Marietta that apparently exploded on Agee yesterday. Only he and Mary Cunningham know whether his plan included a place for her in the combined Bendix-Martin Marietta. Her presence with Agee at meetings this week in Bethesda and in New York with Bendix investment advisers has triggered that speculation.

A Seagram source who asked not to be identified said that "whatever she was doing, it was as Bill Agee's wife . . . Clearly Bill Agee respects her judgment. It's not surprising that he reached out to her again."

At Joseph E. Seagram & Sons in New York, the U.S. subsidiary of the Canadian company, Cunningham has been vice president for strategic planning and product development, primarily responsible for planning Seagram's ventures in the wine business.

The apparent failure of Agee's move will not hurt her reputation at Seagram, where Cunningham, like most executives, has both supporters and detractors, this source predicted. "My guess is that Mary's reputation is already made at Seagram's. The fact that she was with her husband in this rather fierce situation would be understood, I think, by the people whose respect is most important for her."