[GH-ISSUE #453] [Feature]: Add a Token-Based Context Limit alongside the existing Message Limit #201

Closed
opened 2026-10-20 17:26:11 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Navgner on GitHub (May 6, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/453

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.

  • I DID NOT read this template and provide the requested details.
Originally created by @Navgner on GitHub (May 6, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/453 ## 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. - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:26:11 +07:00
Author
Owner

@cha1latte commented on GitHub (May 6, 2026):

Triage note: labeling this as scope-risk because a token-based context limit is strongly aligned with local-model reliability, but it changes prompt assembly from message-count selection to token-budget selection.

Least risky next step is to define token counting, fallback behavior, and how this setting interacts with the existing message limit before implementation.

<!-- gh-comment-id:4392822749 --> @cha1latte commented on GitHub (May 6, 2026): Triage note: labeling this as `scope-risk` because a token-based context limit is strongly aligned with local-model reliability, but it changes prompt assembly from message-count selection to token-budget selection. Least risky next step is to define token counting, fallback behavior, and how this setting interacts with the existing message limit before implementation.
Author
Owner

@SpicyMarinara commented on GitHub (May 10, 2026):

We already have that in Connections.

<!-- gh-comment-id:4414887106 --> @SpicyMarinara commented on GitHub (May 10, 2026): We already have that in Connections.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#201
No description provided.