fix(bookstack-agent): suppress reasoning text before tool calls#100
Merged
Conversation
On-prem models like Qwen emit reasoning/thinking text in a text content block before using tools. Previously this appeared in the UI for the full duration of the tool-call turn before being cleared by the tool_use event. Fix: watch for content_block_start with type=tool_use inside the stream. When detected, immediately yield a text_clear event so the UI discards any rendered text, then suppress further text_chunk events for that turn. The text_clear arrives as soon as the model signals a tool call — not after the full response completes — so the transient reasoning text is never visible to the user. Final-answer turns (no tool use) are unaffected and still stream character-by-character.
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.
On-prem models like Qwen emit reasoning/thinking text in a plain text content block before using tools. Previously this appeared in the chat UI for the full duration of the tool-call turn, then vanished when the
tool_useevent finally arrived afterget_final_message().Root cause:
text_chunkevents fire in real-time buttool_useevents (which clear the text) only fire after the complete response is received.Fix:
ask_stream, watch forcontent_block_startwithtype=tool_useinside the stream loop. When detected, immediately yield{"type": "text_clear"}and stop emittingtext_chunkevents for that turn.chat-page.tsx, handletext_clearby settingcontent: null.The clear signal now arrives the moment the model begins a tool-call block — not after the full response — so transient reasoning text is never visible. Final-answer turns (no tool use) are unaffected and still stream character-by-character. Works with any model via the gateway.