Subject: UI-Based Context Management to Prevent Token Limit Errors - Suggestion for App Prototyper Enhancement
Subject: UI-Based Context Management to Prevent Token Limit Errors - Suggestion for App Prototyper Enhancement
I am writing to you as a community of active App Prototyper users who greatly appreciate its capabilities. Recently, I've encountered a challenge that we believe will become increasingly common for users: the "input token count exceeds" error ([GoogleGenerativeAI Error]: ... The input token count (...) exceeds the maximum number of tokens allowed (...)). This issue arises from the accumulation of conversation history within the capra-context-state.json
file.
A community member (as discussed in this forum post: https://community.firebasestudio.dev/t/temporary-workaround-for-error-due-to-exceeding-input-token-count-unofficial/12457) conducted a detailed investigation and proposed a manual workaround involving direct editing of the capra-context-state.json
file to reduce the conversation history sent as context to the Gemini model. While effective, this manual solution carries risks and requires a level of technical expertise that may not be accessible to all users.
The Identified Problem:
After analysis, based on the current functionality and the content of capra-context-state.json
(an example of its structure is provided below), confirms that the complete history of interactions, particularly within agentHistories["app-prototyping-agent: edit-app-agent"]
, is re-sent with each new prompt. With continued use, this history grows, inevitably leading to the model's token limit being exceeded.
Example of the relevant capra-context-state.json
structure (simplified):
```json
{
// ... other sections like currentProposalObject ...
"agentHistories": {
"app-prototyping-agent: edit-app-agent": [
{
"role": "user",
"content": [{"text": "User message 1..."}]
},
{
"role": "model",
"content": [{"text": "Model response 1..."}]
},
{
"role": "user",
"content": [{"text": "User message 2 (reporting error)..."}]
},
{
"role": "model",
"content": [{"text": "Model response 2 (suggesting fix)..."}]
}
// ... more interactions ...
]
},
"currentState": "edit-app"
}
The Proposal: UI-Integrated Context Management
To make context history management safer, more intuitive, and accessible to all users, we propose implementing features directly within the App Prototyper interface. I believe this would significantly enhance the user experience and the long-term usability of the tool.
Suggest including buttons that could appear next to each message or interaction block (user prompt + model response) in the chat window, possibly on hover to keep the interface clean:
'Delete' (or 'Remove from Context') Button:
Functionality: Would allow the user to select a specific message or an interaction pair (user prompt + model response) and remove it from the corresponding array in agentHistories within capra-context-state.json.
Impact: Directly reduces the token count.
Considerations:
A confirmation dialog would be essential.
Ideally, the removal would also be reflected in capra-thread.json (history view), or at least the message would be visually marked as "not included in context."
Removing a pair (user/model) seems to be the most natural approach, as observed by the community.
'Edit' Button:
Functionality: Would allow the user to modify the text of a previous user message within the context. This would be useful for shortening long prompts or correcting information without removing the entire interaction.
Impact: Allows for finer control over token content.
'Refresh Context' (or similar) Button:
Functionality: After performing deletions or edits, this button would ensure that the App Prototyper uses the updated capra-context-state.json for the next submitted prompt, avoiding the behavior of the "Retry" button which, as understood, uses the pre-modification context. It could also clear the new prompt input field.
Benefits of Implementation:
Accessibility: Empowers all users, regardless of technical expertise, to manage context and avoid token errors.
Safety: Reduces the risk of JSON file corruption from manual editing.
Improved User Experience (UX): Offers an integrated and seamless solution to a recurring problem.
Maintained Productivity: Allows users to continue using the Prototyper for longer periods without interruption.
Next Steps and Collaboration:
I understand that the project is open source. As users with technical capabilities, I am willing to explore the possibility of contributing to the implementation of these features if it aligns with the team's interests. I already have a good understanding of the data structures involved and a VM with code access for prototyping.
I would appreciate hearing your thoughts on this proposal and whether there are any internal plans or considerations regarding this issue. I am available to discuss this further, provide more details about the analysis, or collaborate in a way that is most productive.
Thank you for your time and for the excellent tool that the App Prototyper is.
Sincerely,