From c9ee0f138a5f853805118d824e6eb24a501f1a2f Mon Sep 17 00:00:00 2001 From: Dustin Healy <54083382+dustinhealy@users.noreply.github.com> Date: Thu, 13 Nov 2025 07:21:50 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=A8=20feat:=20Add=20Bedrock=20Prompt?= =?UTF-8?q?=20Caching=20Support=20(#8271)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add Bedrock Cache Control Functionality - fix: Update Bedrock Cache Control to Require cachePoint as a Separate Content Block - Modified the addBedrockCacheControl function to ensure cachePoint is added as a separate content block in the content array, rather than as a property of text objects. - refactor: move addBedrockCacheControl over to packages/api - ci: add tests for addBedrockCacheControl until full coverage reached * ci: add test similar to example from the langchain PR * refactor: move addBedrockCacheControl logic and tests to agents repository * chore: remove extraneous comment * chore: update @librechat/agents dependency to version 3.0.12 * chore: update @librechat/agents dependency to version 3.0.13 * chore: update @librechat/agents dependency to version 3.0.14 * chore: update @librechat/agents to v3.0.15 * chore: update default value for prompt cache setting to true * refactor: set default promptCache to true for claude and nova models --------- Co-authored-by: Danny Avila --- api/package.json | 2 +- package-lock.json | 12 ++++++------ packages/api/package.json | 2 +- packages/data-provider/src/bedrock.ts | 12 ++++++++++++ packages/data-provider/src/parameterSettings.ts | 17 +++++++++++++++++ 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/api/package.json b/api/package.json index a2769afa80..29e87337ea 100644 --- a/api/package.json +++ b/api/package.json @@ -47,7 +47,7 @@ "@langchain/google-genai": "^0.2.13", "@langchain/google-vertexai": "^0.2.13", "@langchain/textsplitters": "^0.1.0", - "@librechat/agents": "^3.0.11", + "@librechat/agents": "^3.0.15", "@librechat/api": "*", "@librechat/data-schemas": "*", "@microsoft/microsoft-graph-client": "^3.0.7", diff --git a/package-lock.json b/package-lock.json index 842e87a546..c8d8427db1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -63,7 +63,7 @@ "@langchain/google-genai": "^0.2.13", "@langchain/google-vertexai": "^0.2.13", "@langchain/textsplitters": "^0.1.0", - "@librechat/agents": "^3.0.11", + "@librechat/agents": "^3.0.15", "@librechat/api": "*", "@librechat/data-schemas": "*", "@microsoft/microsoft-graph-client": "^3.0.7", @@ -16666,13 +16666,13 @@ } }, "node_modules/@librechat/agents": { - "version": "3.0.11", - "resolved": "https://registry.npmjs.org/@librechat/agents/-/agents-3.0.11.tgz", - "integrity": "sha512-Qey74ZptzKRBHVjei4m/dhplBDgZ5lcNPz1MugYWmVJHTJ7AK+m6zJYtSLDAYal10Yz/RP+oFIo2zJJS+VbFXQ==", + "version": "3.0.15", + "resolved": "https://registry.npmjs.org/@librechat/agents/-/agents-3.0.15.tgz", + "integrity": "sha512-iJyUZnfZrPgCeuhCEMOTJW5rp2z6QBsERwytNAr6haSXKiN4F7A6yfzJUkSTTLAu49+xoMIANAOMi8POaFdZ9Q==", "license": "MIT", "dependencies": { "@langchain/anthropic": "^0.3.26", - "@langchain/aws": "^0.1.12", + "@langchain/aws": "^0.1.15", "@langchain/core": "^0.3.79", "@langchain/deepseek": "^0.0.2", "@langchain/google-genai": "^0.2.13", @@ -46470,7 +46470,7 @@ "@azure/storage-blob": "^12.27.0", "@keyv/redis": "^4.3.3", "@langchain/core": "^0.3.79", - "@librechat/agents": "^3.0.11", + "@librechat/agents": "^3.0.15", "@librechat/data-schemas": "*", "@modelcontextprotocol/sdk": "^1.21.0", "axios": "^1.12.1", diff --git a/packages/api/package.json b/packages/api/package.json index 16ecd2a123..087e8a0f04 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -83,7 +83,7 @@ "@azure/storage-blob": "^12.27.0", "@keyv/redis": "^4.3.3", "@langchain/core": "^0.3.79", - "@librechat/agents": "^3.0.11", + "@librechat/agents": "^3.0.15", "@librechat/data-schemas": "*", "@modelcontextprotocol/sdk": "^1.21.0", "axios": "^1.12.1", diff --git a/packages/data-provider/src/bedrock.ts b/packages/data-provider/src/bedrock.ts index fa9bc98eb8..2a4184729f 100644 --- a/packages/data-provider/src/bedrock.ts +++ b/packages/data-provider/src/bedrock.ts @@ -37,6 +37,7 @@ export const bedrockInputSchema = s.tConversationSchema stop: true, thinking: true, thinkingBudget: true, + promptCache: true, /* Catch-all fields */ topK: true, additionalModelRequestFields: true, @@ -78,6 +79,7 @@ export const bedrockInputParser = s.tConversationSchema stop: true, thinking: true, thinkingBudget: true, + promptCache: true, /* Catch-all fields */ topK: true, additionalModelRequestFields: true, @@ -100,6 +102,7 @@ export const bedrockInputParser = s.tConversationSchema 'temperature', 'topP', 'stop', + 'promptCache', ]; const additionalFields: Record = {}; @@ -140,6 +143,15 @@ export const bedrockInputParser = s.tConversationSchema delete additionalFields.thinkingBudget; } + /** Default promptCache for claude and nova models, if not defined */ + if ( + typeof typedData.model === 'string' && + (typedData.model.includes('claude') || typedData.model.includes('nova')) && + typedData.promptCache === undefined + ) { + typedData.promptCache = true; + } + if (Object.keys(additionalFields).length > 0) { typedData.additionalModelRequestFields = { ...((typedData.additionalModelRequestFields as Record | undefined) || {}), diff --git a/packages/data-provider/src/parameterSettings.ts b/packages/data-provider/src/parameterSettings.ts index 93d85d237e..806a5f4bbd 100644 --- a/packages/data-provider/src/parameterSettings.ts +++ b/packages/data-provider/src/parameterSettings.ts @@ -492,6 +492,19 @@ const bedrock: Record = { default: 0.999, range: { min: 0, max: 1, step: 0.01 }, }), + promptCache: { + key: 'promptCache', + label: 'com_endpoint_prompt_cache', + labelCode: true, + type: 'boolean', + description: 'com_endpoint_anthropic_prompt_cache', + descriptionCode: true, + default: true, + component: 'switch', + optionType: 'conversation', + showDefault: false, + columnSpan: 2, + }, }; const mistral: Record = { @@ -752,6 +765,7 @@ const bedrockAnthropic: SettingsConfiguration = [ baseDefinitions.stop, librechat.resendFiles, bedrock.region, + bedrock.promptCache, anthropic.thinking, anthropic.thinkingBudget, librechat.fileTokenLimit, @@ -789,6 +803,7 @@ const bedrockGeneral: SettingsConfiguration = [ meta.topP, librechat.resendFiles, bedrock.region, + bedrock.promptCache, librechat.fileTokenLimit, ]; @@ -807,6 +822,7 @@ const bedrockAnthropicCol2: SettingsConfiguration = [ bedrock.topK, librechat.resendFiles, bedrock.region, + bedrock.promptCache, anthropic.thinking, anthropic.thinkingBudget, librechat.fileTokenLimit, @@ -856,6 +872,7 @@ const bedrockGeneralCol2: SettingsConfiguration = [ meta.topP, librechat.resendFiles, bedrock.region, + bedrock.promptCache, librechat.fileTokenLimit, ];