@@ -273,6 +273,45 @@ def test_supported_models():
273273 },
274274 ),
275275 ),
276+ (
277+ "function_with_parameters_json_schema" ,
278+ types .FunctionDeclaration (
279+ name = "search_database" ,
280+ description = "Searches a database with given criteria." ,
281+ parameters_json_schema = {
282+ "type" : "object" ,
283+ "properties" : {
284+ "query" : {
285+ "type" : "string" ,
286+ "description" : "The search query" ,
287+ },
288+ "limit" : {
289+ "type" : "integer" ,
290+ "description" : "Maximum number of results" ,
291+ },
292+ },
293+ "required" : ["query" ],
294+ },
295+ ),
296+ anthropic_types .ToolParam (
297+ name = "search_database" ,
298+ description = "Searches a database with given criteria." ,
299+ input_schema = {
300+ "type" : "object" ,
301+ "properties" : {
302+ "query" : {
303+ "type" : "string" ,
304+ "description" : "The search query" ,
305+ },
306+ "limit" : {
307+ "type" : "integer" ,
308+ "description" : "Maximum number of results" ,
309+ },
310+ },
311+ "required" : ["query" ],
312+ },
313+ ),
314+ ),
276315]
277316
278317
@@ -346,3 +385,80 @@ async def mock_coro():
346385 mock_client .messages .create .assert_called_once ()
347386 _ , kwargs = mock_client .messages .create .call_args
348387 assert kwargs ["max_tokens" ] == 4096
388+
389+
390+ def test_part_to_message_block_with_content ():
391+ """Test that part_to_message_block handles content format."""
392+ from google .adk .models .anthropic_llm import part_to_message_block
393+
394+ # Create a function response part with content array.
395+ mcp_response_part = types .Part .from_function_response (
396+ name = "generate_sample_filesystem" ,
397+ response = {
398+ "content" : [{
399+ "type" : "text" ,
400+ "text" : '{"name":"root","node_type":"folder","children":[]}' ,
401+ }]
402+ },
403+ )
404+ mcp_response_part .function_response .id = "test_id_123"
405+
406+ result = part_to_message_block (mcp_response_part )
407+
408+ # ToolResultBlockParam is a TypedDict.
409+ assert isinstance (result , dict )
410+ assert result ["tool_use_id" ] == "test_id_123"
411+ assert result ["type" ] == "tool_result"
412+ assert not result ["is_error" ]
413+ # Verify the content was extracted from the content format.
414+ assert (
415+ '{"name":"root","node_type":"folder","children":[]}' in result ["content" ]
416+ )
417+
418+
419+ def test_part_to_message_block_with_traditional_result ():
420+ """Test that part_to_message_block handles traditional result format."""
421+ from google .adk .models .anthropic_llm import part_to_message_block
422+
423+ # Create a function response part with traditional result format
424+ traditional_response_part = types .Part .from_function_response (
425+ name = "some_tool" ,
426+ response = {
427+ "result" : "This is the result from the tool" ,
428+ },
429+ )
430+ traditional_response_part .function_response .id = "test_id_456"
431+
432+ result = part_to_message_block (traditional_response_part )
433+
434+ # ToolResultBlockParam is a TypedDict.
435+ assert isinstance (result , dict )
436+ assert result ["tool_use_id" ] == "test_id_456"
437+ assert result ["type" ] == "tool_result"
438+ assert not result ["is_error" ]
439+ # Verify the content was extracted from the traditional format
440+ assert "This is the result from the tool" in result ["content" ]
441+
442+
443+ def test_part_to_message_block_with_multiple_content_items ():
444+ """Test content with multiple items."""
445+ from google .adk .models .anthropic_llm import part_to_message_block
446+
447+ # Create a function response with multiple content items
448+ multi_content_part = types .Part .from_function_response (
449+ name = "multi_response_tool" ,
450+ response = {
451+ "content" : [
452+ {"type" : "text" , "text" : "First part" },
453+ {"type" : "text" , "text" : "Second part" },
454+ ]
455+ },
456+ )
457+ multi_content_part .function_response .id = "test_id_789"
458+
459+ result = part_to_message_block (multi_content_part )
460+
461+ # ToolResultBlockParam is a TypedDict.
462+ assert isinstance (result , dict )
463+ # Multiple text items should be joined with newlines
464+ assert result ["content" ] == "First part\n Second part"
0 commit comments