What is the role of Tom Sawyer in The Adventures of Huckleberry Finn? What is his "function"?
Tom an incurable romantic appears as a foil character to the more pragmatic Huck. Tom and Huck are dramatic opposites. Tom likes adventures and plots. Tom complicates things just for the sheer pleasure of a drama or complication.
Huck's life and friendship with Jim are very basic and plain. Huck has experienced true hardship, abuse, and want as a result of being in the custody of his alcoholic and abusive father.
Tom's wants to feel that he is "without", but in reality, he lives well, has plenty to eat, and has a nice comfortable home in which to live. The extreme nature of Tom serves to highlight the very pure and basic friendship that has developed between Jim and Huck.
Tom is a "wannabe" rebel, but Huck is the genuine article. Tom wants to smoke, but he doesn't have the stomach for it. Tom is all about showing off and having fun, no matter who may be hurt in the pranks and revelry.
Huck on the other hand, is a serious rebel and smoker. He is concerned with the outcome of real-life situations. Huck is concerned for the rescue of his friend Jim, who is a better friend to Huck than Tom Sawyer. Huck has to deal with some crooks who intend to kill one of their partners. Huck has to come to terms with "white society and racism" or helping his friend Jim escape to Cairo, Illinois (a free state).
Tom's need for adventure obscures the desperate reality of Jim's runaway slave situation. Most of Tom's problems in life are pretend or made-up. He views life as an adventure out of a book or story. Tom's overly complicated rescue of Jim simply makes no sense to Huck who comes up with the idea of simply lifting the bedpost up so the chain can slip under it.