5
5
ConverseStreamCommandOutput ,
6
6
InvokeModelCommand ,
7
7
Message ,
8
+ ToolConfiguration ,
8
9
} from "@aws-sdk/client-bedrock-runtime" ;
9
10
import { fromNodeProviderChain } from "@aws-sdk/credential-providers" ;
10
11
@@ -291,9 +292,10 @@ class Bedrock extends BaseLLM {
291
292
const convertedMessages = this . _convertMessages ( messages ) ;
292
293
293
294
const shouldCacheSystemMessage =
294
- ! ! systemMessage && this . cacheBehavior ?. cacheSystemMessage ;
295
+ ! ! systemMessage && this . cacheBehavior ?. cacheSystemMessage || this . completionOptions . promptCaching ;
295
296
const enablePromptCaching =
296
- shouldCacheSystemMessage || this . cacheBehavior ?. cacheConversation ;
297
+ shouldCacheSystemMessage || this . cacheBehavior ?. cacheConversation || this . completionOptions . promptCaching ;
298
+ const shouldCacheToolsConfig = this . completionOptions . promptCaching ;
297
299
298
300
// Add header for prompt caching
299
301
if ( enablePromptCaching ) {
@@ -305,28 +307,34 @@ class Bedrock extends BaseLLM {
305
307
306
308
const supportsTools =
307
309
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
+
308
329
return {
309
330
modelId : options . model ,
310
- messages : convertedMessages ,
311
331
system : systemMessage
312
332
? shouldCacheSystemMessage
313
333
? [ { text : systemMessage } , { cachePoint : { type : "default" } } ]
314
334
: [ { text : systemMessage } ]
315
335
: 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 ,
330
338
inferenceConfig : {
331
339
maxTokens : options . maxTokens ,
332
340
temperature : options . temperature ,
0 commit comments