President Reagan and Mexican President Jose Lopez Portillo ended two days of talks yesterday with warm words of friendship amid indications their two nations are still far apart in attitudes toward Central America and the Carribean.

They agreed to establish commissions on bilateral political and trade issues, and the U.S. side outlined its plan for a pilot program for 50,000 Mexican "guest workers" to be admitted to the United States on temporary permits.

Reagan accepted an invitation to an October conference on helping the developing world, to be held in Cancun, Mexico, and the two presidents discussed a three-way summit to include Canadian Prime Minister Pierre Elliot Trudeau, acording to participants in the talks.

U.S. officials emphasized the interest they said Lopez Portillo had shown in an evolving U.S. plan for economic aid to the Caribbean basin, but Mexican Foreign Minister Jorge Castaneda stressed that Mexico has reservations about the plan.

Castenda also said Lopez Portillo delivered Mexico's message that "military aid to the [El Salvadore] junta only postpones solution of the problem." The Reagan administration stepped up military and economic aid to the junta.

"We should not intervene on behalf of one side or the other," Castaneda told reporters. "We should all respect the right of the people of El Salvador to self-determination."

Castaneda's account appeared to contradict that of two U.S. officials who spoke on the understanding that they would not be identified. One of the U.S. officials told reporters there had been "no specific political discussion of El Salvador."

In addition to differences over El Salvador, Cuba is an obstacle to the Carribean development plan the United States wants to establish. Lopez Portillo insisted that no plan should automatically exclude any nation from participation, according to Castaneda and the two U.S. officials.

The United States accepted that condition in principle, Castaneda said. The U.S. officials said, however, that the United States did not address the question of eligiblity of nations for the plan.

Mexico has good relations with Cuba, but the United States has no diplomatic relations with Cuba and maintains a trade embargo against that nation.

The U.S. officials said details of the Reagan Caribbean plan remain to be worked out. Castaneda made the "working-out" sound likely to be prolonged. b

Whatever differences remained between the two nations, Lopez Portillo made it clear that he considered his visit a success, in large part because of the manner in which he was received as an equal partner rather than as the head of a poor neighbor.

"I must confess that I am moved," he said in toasting Reagan at a White House luncheon yesterday after the two presidents returned from Camp David where most of the talks were held.

"I have spoken . . . in this same place three times before, and I have never been so moved as I feel today," he said. "The relationship for some reason or another had always been a tense one. The relationships between neighbors are always difficult . . . but for the first time now, I have felt totally relaxed.

"The most important thing of all is respect. If all the powerful people in the world were to truly understand what respect means to the weak people, the world would truly change.

Reagan also spoke of the "warm, personal relationship" he said he and Lopez Portillo had established. "My house is your house," he told Lopez Portillo in halting Spanish.

Reagan demonstrated the importance he attaches to Mexico by making Lopex Portillo the first foreign leader he has invited to Camp David and the first to be there since Israeli Prime Minister Menachem Begin and Egyptian President Anwar Sadat negotiated their peace agreement with President Carter.

Attorney General William French Smith explained the American thinking on guest workers. Although the U.S. plan is not complete, Castaneda said it would experiment with 50,000 Mexicans crossing the border on temporary work permits and that an amnesty for more than two million Mexicans in the United States illegally was discussed.

The anonymous U.S. officials said the talks had brought them nearer to implementing a guest worker program.

The U.S.-Mexican dispute over fisheries was discussed briefly without any agreement and the two nations also signed, for the third straight year, an agreement for the sale of U.S. grain to Mexico.