fix(agents): strip tool leak text (#905)

Thanks @erikpr1994.

Co-authored-by: Erik Pastor Rios <erikpastorrios1994@gmail.com>
This commit is contained in:
Peter Steinberger
2026-01-15 05:57:44 +00:00
parent 5c2eedc340
commit 2bd9e84851
3 changed files with 159 additions and 6 deletions

View File

@@ -329,6 +329,27 @@ Arguments: { "action": "act", "request": "click button" }`,
expect(result).toBe("Let me check that for you.");
});
it("preserves trailing text after downgraded tool call blocks", () => {
const msg: AssistantMessage = {
role: "assistant",
content: [
{
type: "text",
text: `Intro text.
[Tool Call: read (ID: toolu_1)]
Arguments: {
"path": "/tmp/file.txt"
}
Back to the user.`,
},
],
timestamp: Date.now(),
};
const result = extractAssistantText(msg);
expect(result).toBe("Intro text.\nBack to the user.");
});
it("handles multiple text blocks with tool calls and results", () => {
const msg: AssistantMessage = {
role: "assistant",
@@ -375,6 +396,22 @@ File contents here`,
expect(result).toBe("Aquí está tu respuesta.");
});
it("strips thinking tags with attributes", () => {
const msg: AssistantMessage = {
role: "assistant",
content: [
{
type: "text",
text: `<think reason="deliberate">Hidden</think>Visible`,
},
],
timestamp: Date.now(),
};
const result = extractAssistantText(msg);
expect(result).toBe("Visible");
});
it("strips thinking tags without closing tag", () => {
const msg: AssistantMessage = {
role: "assistant",