Skip to content

Commit 387f7a6

Browse files
committed
Update MCP ResourceLink tests and add VCR cassettes
1 parent 1aa5c3d commit 387f7a6

File tree

1 file changed

+51
-41
lines changed

1 file changed

+51
-41
lines changed

tests/test_mcp.py

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,14 @@ async def test_tool_returning_text_resource(allow_model_requests: None, agent: A
443443
@pytest.mark.vcr()
444444
async def test_tool_returning_text_resource_link(allow_model_requests: None, agent: Agent):
445445
async with agent:
446-
result = await agent.run('Get me the product name')
446+
result = await agent.run('Get me the product name via get_product_name_link')
447447
assert result.output == snapshot('The product name is "Pydantic AI".')
448448
assert result.all_messages() == snapshot(
449449
[
450450
ModelRequest(
451451
parts=[
452452
UserPromptPart(
453-
content='Get me the product name',
453+
content='Get me the product name via get_product_name_link',
454454
timestamp=IsDatetime(),
455455
)
456456
]
@@ -460,14 +460,14 @@ async def test_tool_returning_text_resource_link(allow_model_requests: None, age
460460
ToolCallPart(
461461
tool_name='get_product_name_link',
462462
args='{}',
463-
tool_call_id='call_LaiWltzI39sdquflqeuF0EyE',
463+
tool_call_id='call_qi5GtBeIEyT7Y3yJvVFIi062',
464464
)
465465
],
466466
usage=Usage(
467467
requests=1,
468-
request_tokens=200,
468+
request_tokens=305,
469469
response_tokens=12,
470-
total_tokens=212,
470+
total_tokens=317,
471471
details={
472472
'accepted_prediction_tokens': 0,
473473
'audio_tokens': 0,
@@ -478,25 +478,25 @@ async def test_tool_returning_text_resource_link(allow_model_requests: None, age
478478
),
479479
model_name='gpt-4o-2024-08-06',
480480
timestamp=IsDatetime(),
481-
vendor_id='chatcmpl-BRmhyweJVYonarb7s9ckIMSHf2vHo',
481+
vendor_id='chatcmpl-BwdHSFe0EykAOpf0LWZzsWAodIQzb',
482482
),
483483
ModelRequest(
484484
parts=[
485485
ToolReturnPart(
486486
tool_name='get_product_name_link',
487-
content='PydanticAI',
488-
tool_call_id='call_LaiWltzI39sdquflqeuF0EyE',
487+
content='Pydantic AI\n',
488+
tool_call_id='call_qi5GtBeIEyT7Y3yJvVFIi062',
489489
timestamp=IsDatetime(),
490490
)
491491
]
492492
),
493493
ModelResponse(
494-
parts=[TextPart(content='The product name is "PydanticAI".')],
494+
parts=[TextPart(content='The product name is "Pydantic AI".')],
495495
usage=Usage(
496496
requests=1,
497-
request_tokens=224,
498-
response_tokens=12,
499-
total_tokens=236,
497+
request_tokens=332,
498+
response_tokens=11,
499+
total_tokens=343,
500500
details={
501501
'accepted_prediction_tokens': 0,
502502
'audio_tokens': 0,
@@ -507,7 +507,7 @@ async def test_tool_returning_text_resource_link(allow_model_requests: None, age
507507
),
508508
model_name='gpt-4o-2024-08-06',
509509
timestamp=IsDatetime(),
510-
vendor_id='chatcmpl-BRmhzqXFObpYwSzREMpJvX9kbDikR',
510+
vendor_id='chatcmpl-BwdHTIlBZWzXJPBR8VTOdC4O57ZQA',
511511
),
512512
]
513513
)
@@ -598,16 +598,16 @@ async def test_tool_returning_image_resource_link(
598598
allow_model_requests: None, agent: Agent, image_content: BinaryContent
599599
):
600600
async with agent:
601-
result = await agent.run('Get me the image resource')
601+
result = await agent.run('Get me the image resource via get_image_resource_link')
602602
assert result.output == snapshot(
603-
'This is an image of a sliced kiwi with a vibrant green interior and black seeds.'
603+
'This is an image of a sliced kiwi fruit. It shows the green, seed-speckled interior with fuzzy brown skin around the edges.'
604604
)
605605
assert result.all_messages() == snapshot(
606606
[
607607
ModelRequest(
608608
parts=[
609609
UserPromptPart(
610-
content='Get me the image resource',
610+
content='Get me the image resource via get_image_resource_link',
611611
timestamp=IsDatetime(),
612612
)
613613
]
@@ -617,14 +617,14 @@ async def test_tool_returning_image_resource_link(
617617
ToolCallPart(
618618
tool_name='get_image_resource_link',
619619
args='{}',
620-
tool_call_id='call_nFsDHYDZigO0rOHqmChZ3pmt',
620+
tool_call_id='call_eVFgn54V9Nuh8Y4zvuzkYjUp',
621621
)
622622
],
623623
usage=Usage(
624624
requests=1,
625-
request_tokens=191,
625+
request_tokens=305,
626626
response_tokens=12,
627-
total_tokens=203,
627+
total_tokens=317,
628628
details={
629629
'accepted_prediction_tokens': 0,
630630
'audio_tokens': 0,
@@ -635,14 +635,14 @@ async def test_tool_returning_image_resource_link(
635635
),
636636
model_name='gpt-4o-2024-08-06',
637637
timestamp=IsDatetime(),
638-
vendor_id='chatcmpl-BRlo7KYJVXuNZ5lLLdYcKZDsX2CHb',
638+
vendor_id='chatcmpl-BwdHygYePH1mZgHo2Xxzib0Y7sId7',
639639
),
640640
ModelRequest(
641641
parts=[
642642
ToolReturnPart(
643643
tool_name='get_image_resource_link',
644644
content='See file 1c8566',
645-
tool_call_id='call_nFsDHYDZigO0rOHqmChZ3pmt',
645+
tool_call_id='call_eVFgn54V9Nuh8Y4zvuzkYjUp',
646646
timestamp=IsDatetime(),
647647
),
648648
UserPromptPart(content=['This is file 1c8566:', image_content], timestamp=IsDatetime()),
@@ -651,14 +651,14 @@ async def test_tool_returning_image_resource_link(
651651
ModelResponse(
652652
parts=[
653653
TextPart(
654-
content='This is an image of a sliced kiwi with a vibrant green interior and black seeds.'
654+
content='This is an image of a sliced kiwi fruit. It shows the green, seed-speckled interior with fuzzy brown skin around the edges.'
655655
)
656656
],
657657
usage=Usage(
658658
requests=1,
659-
request_tokens=1332,
660-
response_tokens=19,
661-
total_tokens=1351,
659+
request_tokens=1452,
660+
response_tokens=29,
661+
total_tokens=1481,
662662
details={
663663
'accepted_prediction_tokens': 0,
664664
'audio_tokens': 0,
@@ -669,7 +669,7 @@ async def test_tool_returning_image_resource_link(
669669
),
670670
model_name='gpt-4o-2024-08-06',
671671
timestamp=IsDatetime(),
672-
vendor_id='chatcmpl-BRloBGHh27w3fQKwxq4fX2cPuZJa9',
672+
vendor_id='chatcmpl-BwdI2D2r9dvqq3pbsA0qgwKDEdTtD',
673673
),
674674
]
675675
)
@@ -735,23 +735,33 @@ async def test_tool_returning_audio_resource_link(
735735
):
736736
model = GoogleModel('gemini-2.5-pro-preview-03-25', provider=GoogleProvider(api_key=gemini_api_key))
737737
async with agent:
738-
result = await agent.run("What's the content of the audio resource?", model=model)
739-
assert result.output == snapshot('The audio resource contains a voice saying "Hello, my name is Marcelo."')
738+
result = await agent.run("What's the content of the audio resource via get_audio_resource_link?", model=model)
739+
assert result.output == snapshot('00:05')
740740
assert result.all_messages() == snapshot(
741741
[
742742
ModelRequest(
743-
parts=[UserPromptPart(content="What's the content of the audio resource?", timestamp=IsDatetime())]
743+
parts=[
744+
UserPromptPart(
745+
content="What's the content of the audio resource via get_audio_resource_link?",
746+
timestamp=IsDatetime(),
747+
)
748+
]
744749
),
745750
ModelResponse(
746-
parts=[ToolCallPart(tool_name='get_audio_resource_link', args={}, tool_call_id=IsStr())],
751+
parts=[
752+
TextPart(
753+
content='The content of the audio resource is at a link that can be accessed by calling the function `get_audio_resource_link`.'
754+
),
755+
ToolCallPart(tool_name='get_audio_resource_link', args={}, tool_call_id=IsStr()),
756+
],
747757
usage=Usage(
748758
requests=1,
749-
request_tokens=383,
750-
response_tokens=12,
751-
total_tokens=520,
752-
details={'thoughts_tokens': 125, 'text_prompt_tokens': 383},
759+
request_tokens=561,
760+
response_tokens=41,
761+
total_tokens=797,
762+
details={'thoughts_tokens': 195, 'text_prompt_tokens': 561},
753763
),
754-
model_name='models/gemini-2.5-pro-preview-05-06',
764+
model_name='models/gemini-2.5-pro',
755765
timestamp=IsDatetime(),
756766
vendor_details={'finish_reason': 'STOP'},
757767
),
@@ -767,15 +777,15 @@ async def test_tool_returning_audio_resource_link(
767777
]
768778
),
769779
ModelResponse(
770-
parts=[TextPart(content='The audio resource contains a voice saying "Hello, my name is Marcelo."')],
780+
parts=[TextPart(content='00:05')],
771781
usage=Usage(
772782
requests=1,
773-
request_tokens=575,
774-
response_tokens=15,
775-
total_tokens=590,
776-
details={'text_prompt_tokens': 431, 'audio_prompt_tokens': 144},
783+
request_tokens=784,
784+
response_tokens=5,
785+
total_tokens=789,
786+
details={'text_prompt_tokens': 640, 'audio_prompt_tokens': 144},
777787
),
778-
model_name='models/gemini-2.5-pro-preview-05-06',
788+
model_name='models/gemini-2.5-pro',
779789
timestamp=IsDatetime(),
780790
vendor_details={'finish_reason': 'STOP'},
781791
),

0 commit comments

Comments
 (0)