I want to make an bot that can run function but for that i would need to get every character that the llm generates and then chck if there is a pattern and if so stop add the output and continue running the llm

i think that that is the callbackmanager but im not sure how to use it