Error in StreamlitCallbackHandler.on_llm_new_token callback: maximum recursion depth exceeded

Summary

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.

Steps to reproduce

cbh = StreamlitCallbackHandler(container,
max_thought_containers=3,
collapse_completed_thoughts=False,
thought_labeler=LLMThoughtLabeler(),
)
agent.run(prompt, callbacks=[cbh])

where agent is a class derived from Agent(BaseSingleActionAgent) and container is a st.container().

I am not aware that my code modifies anything else to uniquely cause this but will keep digging.

Curious if anyone else has seen such a recursion stacking.

Hi @rasmuswissmann

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.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.