fix(tui): system prompt not loaded in interactive mode#218
Merged
Conversation
The TUI was adding the user message to sessionState BEFORE calling
dispatchProvider, which caused isNewThread to be false. This prevented
the system prompt from being prepended to the conversation on the
first message.
Fix: Move sessionState.addExchange({ role: 'user' }) to AFTER
dispatchProvider returns, matching the non-interactive flow where
callProvider is called before the exchange is persisted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Problem
In interactive mode (TUI), the system prompt was not being loaded correctly. The agent would fall back to its default identity instead of using the custom persona defined in
prompts/SYSTEM_PROMPT.md.Root Cause
The TUI's
handleChatfunction was callingsessionState.addExchange({ role: 'user', content: text })before callingdispatchProvider. This meant that whencallProvidercheckedsessionState.getConversation().length === 0to determineisNewThread, it was alreadyfalse(the user message was already in the conversation).Since
isNewThreadwasfalse, the system prompt was never prepended to the conversation messages incallReactAgent.The Fix
Move the
sessionState.addExchange({ role: 'user' })call to afterdispatchProviderreturns, matching the non-interactive flow wherecallProvideris called before the exchange is persisted.Before (broken):
After (fixed):
Testing
node index.js "who are you?"- works correctly