mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 12:56:01 -06:00
fix(agents): keep Anthropic tool cache breakpoint advancing
This commit is contained in:
@@ -100,12 +100,13 @@ describe("anthropic payload policy", () => {
|
||||
type: "tool_result",
|
||||
tool_use_id: "tool_1",
|
||||
content: "done",
|
||||
cache_control: { type: "ephemeral", ttl: "1h" },
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the conversation cache marker on user text through trailing tool results", () => {
|
||||
it("keeps a stable user marker while advancing through trailing tool results", () => {
|
||||
const policy = resolveAnthropicPayloadPolicy({
|
||||
provider: "anthropic",
|
||||
api: "anthropic-messages",
|
||||
@@ -157,7 +158,14 @@ describe("anthropic payload policy", () => {
|
||||
});
|
||||
expect(payload.messages[4]).toEqual({
|
||||
role: "user",
|
||||
content: [{ type: "tool_result", tool_use_id: "tool_2", content: "next chunk" }],
|
||||
content: [
|
||||
{
|
||||
type: "tool_result",
|
||||
tool_use_id: "tool_2",
|
||||
content: "next chunk",
|
||||
cache_control: { type: "ephemeral" },
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -185,6 +185,9 @@ function applyAnthropicCacheControlToMessages(
|
||||
const blockRecord = block as Record<string, unknown>;
|
||||
if (blockRecord.type === "text" || blockRecord.type === "image") {
|
||||
blockRecord.cache_control = cacheControl;
|
||||
if (fallbackToolResult) {
|
||||
fallbackToolResult.cache_control = cacheControl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (blockRecord.type === "tool_result" && fallbackToolResult === undefined) {
|
||||
|
||||
@@ -1193,6 +1193,13 @@ function convertMessages(
|
||||
if (block.type === "text" || block.type === "image") {
|
||||
(block as typeof block & { cache_control?: typeof cacheControl }).cache_control =
|
||||
cacheControl;
|
||||
if (fallbackToolResult) {
|
||||
(
|
||||
fallbackToolResult as typeof fallbackToolResult & {
|
||||
cache_control?: typeof cacheControl;
|
||||
}
|
||||
).cache_control = cacheControl;
|
||||
}
|
||||
return params;
|
||||
}
|
||||
if (block.type === "tool_result" && fallbackToolResult === undefined) {
|
||||
|
||||
Reference in New Issue
Block a user