Skip to content

WIP: Strip <think> blocks from chat responses (closes #73) - #74

Closed
strk-ai-agent wants to merge 1 commit into
ominiverdi:mainfrom
strk-ai-agent:fix/strip-think-tags
Closed

WIP: Strip <think> blocks from chat responses (closes #73)#74
strk-ai-agent wants to merge 1 commit into
ominiverdi:mainfrom
strk-ai-agent:fix/strip-think-tags

Conversation

@strk-ai-agent

Copy link
Copy Markdown

Status: WIP / draft — do not merge.

Reasoning models that emit <think>...</think> inline in the regular
message stream (Qwen-style, DeepSeek R1, etc.) were leaking the raw
tags and reasoning content into every connector. This branch adds a
conservative stripThinkBlocks helper in src/session-utils.ts that
removes well-formed (closed) <think> blocks case-insensitively, and
applies 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_chunk channel, but occasionally an
orphan </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> on agent_thought_chunk
(which the connectors drop into updateHandler rather than
responseBuffer) and the closing </think> plus the answer on
agent_message_chunk. With only the closing half in
responseBuffer, the helper has nothing to match and the orphan
</think> survives cleaning.

I am still debugging this. Likely next steps:

  1. Add a one-shot debug log of the raw responseBuffer (and any
    agent_thought_chunk text captured separately) on the affected
    connector to confirm the channel-split hypothesis.
  2. Either widen the regex to also strip orphan </think> (with a
    warning, dropping the conservative guarantee) or capture
    agent_thought_chunk text into the same buffer so the regex sees
    both halves.
  3. Re-run and confirm no <think> / </think> survives on any
    connector before removing the WIP/draft flag.

Tracking issue: #73.

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
@ominiverdi

Copy link
Copy Markdown
Owner

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.

@ominiverdi ominiverdi closed this Aug 10, 2026
@ominiverdi

Copy link
Copy Markdown
Owner

@strk: please stop submitting implementation pull requests through strk-ai-agent. Future contributions must be reviewed, understood, and submitted by a human; discussed with a maintainer before implementation where required; and limited to one active implementation pull request at a time. Resubmitting the closed work through another account would circumvent this boundary. Valid bug reports can remain open. This is a final maintainer-capacity decision, not a request to revise the current backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants