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:
Cklee
2026-02-11 05:04:52 +09:00
committed by GitHub
parent 67d25c6533
commit 22458f57f2
3 changed files with 48 additions and 4 deletions

View File

@@ -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();
}