Skip to content

Commit 2d09a92

Browse files
author
root
committed
fix(openclaw): strip <think/> tags from assistant messages
DeepSeek-style reasoning models emit <think…>…</think⟩ blocks that confuse downstream parsing and trigger error-retry loops, eventually causing timeouts. Strip these tags early in the capture pipeline. Closes #1268
1 parent 2baf35d commit 2d09a92

File tree

1 file changed

+8
-0
lines changed
  • apps/memos-local-openclaw/src/capture

1 file changed

+8
-0
lines changed

apps/memos-local-openclaw/src/capture/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function captureMessages(
7070
if (role === "user") {
7171
content = stripInboundMetadata(content);
7272
} else {
73+
content = stripThinkingTags(content);
7374
content = stripEvidenceWrappers(content, evidenceTag);
7475
}
7576
if (!content.trim()) continue;
@@ -148,6 +149,13 @@ export function stripInboundMetadata(text: string): string {
148149
return stripEnvelopePrefix(result.join("\n")).trim();
149150
}
150151

152+
/** Strip <think…>…</think⟩ blocks emitted by DeepSeek-style reasoning models. */
153+
const THINKING_TAG_RE = /<think[\s>][\s\S]*?<\/think>\s*/gi;
154+
155+
function stripThinkingTags(text: string): string {
156+
return text.replace(THINKING_TAG_RE, "");
157+
}
158+
151159
function stripEnvelopePrefix(text: string): string {
152160
return text.replace(ENVELOPE_PREFIX_RE, "");
153161
}

0 commit comments

Comments
 (0)