fix(agents): preserve fallback tool-call hints (#99851)

This commit is contained in:
Vincent Koc
2026-07-03 23:42:05 -07:00
committed by GitHub
parent a07b4bed79
commit 03fafe2364
2 changed files with 12 additions and 4 deletions
@@ -12,7 +12,11 @@ import {
startsWithSilentToken,
stripLeadingSilentToken,
} from "../../auto-reply/tokens.js";
import { resolveToolUseId, type ToolContentBlock } from "../../chat/tool-content.js";
import {
isToolCallBlock,
resolveToolUseId,
type ToolContentBlock,
} from "../../chat/tool-content.js";
import {
type ClaudeCliFallbackSeed,
readClaudeCliFallbackSeed,
@@ -320,7 +324,7 @@ function extractFallbackTurnText(message: FallbackTurnLikeMessage): string {
// Tool calls: render as a compact "(tool: name)" hint so the fallback
// model sees the conversation flow without the full tool argument blob,
// which is rarely useful out of context and chews through char budget.
if (rec.type === "tool_use" && typeof rec.name === "string") {
if (isToolCallBlock(rec) && typeof rec.name === "string") {
parts.push(`(tool call: ${rec.name})`);
continue;
}
+6 -2
View File
@@ -166,7 +166,7 @@ describe("formatClaudeCliFallbackPrelude", () => {
role: "assistant",
content: [
{ type: "text", text: "Earlier assistant reply" },
{ type: "tool_use", name: "Bash" },
{ type: "toolcall", name: "Bash" },
],
},
{
@@ -269,7 +269,10 @@ describe("buildClaudeCliFallbackContextPrelude", () => {
message: {
role: "assistant",
model: "claude-sonnet-4-6",
content: [{ type: "text", text: "prior answer about blue-green" }],
content: [
{ type: "text", text: "prior answer about blue-green" },
{ type: "tool_use", id: "toolu_1", name: "Bash", input: { command: "pwd" } },
],
},
},
];
@@ -285,6 +288,7 @@ describe("buildClaudeCliFallbackContextPrelude", () => {
expect(prelude).toContain("## Prior session context (from claude-cli)");
expect(prelude).toContain("user: prior question about deploys");
expect(prelude).toContain("assistant: prior answer about blue-green");
expect(prelude).toContain("(tool call: Bash)");
} finally {
await fs.rm(tmpHome, { recursive: true, force: true });
}