Throughout the Middle Ages and Renaissance, the Val Trompia, an iron-rich valley running from Brescia to Gardone in eastern Lombardy in Italy, was a major center for weapons production, and its artisans were known throughout the courts of Europe and the Near East.

One of these artisans was Bartolomeo Beretta, who sold harquebus barrels to the Venetian Republic in the early 1500s. Today, the Val Trompia is still known for its scores of arms companies. And the descendants of Bartolomeo -- now in their 12th generation -- are still doing a flourishing business.

Because of its quality work and fine reputation among sportsmen, hunters and other arms users, Pietro Beretta s.p.a., as the company is now called, has long been the unchallenged leader of Italian manufacturers of short and long "light" arms.

In recent years, however, the company has begun to develop in a new direction, a near-total transition to computerized or robotized forms of production. The switch to high technology, which makes Beretta one of Italy's most modern companies, has enabled the firm to weather a recent slump in the light arms market. In addition, it no doubt played a role in Beretta's successful January bid for a prestigious $75 million contract to supply the U.S. Army with a new 9 mm handgun that would replace the outdated Colt 45 and bring the United States into line with its NATO allies, which adopted the 9 mm some time ago.

By the terms of the deal, Beretta will sell the U.S. Army the license for the new 92 F and provide the Pentagon with the first 315,930 guns, most of which will be produced by a Beretta subsidiary in Accokeek, Md. The company also hopes to win a second competition in 1990 for the manufacture of another 200,000 to 300,000 guns.

Italian politicians believe that to an extent the Beretta bid, which defeated offers by Colt and Smith and Wesson of the United States, F. M. Herstal of Belgium, and Heckler and Koch of West Germany, may have been helped by the U.S. government's willingness to take into account a largely unfulfilled 1978 U.S.-Italian "memorandum of understanding" mandating the United States to buy more Italian-made weapons.

Beretta also offered a price of $179 per pistol, far below its regular U.S. retail price. But arms experts here and in the United States also have said that the Beretta 92 semiautomatic, which carries a 15-round magazine, probably is safer and more reliable than any other gun of its type now on the market.

"We are talking about a gun that is both the best-tested of its kind and the most up-to-date," Ugo Gussalli-Beretta, the company's managing director, said. He points out that the 92 model has been the standard handgun for Italian police and army for almost a decade, and is used by the armies of India, Brazil and Ecuador as well as by the Texas Rangers and state police in Connecticut, North Carolina and Wyoming.

In terms of quantity, the U.S. Army order is hardly one of Beretta's largest. The 50,000 or so 92 Fs to be supplied this year are only a small percentage of the 300,000 that Beretta produces annually.

But the enormous prestige of the award is seen likely to boost orders from other governments. At the same time, it also could lead to increased sales for other types of Beretta arms in the United States -- the world's single biggest firearms market and Beretta's best foreign customer, with 18 percent of company exports.

Beretta's inventory today runs from light military weapons like assault rifles, machine guns and submachine guns (including a gold-plated submachine gun identical to a lot of 25 ordered a few years ago by Saudi Arabia's King Faisal) to hunting and bolt action rifles and a full range of pistols, including tiny gold- or silver-plated models that fit snugly into a lady's elegant evening purse.

In sporting guns Beretta has few rivals. "Now that I can afford them you can be sure it's the only gun I want," says U.S. Olympic bronze medal winner Dan Carlisle, who was in Gardone in February to pick up four new custom-made rifles, one for skeet, one for international trap, one for American trap and one for his wife.

It is in the custom-made department that the link with Beretta's 450 years of tradition is the most evident. In the "Ferrari department," which employs between 80 and 100 of the firm's 1,300 employes, guns are made largely by hand. In the department's decoration sector, 23 highly skilled engravers spend a minimum of 200 hours to execute magnificently detailed designs on the action body of every rifle.

However, in most of Beretta's huge sprawling factory, which covers some 120,000 square feet, the break with the past is dramatic. Since 1981 the company has almost totally automated its production, and today three-quarters of its 3,000 machines are programmed by computers to perform dozens of different and complex operations.

Beretta's decision to automate was largely a result of soaring Italian labor costs, among the highest in Western Europe. The changeover cost more than $10 million but has allowed the company to concentrate the factory's skilled manpower on quality control and special production lines.

Plagued recently by a slack in demand and tightened Italian government controls on export licenses, in 1983 sales fell sharply to 82.6 billion lire ($41.3 million) from 91.2 billion ($45.6 million) in 1982. In 1984, however, there was a new boom; sales rose to 102 billion lire (about $51 million) and exports, which in 1983 had slipped to 43 percent of total production, climbed back to their former level of 60 percent.