fix(agents): harden tool-name normalization and transcript repair

Landed from contributor PRs #30620 and #30735 by @Sid-Qin, plus #30881 by @liuxiaopai-ai.

Co-authored-by: SidQin-cyber <sidqin0410@gmail.com>
Co-authored-by: liuxiaopai-ai <73659136+liuxiaopai-ai@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-03-01 23:51:43 +00:00
parent 50e2674dfc
commit ee03ade0d6
7 changed files with 224 additions and 13 deletions

View File

@@ -74,6 +74,29 @@ describe("sanitizeToolUseResultPairing", () => {
expect(out[3]?.role).toBe("user");
});
it("repairs blank tool result names from matching tool calls", () => {
const input = [
{
role: "assistant",
content: [{ type: "toolCall", id: "call_1", name: "read", arguments: {} }],
},
{
role: "toolResult",
toolCallId: "call_1",
toolName: " ",
content: [{ type: "text", text: "ok" }],
isError: false,
},
] as unknown as AgentMessage[];
const out = sanitizeToolUseResultPairing(input);
const toolResult = out.find((message) => message.role === "toolResult") as {
toolName?: string;
};
expect(toolResult?.toolName).toBe("read");
});
it("drops duplicate tool results for the same id within a span", () => {
const input = [
...buildDuplicateToolResultInput(),