mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 07:27:40 +00:00
fix(agents): strip [Historical context: ...] and tool call text from streaming path (#13453)
- Add [Historical context: ...] marker pattern to stripDowngradedToolCallText - Apply stripDowngradedToolCallText in emitBlockChunk streaming path - Previously only stripBlockTags ran during streaming, leaking [Tool Call: ...] markers to users - Add 7 test cases for the new pattern stripping
This commit is contained in:
@@ -37,7 +37,7 @@ export function stripDowngradedToolCallText(text: string): string {
|
||||
if (!text) {
|
||||
return text;
|
||||
}
|
||||
if (!/\[Tool (?:Call|Result)/i.test(text)) {
|
||||
if (!/\[Tool (?:Call|Result)/i.test(text) && !/\[Historical context/i.test(text)) {
|
||||
return text;
|
||||
}
|
||||
|
||||
@@ -186,6 +186,9 @@ export function stripDowngradedToolCallText(text: string): string {
|
||||
// Remove [Tool Result for ID ...] blocks and their content.
|
||||
cleaned = cleaned.replace(/\[Tool Result for ID[^\]]*\]\n?[\s\S]*?(?=\n*\[Tool |\n*$)/gi, "");
|
||||
|
||||
// Remove [Historical context: ...] markers (self-contained within brackets).
|
||||
cleaned = cleaned.replace(/\[Historical context:[^\]]*\]\n?/gi, "");
|
||||
|
||||
return cleaned.trim();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user