Fix new line bug in chat mode for agents
# What does this PR do?

Depending on the agent used we might get too many new lines here. Just stripping everything and adding the right amount fixes this.
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_23267). All of your documentation changes will be reflected on that endpoint.