The D.C. City Council narrowly approved automatic annual inflation increases in public assistance benefits yesterday over the objections of Mayor Marion Barry, after a strong lobbying effort by advocates for the poor.

The council already had agreed to increase Aid to Families with Dependent Children (AFDC) and General Public Assistance by 7 percent in April and 4 percent in October. But beginning in fiscal 1987, automatic increases in those benefits will be pegged to the consumer price index, under an amendment approved yesterday.

In other action, the council gave final approval to bills to:Make it a crime for parents to abduct their own children in violation of a custody order. Make it more difficult for companies with business ties to South Africa to obtain District contracts. Direct the mayor to develop a comprehensive response plan for acquired immune deficiency syndrome, including consideration of establishing a residential facility especially for AIDS victims and their families. Temporarily prevent many of the city's restaurants from losing their liquor licenses because of a court decision specifying that they must get more income from food sales than from liquor sales.

The council also signaled its interest in new programs to help welfare recipients get steady jobs, with 11 of the 13 members sponsoring a bill introduced yesterday by council member John Ray (D-At Large) to entitle all AFDC recipients to education, job training and support services. However, the program would be voluntary, unlike a proposal introduced recently by council member H.R. Crawford (D-Ward 7) to require employable welfare recipients to register for work or lose their benefits.

Council member John A. Wilson (D-Ward 2), who offered the public assistance cost-of-living amendment, said the District now ranks 26th in the nation in its level of welfare payment. After both increases agreed to for this year are in effect, the AFDC payment to a family of three will be $364 a month, or $4,368 a year, substantially below the federally established poverty level of $8,850, Wilson said.

Wilson said the CPI is expected to rise less than 4 percent a year for the next three years and that the cost of the automatic increases for nearly 29,000 households in the District receiving assistance would be about $2 million a year.

Barry said in a letter to council member Polly Shackleton (D-Ward 3), chairwoman of the Human Services Committee, that he opposed automatic indexing because the city needs to "preserve our options to provide programs and services to our needy clients in a variety of ways," particularly in light of expected federal budget cuts.

Shackleton said the idea needed to be considered further and moved to table Wilson's motion. But that attempt failed in a 6-to-6 vote with council member Charlene Drew Jarvis (D-Ward 4) voting present. After some discussion, Shackleton announced she would support the amendment, which was then quickly approved by voice vote.

Shackleton defended the city's record on providing public assistance, saying that when all the different kinds of benefits are taken into consideration -- including food stamps, housing and medical services -- that benefits in the District will total $9,960 for a family of three with this year's increased assistance payments.

The contracting measure, intended as a sanction against South Africa because of its continuing apartheid policy of racial segregation, provides for a system of demerits against companies that do business in South Africa, to be taken into account in evaluating bids on city contracts.