Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions docs/api-reference/veryfront/chat.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/api-reference/veryfront/provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ import {
| `createStreamRetentionBudget` | Create an empty retention budget. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/provider/runtime-loader/stream-retention.ts) |
| `createWarningCollector` | Create warning collector. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/provider/runtime-loader.ts) |
| `fileInputBaseName` | The base name of a file part's filename, or `undefined` when none is usable. Requests and errors leave the machine, so a local path must not. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/provider/runtime-loader/inline-file.ts) |
| `findActiveSkillPromptCall` | Find the prompt call that loaded the active skill. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/skill/active-skill.ts) |
| `getAnthropicMessagesUrl` | Return Anthropic messages URL. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/provider/runtime-loader/provider-endpoints.ts) |
| `getGoogleEmbeddingUrl` | Return Google embedding URL. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/provider/runtime-loader/provider-endpoints.ts) |
| `getGoogleGenerateContentUrl` | Return Google generate content URL. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/provider/runtime-loader/provider-endpoints.ts) |
Expand Down Expand Up @@ -237,6 +238,7 @@ import {

| Name | Description | Source |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------- |
| `ActiveSkillCall` | | [source](https://github.com/veryfront/veryfront-code/blob/main/src/skill/active-skill.ts) |
| `JsonSnapshotOptions` | Resource limits applied while taking a provider-boundary JSON snapshot. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/provider/runtime-loader/json-snapshot.ts) |
| `JsonSnapshotValue` | A deeply owned JSON value returned by `snapshotJsonValue`. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/provider/runtime-loader/json-snapshot.ts) |
| `ModelRuntimeCallOptions` | Canonical request contract passed to `ModelRuntime` generation hooks. | [source](https://github.com/veryfront/veryfront-code/blob/main/src/provider/types.ts) |
Expand Down
266 changes: 266 additions & 0 deletions extensions/ext-llm-anthropic/src/anthropic-request-builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4897,6 +4897,272 @@ describe("ext-llm-anthropic/anthropic-request-builder", () => {
assertEquals(body.thinking, { type: "enabled", budget_tokens: 4096 });
});

it("keeps the active skill round when it compacts completed historical tool rounds", () => {
const round = (toolCallId: string, instructions: string): RuntimePromptMessage[] => [
{
role: "assistant",
content: [{
type: "tool-call",
toolCallId,
toolName: "veryfront__load_skill",
input: { skillId: "plan" },
}],
},
{
role: "tool",
content: [{
type: "tool-result",
toolCallId,
toolName: "veryfront__load_skill",
output: { type: "json", value: { skillId: "plan", instructions } },
}],
},
];
const prompt: RuntimePromptMessage[] = [
{ role: "user", content: [{ type: "text", text: "Load the plan." }] },
...round("old", "OLD_SKILL"),
...round("active", "ACTIVE_SKILL"),
...round("repeat", 'Skill "plan" is already loaded in this turn.'),
{ role: "assistant", content: [{ type: "text", text: "Loaded." }] },
{ role: "user", content: [{ type: "text", text: "Continue." }] },
];

const body = buildAnthropicMessagesRequest(
"claude-sonnet-4-6",
"anthropic",
{ prompt },
false,
createWarningCollector(),
);

const serialized = JSON.stringify(body.messages);
assertEquals(serialized.includes("ACTIVE_SKILL"), true);
assertEquals(serialized.includes("OLD_SKILL"), false);
assertEquals(
body.messages.flatMap(({ content }: { content: Array<Record<string, unknown>> }) =>
content.flatMap((block) =>
block.type === "tool_use"
? [`use:${block.id}`]
: block.type === "tool_result"
? [`result:${block.tool_use_id}`]
: []
)
),
["use:active", "result:active"],
);
});

const skillCallPart = {
type: "tool-call" as const,
toolCallId: "active",
toolName: "load_skill",
input: { skillId: "plan" },
};
const largeCallPart = {
type: "tool-call" as const,
toolCallId: "large",
toolName: "read_file",
input: {},
};
const skillResultPart = {
type: "tool-result" as const,
toolCallId: "active",
toolName: "load_skill",
output: { type: "json" as const, value: { skillId: "plan", instructions: "ACTIVE" } },
};
const largeResultPart = {
type: "tool-result" as const,
toolCallId: "large",
toolName: "read_file",
output: { type: "json" as const, value: "LARGE ".repeat(50_000) },
};
const skillPairMessages = [
{ role: "user", content: [{ type: "text", text: "Load the plan." }] },
{
role: "assistant",
content: [
{ type: "text", text: "Loading." },
{ type: "tool_use", id: "active", name: "load_skill", input: { skillId: "plan" } },
],
},
{
role: "user",
content: [{
type: "tool_result",
tool_use_id: "active",
content: '{"skillId":"plan","instructions":"ACTIVE"}',
}],
},
{ role: "assistant", content: [{ type: "text", text: "Loaded." }] },
{ role: "user", content: [{ type: "text", text: "Continue." }] },
];
function sentSkillRound(
round: RuntimePromptMessage,
between: RuntimePromptMessage[],
): unknown {
const body = buildAnthropicMessagesRequest(
"claude-sonnet-4-6",
"anthropic",
{
prompt: [
{ role: "user", content: [{ type: "text", text: "Load the plan." }] },
round,
...between,
{ role: "assistant", content: [{ type: "text", text: "Loaded." }] },
{ role: "user", content: [{ type: "text", text: "Continue." }] },
],
},
false,
createWarningCollector(),
);
return JSON.parse(JSON.stringify(body.messages));
}
const parallelRound: RuntimePromptMessage = {
role: "assistant",
content: [{ type: "text", text: "Loading." }, largeCallPart, skillCallPart],
};

it("keeps only the active skill pair from a historical parallel round", () => {
for (
const between of [
[{ role: "tool" as const, content: [largeResultPart, skillResultPart] }],
[
{ role: "tool" as const, content: [largeResultPart] },
{ role: "tool" as const, content: [skillResultPart] },
],
// The parallel call has no result.
[{ role: "tool" as const, content: [skillResultPart] }],
]
) {
assertEquals(sentSkillRound(parallelRound, between), skillPairMessages);
}
});

it("keeps only the active skill pair when it has no parallel call", () => {
assertEquals(
sentSkillRound(
{ role: "assistant", content: [{ type: "text", text: "Loading." }, skillCallPart] },
[{ role: "tool", content: [skillResultPart] }],
),
skillPairMessages,
);
});

it("sends no skill call when its result is missing or not next to it", () => {
const withoutTools = skillPairMessages.filter((_, index) => index !== 2).map((message) => ({
...message,
content: message.content.filter((block) => block.type === "text"),
}));
assertEquals(
sentSkillRound(parallelRound, [{ role: "tool", content: [largeResultPart] }]),
withoutTools,
);
const separated = JSON.stringify(sentSkillRound(parallelRound, [
{ role: "assistant", content: [{ type: "text", text: "Waiting." }] },
{ role: "tool", content: [skillResultPart] },
]));
assertEquals(separated.includes("tool_use"), false);
assertEquals(separated.includes("tool_result"), false);
});

it("drops thinking and server tools beside a partial skill round", () => {
const largeUse = { type: "tool_use", id: "large", name: "read_file", input: {} };
const serverUse = {
type: "server_tool_use",
id: "server_search",
name: "web_search",
input: { query: "plan" },
};
for (
const { parallel, siblings } of [
{ parallel: [largeCallPart], siblings: [largeUse] },
{ parallel: [], siblings: [serverUse] },
// The raw message has a call that the canonical history no longer has.
{ parallel: [], siblings: [largeUse] },
]
) {
assertEquals(
sentSkillRound({
role: "assistant",
content: [{ type: "text", text: "Loading." }, ...parallel, skillCallPart],
providerMetadata: {
anthropic: {
rawAssistantMessages: [[
{ type: "thinking", thinking: "Load it.", signature: "signed" },
{ type: "text", text: "Loading." },
...siblings,
{ type: "tool_use", id: "active", name: "load_skill", input: { skillId: "plan" } },
]],
},
},
}, [{ role: "tool", content: [largeResultPart, skillResultPart] }]),
skillPairMessages,
);
}
});

it("replays thinking with the active skill round and its result", () => {
const body = buildAnthropicMessagesRequest(
"claude-sonnet-4-6",
"anthropic",
{
prompt: [
{ role: "user", content: [{ type: "text", text: "Load the plan." }] },
{
role: "assistant",
content: [{
type: "tool-call",
toolCallId: "active",
toolName: "load_skill",
input: { skillId: "plan" },
}],
providerMetadata: {
anthropic: {
rawAssistantMessages: [[
{ type: "thinking", thinking: "Load it.", signature: "signed" },
{
type: "tool_use",
id: "active",
name: "load_skill",
input: { skillId: "plan" },
},
]],
},
},
},
{
role: "tool",
content: [{
type: "tool-result",
toolCallId: "active",
toolName: "load_skill",
output: { type: "json", value: { skillId: "plan", instructions: "ACTIVE" } },
}],
},
{ role: "assistant", content: [{ type: "text", text: "Loaded." }] },
{ role: "user", content: [{ type: "text", text: "Continue." }] },
],
},
false,
createWarningCollector(),
);

assertEquals(JSON.parse(JSON.stringify(body.messages)).slice(1, 3), [{
role: "assistant",
content: [
{ type: "thinking", thinking: "Load it.", signature: "signed" },
{ type: "tool_use", id: "active", name: "load_skill", input: { skillId: "plan" } },
],
}, {
role: "user",
content: [{
type: "tool_result",
tool_use_id: "active",
content: '{"skillId":"plan","instructions":"ACTIVE"}',
}],
}]);
});

it("compacts completed historical tool rounds before replaying later user turns", () => {
const prompt: RuntimePromptMessage[] = [
{ role: "user", content: [{ type: "text", text: "Build a briefing." }] },
Expand Down
Loading
Loading