The caboose is headed for the last roundhouse.

The venerable piece of Americana that has brought up the rear of countless trains for more than a century is headed for extinction, replaced by a shoebox-size microelectronic monitor -- most of them built in Rockville, Md. -- designed to do the work traditionally entrusted to a crew member perched in the caboose's cupola.

"We're replacing a manned caboose that weighs 25 tons and costs $70,000 with an automatic 35-pound black box that costs about $4,000," said Dick Tincher, an executive with the Union Pacific, which is buying hundreds of the electronic monitors, which indicate whether the train and its air brakes are working properly.

But as in other confrontations between man and microchip, this leap into the future has not been entirely smooth. The caboose question has become a major economic and political battle.

Prodded by rail unions, three federal agencies, including a special inquiry board set up by President Reagan, have contemplated the caboose controversy. All three eventually agreed that the caboose is an anachronism.

Now the United Transportation Union has mounted an all-out lobbying campaign in state legislatures to save the caboose -- and the jobs of crew members who ride it.

Four states have passed mandatory-caboose laws for freight trains within their borders, and perhaps 10 other legislatures are pondering similar bills in the current session.

But all this activity may merely be delaying the inevitable.

"Five years, maybe eight years from now, and you won't ever see a caboose," said Tincher. Even A.W. Westphal of the United Transportation Union conceded that "the caboose is probably doomed unless we get some regulatory or legislative changes pretty fast."

The beneficiaries of this change would be the railroads, which would save $400 million annually in maintenance and fuel costs, according to the Association of American Railroads. Also benefiting would be a handful of inventive new companies that have brought the glamour of high-tech electronics to the workaday world of the freight yard.

The largest U.S. supplier of the microelectronic train-end monitor is Pulse Electronics on Frederick Avenue in Rockville.

Pulse was started in 1977 by a pair of Cuban refugees, Emilio Fernandez and Angel Bezos, who knew both microelectronics and railroading. Today their privately held company has 100 employes and offers a full line of train-monitoring gear.

Pulse is selling its caboose replacement -- called Trainlink -- to Union Pacific, Burlington Northern and other roads.

Mark Kane, marketing director at the Rockville firm, has ambitious dreams for Trainlink. "It's got to be a multimillion-dollar product," he said. "There are 12,000 cabooses out there now, and every one is going to be replaced with this technology."

Modern Railroads magazine lists four other U.S. companies selling versions of the microelectronic caboose. Ironically, it reports that Conrail, the U.S. government-owned freight line, is buying its rear-end monitors from a Canadian company.

Caboose history is somewhat shrouded in mystery, but, according to rail historians, the friendly little car with the cupola probably was invented about 1850 when trains were getting so long that the crew could not watch every car from the engine.

At first, the railroads erected a wooden shanty on a flatcar and hooked it to the rear of the train. This makeshift car eventually was named the caboose, evidently from the Dutch word "kabuis," meaning "cabin house."

Railroad men have battled for years over the proper plural of this term. "Cabeese" was the accepted form for some time; "cabooses" seems to be standard now.

The caboose matured into a separate car, serving as the train's office, where the conductor kept records of his freight, and as a rolling dormitory for the crew.

Around 100 years ago, railroads added the cupola -- a raised, windowed box sticking out of the caboose's roof. A crew member, either the conductor or the rear brakeman, was assigned to sit there and keep an eye out for derailments, dragging equipment and overheated axles, called "hot boxes."

In later years, some railroads opted for bay windows on the side of the caboose rather than a cupola.

Over time, however, many of the caboose's functions were rendered unnecessary. With computerized record-handling, train personnel no longer needed a rolling office. Changing work rules meant crews no longer spent the night on the caboose.

Most railroads placed electronic monitors every 50 miles or so along the track to detect dragging gear and "hot boxes," making the brakeman in the cupola less important.

Gradually, the railroads concluded that the expense of buying and maintaining the caboose, and the fuel used in hauling the 25-ton car across the continent, could no longer be justified.

In 1982, during the last national rail labor negotiations, the railroads made a major push to kill the caboose.

After a bitter fight and referral to a special presidential fact-finding board -- which sided with the railroads -- the unions agreed that cabooses could be dropped on all local trains, trains making deliveries within an urban area and 25 percent of cross-country freight hauls, pursuant to local bargaining agreements.

When the engineers at Pulse Electronics heard about this, "a light bulb went off in our heads," said Kane, the marketing director.

Pulse had been working on an electronic gadget that could monitor train activity and send radio reports forward to the engineer in the locomotive.

With the pending demise of the caboose, such equipment would have a market.

Pulse Electronics' "Trainlink" is the best-selling caboose replacement. Most of the devices from all the companies feature sensors that constantly measure the train's air-brake pressure and the motion of the rear car.

Knowing rear-car motion is important because slack in the couplers between cars can allow a train to act like an accordion, building up forces that can break the train in two.

Two major functions of a caboose crew have been to monitor whether the air brakes are functioning and whether the engineer is handling the train smoothly.

Railroad officials claim that this electronic monitoring system is more reliable, and thus safer, than the brakeman in the cupola. The rail unions and their allies in the state legislatures vigorously dispute this.

"I think this effort is one of sacrificing safety to reduce crew size and maintenance cost," said Rex Black, a former freight engineer who now is minority leader of the Utah state Senate and sponsor of a pending mandatory caboose law here.

"They're running these mile-long trains, many of them with hazardous cargo, and there's no person back there to observe the condition of the track or train or whether somebody is trying to vandalize it."

But Black, too, allowed that chances for his bill and others like it elsewhere are not good. "Nothing's going to bring back the caboose until they have a few good wrecks to prove that it's necessary," Black said.

The railroads, arguing that there is no greater chance of accident with the electronic devices, plan to seek greater authority to drop cabooses in the next labor negotiations.

To date, the demise of the caboose has not cut the size of train crews. The brakeman who used to ride the caboose now sits in the locomotive. But union officials fear there will be an effort to drop that crew member once the caboose is gone for good.

A minor problem for the railroads is how to dispose of the thousands of cabooses now headed for the end of the line. "You keep hearing about these private rail buffs who are sure to jump up and bid for an old caboose," said Tom LeHood, of the Union Pacific's Omaha headquarters. "But we haven't found any of them."

The Union Pacific ran a classified ad under the heading "Miscellaneous For Sale" in the Omaha World-Telegraph. LeHood said response was tepid. Many rail lines simply are giving away cabooses.

Many city and state parks across the Great Plains now feature bright red, yellow or green cabooses for children to climb on.

"That's been a good way to get rid of them," LeHood said. "Pretty soon, the only caboose you'll ever see will be the one by the sliding board down in the park."