[Feature request] Perform hard action before exceeding endpoint maximum context length.
Create a chat session rule system that allows conditional interruption and execution of a prompt based on context window length.
For example, the rule pseudocode is as follows:
If (contextLength.this_session) <= (10% of contextLength.Maximum) then { haltConversation() #halt the current conversation sendPrompt(customMaxContextEscapePrompt())
"customMaxContextEscapePrompt" is something defined by the user:
it could be just a "stop talking, you're out of context length" or it could be "record all your work into [custom mcp tool] and inform me that you are out of context length" or all the way to "record all your work and tell me what your plans are for the next session" (and store the output of this into an immediate chain prompt for a next session.
it's like a discount langchain idea, basically.
I know this is very basic. maybe in the future it could be a little graphical workflow or whatever. but something simple so I don't loose work when I exceed the maximum context length of an endpoint would be nice, and is the actual problem space I am encountering.
Thank you for raising this important issue about handling context length limitations. I completely agree this is a critical problem to solve. Based on our research, there are two main challenges we're facing:
Challenge 1: Token Calculation Accuracy
The accuracy of token calculation tools remains problematic. Current mainstream calculators from OpenAI and LangChain often produce inconsistent results. This is especially challenging with non-English languages like Chinese, where a single character might be assigned 2-3 tokens. Without accurate token counting, it's difficult to reliably predict when we're approaching context limits.
Challenge 2: Model-Specific Context Windows
Different models have varying maximum context window sizes, and there's currently no standardized API to programmatically obtain this information. While manual configuration of model context windows might be possible in the future, we currently lack a reliable way to detect these limitations automatically across different providers.
Let us investigate this further to develop a comprehensive solution that prevents work loss