@@ -198,7 +198,7 @@ func TestConvertGenaiToolsToBedrock(t *testing.T) {
198198 },
199199 }}}}
200200
201- bt1 , nm1 := convertGenaiToolsToBedrock (tools )
201+ bt1 , nm1 := convertGenaiToolsToBedrock (tools , false , "" )
202202 schema := extractSchema (t , bt1 , nm1 )
203203
204204 props := schema ["properties" ].(map [string ]any )
@@ -226,7 +226,7 @@ func TestConvertGenaiToolsToBedrock(t *testing.T) {
226226 },
227227 }}}}
228228
229- bt2 , nm2 := convertGenaiToolsToBedrock (tools )
229+ bt2 , nm2 := convertGenaiToolsToBedrock (tools , false , "" )
230230 schema := extractSchema (t , bt2 , nm2 )
231231 props , ok := schema ["properties" ].(map [string ]any )
232232 if ! ok || len (props ) == 0 {
@@ -247,7 +247,7 @@ func TestConvertGenaiToolsToBedrock(t *testing.T) {
247247 ParametersJsonSchema : s ,
248248 }}}}
249249
250- bt3 , nm3 := convertGenaiToolsToBedrock (tools )
250+ bt3 , nm3 := convertGenaiToolsToBedrock (tools , false , "" )
251251 schema := extractSchema (t , bt3 , nm3 )
252252 props , ok := schema ["properties" ].(map [string ]any )
253253 if ! ok || len (props ) == 0 {
@@ -402,7 +402,7 @@ func TestConvertGenaiToolsToBedrockSanitizesNames(t *testing.T) {
402402 {Name : "filesystem:read_file" , Description : "Read a file" },
403403 }}}
404404
405- bedrockTools , nameMap := convertGenaiToolsToBedrock (tools )
405+ bedrockTools , nameMap := convertGenaiToolsToBedrock (tools , false , "" )
406406 if len (bedrockTools ) != 2 {
407407 t .Fatalf ("expected 2 tools, got %d" , len (bedrockTools ))
408408 }
@@ -672,3 +672,77 @@ func TestBuildInferenceConfig(t *testing.T) {
672672 })
673673 }
674674}
675+
676+ func TestConvertGenaiToolsToBedrockPromptCaching (t * testing.T ) {
677+ tools := []* genai.Tool {{FunctionDeclarations : []* genai.FunctionDeclaration {
678+ {Name : "get_weather" , Description : "lookup weather" },
679+ {Name : "list_pods" , Description : "list pods" },
680+ }}}
681+
682+ t .Run ("disabled: no cache marker appended" , func (t * testing.T ) {
683+ out , _ := convertGenaiToolsToBedrock (tools , false , "" )
684+ if len (out ) != 2 {
685+ t .Fatalf ("expected 2 tools, got %d" , len (out ))
686+ }
687+ for i , tool := range out {
688+ if _ , ok := tool .(* types.ToolMemberCachePoint ); ok {
689+ t .Fatalf ("did not expect a CachePoint at index %d when caching disabled" , i )
690+ }
691+ }
692+ })
693+
694+ t .Run ("enabled: cache marker appended at the END of the tool list" , func (t * testing.T ) {
695+ out , _ := convertGenaiToolsToBedrock (tools , true , "" )
696+ if len (out ) != 3 {
697+ t .Fatalf ("expected 3 entries (2 tools + 1 CachePoint), got %d" , len (out ))
698+ }
699+ // The first two must remain ToolSpec entries (order preserved).
700+ for i := range 2 {
701+ if _ , ok := out [i ].(* types.ToolMemberToolSpec ); ! ok {
702+ t .Fatalf ("entry %d: expected ToolMemberToolSpec, got %T" , i , out [i ])
703+ }
704+ }
705+ // The trailing entry must be a CachePoint with type=default.
706+ cp , ok := out [2 ].(* types.ToolMemberCachePoint )
707+ if ! ok {
708+ t .Fatalf ("trailing entry: expected ToolMemberCachePoint, got %T" , out [2 ])
709+ }
710+ if cp .Value .Type != types .CachePointTypeDefault {
711+ t .Errorf ("expected CachePointType=default, got %v" , cp .Value .Type )
712+ }
713+ // Default (empty) TTL must leave Ttl unset so Bedrock applies its
714+ // standard 5-minute cache (broadest model support).
715+ if cp .Value .Ttl != "" {
716+ t .Errorf ("expected unset Ttl for default cache, got %q" , cp .Value .Ttl )
717+ }
718+ })
719+
720+ t .Run (`cacheTTL "5m": Ttl left unset (default 5-minute cache)` , func (t * testing.T ) {
721+ out , _ := convertGenaiToolsToBedrock (tools , true , "5m" )
722+ cp , ok := out [len (out )- 1 ].(* types.ToolMemberCachePoint )
723+ if ! ok {
724+ t .Fatalf ("trailing entry: expected ToolMemberCachePoint, got %T" , out [len (out )- 1 ])
725+ }
726+ if cp .Value .Ttl != "" {
727+ t .Errorf ("expected unset Ttl for 5m, got %q" , cp .Value .Ttl )
728+ }
729+ })
730+
731+ t .Run (`cacheTTL "1h": Ttl set to extended-TTL caching` , func (t * testing.T ) {
732+ out , _ := convertGenaiToolsToBedrock (tools , true , "1h" )
733+ cp , ok := out [len (out )- 1 ].(* types.ToolMemberCachePoint )
734+ if ! ok {
735+ t .Fatalf ("trailing entry: expected ToolMemberCachePoint, got %T" , out [len (out )- 1 ])
736+ }
737+ if cp .Value .Ttl != types .CacheTTLOneHour {
738+ t .Errorf ("expected Ttl=%q, got %q" , types .CacheTTLOneHour , cp .Value .Ttl )
739+ }
740+ })
741+
742+ t .Run ("enabled but no tools: no cache marker (skipped)" , func (t * testing.T ) {
743+ out , _ := convertGenaiToolsToBedrock (nil , true , "" )
744+ if len (out ) != 0 {
745+ t .Fatalf ("expected empty slice for no tools, got %d entries" , len (out ))
746+ }
747+ })
748+ }
0 commit comments