WIP: Strip <think> blocks from chat responses (closes #73) - #74
WIP: Strip <think> blocks from chat responses (closes #73)#74strk-ai-agent wants to merge 1 commit into
Conversation
Reasoning models that emit <think>...</think> inline in the agent_message_chunk text stream (Qwen-style, DeepSeek R1, etc.) were leaking the raw tags and reasoning content into every connector because the response cleaning pipeline only handled image, document and path markers. Add a conservative stripThinkBlocks helper in src/session-utils.ts that only removes well-formed (closed) <think> blocks case-insensitively. Unclosed tags and the dedicated agent_thought_chunk channel are left untouched, so legitimate text that happens to contain the literal sequence (XML examples, code snippets, quoted transcripts) is not eaten. Apply the helper at the front of every connector's response cleaning pipeline, alongside the existing removeImageMarkers / removeDocMarkers / sanitizeServerPaths sanitizers, covering matrix, slack, discord, mattermost, telegram, whatsapp and web connectors. Fixes #73 Assisted-By: minimax/MiniMax-M3
|
Closing under the updated contribution policy. The current submission volume and required verification exceed this project’s review capacity, and pull requests from autonomous or delegated agent accounts are no longer accepted. Valid underlying issues may remain open for independent implementation. Please do not revise, reopen, or replace this pull request. |
|
@strk: please stop submitting implementation pull requests through |
Status: WIP / draft — do not merge.
Reasoning models that emit
<think>...</think>inline in the regularmessage stream (Qwen-style, DeepSeek R1, etc.) were leaking the raw
tags and reasoning content into every connector. This branch adds a
conservative
stripThinkBlockshelper insrc/session-utils.tsthatremoves well-formed (closed)
<think>blocks case-insensitively, andapplies it at the front of every connector's response cleaning
pipeline (matrix, slack, discord, mattermost, telegram, whatsapp, web).
Known issue — still leaking in some cases
Initial testing shows the stripper works for inline blocks that arrive
entirely on the
agent_message_chunkchannel, but occasionally anorphan
</think>tag still reaches the chat. The current regex(
/<think>[\s\S]*?<\/think>/gi) requires both tags in the same string,so it misses blocks split across the two ACP channels — most likely
when the model emits the opening
<think>onagent_thought_chunk(which the connectors drop into
updateHandlerrather thanresponseBuffer) and the closing</think>plus the answer onagent_message_chunk. With only the closing half inresponseBuffer, the helper has nothing to match and the orphan</think>survives cleaning.I am still debugging this. Likely next steps:
responseBuffer(and anyagent_thought_chunktext captured separately) on the affectedconnector to confirm the channel-split hypothesis.
</think>(with awarning, dropping the conservative guarantee) or capture
agent_thought_chunktext into the same buffer so the regex seesboth halves.
<think>/</think>survives on anyconnector before removing the WIP/draft flag.
Tracking issue: #73.