Efficient state management is crucial for optimizing chatbot performance in Botpress. This guide outlines best practices to avoid performance degradation and errors caused by exceeding the 128 KB state size limit, ensuring your bot operates seamlessly.
Botpress enforces a state size limit of 128 KB to maintain optimal performance. Poorly managed state variables, especially in nested workflows, can lead to:
State bloat: Accumulation of unnecessary or oversized variables.
Performance issues: Slower bot responses as state size grows.
Ensure that each workflow completes before initiating the next. This prevents unused variables from lingering in the state.Best Practice Workflow Design:Workflow 1 → EndWorkflow 2 → End
3. Minimize Use of Large Variables in Main Workflow
Avoid storing large data structures (e.g., arrays, objects) in the main workflow (wf-main). Instead, limit variables to essentials for transitions or core logic.Best Practices:
Move non-essential or large variables to sub-workflows.
Adhering to these state management best practices ensures your bot performs optimally, avoids the 128 KB state size limit, and maintains clean and efficient workflows:
Design workflows with proper exits.
Manually clear unused variables when needed.
Minimize use of large variables in the main workflow.
Regularly monitor and audit state size.
By implementing these guidelines, you’ll enhance chatbot performance, reduce errors, and provide a better user experience.