A short and accurate answer would be, committing a mistake(s). But I'll elaborate.
After the French were defeated in the First Indochina war, the the west could not accept ceding all of Vietnam to the communists. Accordingly, the peace treaty split the country in two with the promise of elections about reuniting the country in two years. During that war, the US was a huge supporter of the French, which it demonstrated by paying 80% of the costs for the French forces. The primary basis for the US support was the Domino Theory, a policy that still had primacy for American motivation right up until the end of the Second Indochina War.
US intentions to support the newly formed S. Vietnamese government were honorable, even if they were mistaken. A huge problem, one that could not be overcome, was that the S. Vietnamese government was comprised of a religious minority and/or former French educated officials, that was totally corrupt and incompetent, with a penchant for persecuting the religion of the majority. Additionally, 80% of the population of S.Vietnam were peasant farmers and the government officials were primarily city folk. The S. Vietnamese government never controlled more than a third of the country and also never made an effective effort to integrate more of the population into government and national supporters. Thus the S. Vietnamese government never had a chance to resist a determined uprising.
The forces of the Domino Theory, communist containment, support for an ally, demonstrating to other US allies, and Russia. that America would truly support allies against communist uprisings combined to compel the US into support for the S. Vietnamese despite those issues. As N. Vietnam ratcheted up the armed effort to topple the S. Vietnamese, the US had to amp up it's military forces because of all the limitations that resulted from the shortcomings of the Saigon meant that the S. Vietnamese responses were always a mere fraction of what was required.
As N. Vietnam continued to further increase its efforts to reunite the country and with the S. Vietnamese government demonstrating that it was both incapable and unworthy of maintaining itself, the US became a bad poker player. The US was holding a bad hand while too proud and too stupid to walk away. The US Presidents, starting with JFK, at least, were aware that the US was backing a losing proposition, but for ........reasons..........continued to throw American treasure and blood into the conflict until sufficient time and bad publicity turned the American public's opinion against continued involvement in Vietnam.
So the long answer is the US was there in an effort to block the spread of international communism in compliance with the principles of the Domino Theory and to demonstrate to the entire world, both communist and non-communist, that it would be a faithful and willing ally with the willpower to spend whatever was necessary.