The Alexandria public housing agency agreed last night to give a private developer the exclusive right to develop a site near a future Metro stop in exchange for the developer's help in avoiding bankruptcy, which the agency faced in a matter of days.

The developer, the Carley Capital Group, will guarantee a line of credit to keep the financially troubled Redevelopment and Housing Authority in operation for the next 18 months. In return, the housing agency agreed to deal exclusively with the Carley firm on plans for development of land the agency owns next to the Braddock Road Metro stop. The 40-year-old John Roberts Homes project now occupies the land, which is considered a prime site for private office, commercial and residential development.

The agency's decision was made by its seven-member board of directors at a special meeting called to consider the Carley offer.

The housing authority, which has been running a deficit of $100,000 a month, probably will need a loan of $1.5 million to cover its operations for the next 1 1/2 years, according to Angus Olson, the authority's executive director. The agency provides shelter for about 3,000 people in 1,150 units of public housing in the city, he said.

The agency's financial problems have mounted as federal subsidies have been cut over recent months, Olson said. Last January, the authority obtained zoning for development of the John Roberts site with a mixture of office, retail and residential buildings. The agency hoped to sell the property for about $10 million, which could be invested to provide funds for its operating costs. But the sagging real estate market and a glut of office space in the metropolitan area cut into the value of the property, which was recently appraised at only $5 million.

Under terms of its agreement with the Carley company, the housing authority and the developer will try to reach an agreement as partners in a joint venture development on the property. With the opening of the Braddock Road stop, expected late in 1983, the site could be expected to attract tenants for offices and homes, and shoppers for stores.

Elderly residents of the 90-unit John Roberts project will be moved into new apartment buildings for the elderly under construction behind the housing authority's offices in the city's Old Town area. Families from John Roberts eventually will move into another housing project in Old Town, the George Parker Homes, after the Parker units have been repaired and rehabilitated, Olson said.

Affluent neighbors of the George Parker project have urged that the low-income residents be moved to make way for town house and condominium development that would enrich the city treasury with tax receipts.

Vice Mayor James P. Moran Jr., a Democrat, said recently, however, that the City Council "is committed to providing for these people [the low income residents] because they are Alexandrians."