Skip to content

Commit d350549

Browse files
Merge pull request continuedev#5371 from chezsmithy/feat-cache-tools-config
feat(config-yaml): Add promptCaching to Default Completion Options and enable Bedrock Tools Caching
2 parents 7e48feb + e29d188 commit d350549

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

core/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ export interface BaseCompletionOptions {
10231023
toolChoice?: ToolChoice;
10241024
reasoning?: boolean;
10251025
reasoningBudgetTokens?: number;
1026+
promptCaching?: boolean;
10261027
}
10271028

10281029
export interface ModelCapability {

core/llm/llms/Bedrock.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
ConverseStreamCommandOutput,
66
InvokeModelCommand,
77
Message,
8+
ToolConfiguration,
89
} from "@aws-sdk/client-bedrock-runtime";
910
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
1011

@@ -291,9 +292,10 @@ class Bedrock extends BaseLLM {
291292
const convertedMessages = this._convertMessages(messages);
292293

293294
const shouldCacheSystemMessage =
294-
!!systemMessage && this.cacheBehavior?.cacheSystemMessage;
295+
!!systemMessage && this.cacheBehavior?.cacheSystemMessage || this.completionOptions.promptCaching;
295296
const enablePromptCaching =
296-
shouldCacheSystemMessage || this.cacheBehavior?.cacheConversation;
297+
shouldCacheSystemMessage || this.cacheBehavior?.cacheConversation || this.completionOptions.promptCaching;
298+
const shouldCacheToolsConfig = this.completionOptions.promptCaching;
297299

298300
// Add header for prompt caching
299301
if (enablePromptCaching) {
@@ -305,28 +307,34 @@ class Bedrock extends BaseLLM {
305307

306308
const supportsTools =
307309
PROVIDER_TOOL_SUPPORT.bedrock?.(options.model || "") ?? false;
310+
311+
let toolConfig = supportsTools && options.tools
312+
? {
313+
tools: options.tools.map((tool) => ({
314+
toolSpec: {
315+
name: tool.function.name,
316+
description: tool.function.description,
317+
inputSchema: {
318+
json: tool.function.parameters,
319+
},
320+
},
321+
})),
322+
} as ToolConfiguration
323+
: undefined;
324+
325+
if (toolConfig?.tools && shouldCacheToolsConfig) {
326+
toolConfig.tools.push({ cachePoint: { type: "default" } });
327+
}
328+
308329
return {
309330
modelId: options.model,
310-
messages: convertedMessages,
311331
system: systemMessage
312332
? shouldCacheSystemMessage
313333
? [{ text: systemMessage }, { cachePoint: { type: "default" } }]
314334
: [{ text: systemMessage }]
315335
: undefined,
316-
toolConfig:
317-
supportsTools && options.tools
318-
? {
319-
tools: options.tools.map((tool) => ({
320-
toolSpec: {
321-
name: tool.function.name,
322-
description: tool.function.description,
323-
inputSchema: {
324-
json: tool.function.parameters,
325-
},
326-
},
327-
})),
328-
}
329-
: undefined,
336+
toolConfig: toolConfig,
337+
messages: convertedMessages,
330338
inferenceConfig: {
331339
maxTokens: options.maxTokens,
332340
temperature: options.temperature,

packages/config-yaml/src/schemas/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const completionOptionsSchema = z.object({
4949
n: z.number().optional(),
5050
reasoning: z.boolean().optional(),
5151
reasoningBudgetTokens: z.number().optional(),
52+
promptCaching: z.boolean().optional(),
5253
});
5354
export type CompletionOptions = z.infer<typeof completionOptionsSchema>;
5455

0 commit comments

Comments
 (0)