mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #289] [Feature]: Add a Token-Based Context Limit alongside the existing Message Limit #115
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#115
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Navgner on GitHub (Apr 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/289
What problem does this solve?
Currently, Marinara Engine relies on a fixed "Message Limit" to manage how much context is sent to the model. However, since message lengths vary wildly during a roleplay, this approach is highly unpredictable. Sometimes a limit of X messages underutilizes my available context window, while other times it completely overflows it, causing my local LLM to bug out or truncate unexpectedly.
Describe the solution you'd like
I would love to see a "Context Limit in Tokens" option, ideally placed right below the Message Limit setting.
Instead of pulling a fixed number of messages, the engine would pull messages dynamically until it hits this user-defined token ceiling.
Why is this important? (Use Case)
If I am running a local model with a strict 16,000 token context window, I need precise control. I want to be able to set a token limit of, say, 14,500 tokens. This acts as a strict ceiling, leaving a guaranteed safe "buffer" of 1,500 tokens for the AI's generation. This ensures the engine maximizes the context without ever risking an overflow/crash on local hardware. Otherwise when the limit is hit, I notice the AI forgetting much more to do the thinking before generating a message.
Additional context
I am unsure if the lack of this feature is an intentional design choice due to the way context injection is coded, but having a token-based knapsack approach (filling up to a token threshold rather than a message count) would be a massive quality-of-life improvement for local users who need to manage VRAM strictly.
@kinthaiofficial commented on GitHub (Apr 28, 2026):
Token-based context limits are essential for any AI character engine. Message-count limits are a legacy approach that works poorly with variable-length messages.
What we learned implementing this at KinthAI:
1. Token counting must be model-specific
Different models tokenize differently. GPT-4 and Claude use different tokenizers. A "4K token limit" means different amounts of text depending on the model. Use the actual tokenizer for the active model, not a universal estimate.
2. Dynamic allocation within the token budget
Not all context is equal. We divide the budget:
This way, conversation history flexes based on how much other context needs.
3. Smart truncation when over budget
When the total exceeds the context window:
Trimming from the middle preserves both the character setup and the recent conversation flow.
4. The "overflow bug" you describe is common:
Local LLMs silently truncate when you exceed the context window. The fix: always leave a 10% buffer below the context limit. If the model supports 8K, target 7.2K max.
This is fundamentally the same problem as the sliding context window that causes Character.AI users to lose their conversation history. The fix is not a bigger window — it is smarter context management. We wrote about this: Why Character.AI Forgets You — Persistent Memory Architecture
@SpicyMarinara commented on GitHub (Apr 28, 2026):
v1.5.6.
@Navgner commented on GitHub (Apr 28, 2026):
I'm confused, I do not see the added feature in the 1.5.6 update? Is for a later version of 1.5.6?