I am using the StreamlitCallbackHandler with a LangChain agent in a chatbot style interface.
When agent responses exceed a few hundred tokens, the system throws an error:
Error in StreamlitCallbackHandler.on_llm_new_token callback: maximum recursion depth exceeded
Has anyone come across this?
I can set sys.setrecursionlimit() to more than Python’s default of 1000. That prevents this error but causes other instability and crashes the Streamlit process altogether. It also feels wrong.
Thanks for the question. In regards to the maximum recursion depth exceeded it may have been caused by an unintentional recursion in the code. There are a few forum post on resolving the issue that you can look into:
It may also be helpful to experiment with the max_thought_containers parameter to see if fewer value would still cause the error.