@@ -359,6 +359,38 @@ async fn test_tool_result_content_serialization() -> Result<()> {
359359 Ok ( ( ) )
360360}
361361
362+ #[ tokio:: test]
363+ async fn test_tool_result_content_with_array_structured_content ( ) -> Result < ( ) > {
364+ let structured =
365+ serde_json:: json!( [ { "city" : "SF" , "temp" : 72 } , { "city" : "NY" , "temp" : 65 } ] ) ;
366+ let mut tool_result = ToolResultContent :: new ( "call_123" , vec ! [ Content :: text( "forecast" ) ] ) ;
367+ tool_result. structured_content = Some ( structured) ;
368+
369+ let json = serde_json:: to_string ( & tool_result) ?;
370+ let deserialized: ToolResultContent = serde_json:: from_str ( & json) ?;
371+ assert_eq ! ( tool_result, deserialized) ;
372+ assert ! ( deserialized. structured_content. unwrap( ) . is_array( ) ) ;
373+
374+ Ok ( ( ) )
375+ }
376+
377+ #[ tokio:: test]
378+ async fn test_tool_result_content_with_primitive_structured_content ( ) -> Result < ( ) > {
379+ let structured = serde_json:: json!( 42 ) ;
380+ let mut tool_result = ToolResultContent :: new ( "call_123" , vec ! [ Content :: text( "count" ) ] ) ;
381+ tool_result. structured_content = Some ( structured) ;
382+
383+ let json = serde_json:: to_string ( & tool_result) ?;
384+ let deserialized: ToolResultContent = serde_json:: from_str ( & json) ?;
385+ assert_eq ! ( tool_result, deserialized) ;
386+ assert ! ( matches!(
387+ deserialized. structured_content,
388+ Some ( serde_json:: Value :: Number ( _) )
389+ ) ) ;
390+
391+ Ok ( ( ) )
392+ }
393+
362394#[ tokio:: test]
363395async fn test_sampling_message_with_tool_use ( ) -> Result < ( ) > {
364396 let message = SamplingMessage :: assistant_tool_use (
0 commit comments