2020 BuiltinToolReturnPart ,
2121 DocumentUrl ,
2222 FilePart ,
23- FileSearchTool ,
2423 FinalResultEvent ,
2524 FunctionToolCallEvent ,
2625 FunctionToolResultEvent ,
@@ -3123,133 +3122,25 @@ def _generate_response_with_texts(response_id: str, texts: list[str]) -> Generat
31233122 )
31243123
31253124
3126- @pytest .mark .skip (reason = 'google-genai SDK does not support file_search tool type yet (version 1.46.0). Code is ready for when SDK adds support.' )
3127- async def test_google_model_file_search_tool (allow_model_requests : None , google_provider : GoogleProvider ):
3128- """Test FileSearchTool with Google models using grounding_metadata."""
3129- m = GoogleModel ('gemini-2.5-pro' , provider = google_provider )
3130- agent = Agent (m , system_prompt = 'You are a helpful assistant.' , builtin_tools = [FileSearchTool (vector_store_ids = ['files/test_doc_123' ])])
3131-
3132- result = await agent .run ('What information is in the uploaded document?' )
3133- assert result .all_messages () == snapshot (
3134- [
3135- ModelRequest (
3136- parts = [
3137- SystemPromptPart (
3138- content = 'You are a helpful assistant.' ,
3139- timestamp = IsDatetime (),
3140- ),
3141- UserPromptPart (
3142- content = 'What information is in the uploaded document?' ,
3143- timestamp = IsDatetime (),
3144- ),
3145- ]
3146- ),
3147- ModelResponse (
3148- parts = [
3149- BuiltinToolCallPart (
3150- tool_name = 'file_search' ,
3151- args = {'queries' : ['information uploaded document' ]},
3152- tool_call_id = IsStr (),
3153- provider_name = 'google-gla' ,
3154- ),
3155- BuiltinToolReturnPart (
3156- tool_name = 'file_search' ,
3157- content = [
3158- {
3159- 'title' : 'Document Title' ,
3160- 'uri' : 'https://example.com/document.pdf' ,
3161- }
3162- ],
3163- tool_call_id = IsStr (),
3164- timestamp = IsDatetime (),
3165- provider_name = 'google-gla' ,
3166- ),
3167- TextPart (
3168- content = IsStr (),
3169- ),
3170- ],
3171- usage = RequestUsage (
3172- input_tokens = IsInt (),
3173- output_tokens = IsInt (),
3174- ),
3175- model_name = 'gemini-2.5-pro' ,
3176- timestamp = IsDatetime (),
3177- provider_name = 'google-gla' ,
3178- provider_details = {'finish_reason' : 'STOP' },
3179- provider_response_id = IsStr (),
3180- finish_reason = 'stop' ,
3181- ),
3182- ]
3183- )
3184-
3185-
3186- @pytest .mark .skip (reason = 'google-genai SDK does not support file_search tool type yet (version 1.46.0). Code is ready for when SDK adds support.' )
3187- async def test_google_model_file_search_tool_stream (allow_model_requests : None , google_provider : GoogleProvider ):
3188- """Test FileSearchTool streaming with Google models."""
3189- m = GoogleModel ('gemini-2.5-pro' , provider = google_provider )
3190- agent = Agent (m , system_prompt = 'You are a helpful assistant.' , builtin_tools = [FileSearchTool (vector_store_ids = ['files/test_doc_123' ])])
3191-
3192- event_parts : list [Any ] = []
3193- async with agent .iter (user_prompt = 'What information is in the uploaded document?' ) as agent_run :
3194- async for node in agent_run :
3195- if Agent .is_model_request_node (node ) or Agent .is_call_tools_node (node ):
3196- async with node .stream (agent_run .ctx ) as request_stream :
3197- async for event in request_stream :
3198- event_parts .append (event )
3199-
3200- assert agent_run .result is not None
3201- messages = agent_run .result .all_messages ()
3202- assert messages == snapshot (
3203- [
3204- ModelRequest (
3205- parts = [
3206- SystemPromptPart (
3207- content = 'You are a helpful assistant.' ,
3208- timestamp = IsDatetime (),
3209- ),
3210- UserPromptPart (
3211- content = 'What information is in the uploaded document?' ,
3212- timestamp = IsDatetime (),
3213- ),
3214- ]
3215- ),
3216- ModelResponse (
3217- parts = [
3218- TextPart (
3219- content = IsStr (),
3220- )
3221- ],
3222- usage = RequestUsage (
3223- input_tokens = IsInt (),
3224- output_tokens = IsInt (),
3225- ),
3226- model_name = 'gemini-2.5-pro' ,
3227- timestamp = IsDatetime (),
3228- provider_name = 'google-gla' ,
3229- provider_details = {'finish_reason' : 'STOP' },
3230- provider_response_id = IsStr (),
3231- finish_reason = 'stop' ,
3232- ),
3233- ]
3234- )
3235-
3236- # Verify streaming events include file search parts
3237- assert len (event_parts ) > 0
3125+ # Integration tests for FileSearchTool are skipped because google-genai SDK v1.46.0
3126+ # does not support file_search as a tool type yet. The code is ready for when SDK adds support.
3127+ # Unit tests below validate the parsing logic.
32383128
32393129
32403130def test_map_file_search_grounding_metadata ():
32413131 """Test that _map_file_search_grounding_metadata correctly creates builtin tool parts."""
3242- from pydantic_ai .models .google import _map_file_search_grounding_metadata
32433132 from google .genai .types import GroundingMetadata
32443133
3134+ from pydantic_ai .models .google import _map_file_search_grounding_metadata # type: ignore[reportPrivateUsage]
3135+
32453136 # Test with retrieval queries
32463137 grounding_metadata = GroundingMetadata (
32473138 retrieval_queries = ['test query 1' , 'test query 2' ],
32483139 grounding_chunks = [],
32493140 )
3250-
3141+
32513142 call_part , return_part = _map_file_search_grounding_metadata (grounding_metadata , 'google-gla' )
3252-
3143+
32533144 assert call_part is not None
32543145 assert return_part is not None
32553146 assert call_part .tool_name == 'file_search'
@@ -3262,23 +3153,24 @@ def test_map_file_search_grounding_metadata():
32623153
32633154def test_map_file_search_grounding_metadata_no_queries ():
32643155 """Test that _map_file_search_grounding_metadata returns None when no retrieval queries."""
3265- from pydantic_ai .models .google import _map_file_search_grounding_metadata
32663156 from google .genai .types import GroundingMetadata
32673157
3158+ from pydantic_ai .models .google import _map_file_search_grounding_metadata # type: ignore[reportPrivateUsage]
3159+
32683160 # Test with no retrieval queries
32693161 grounding_metadata = GroundingMetadata (grounding_chunks = [])
3270-
3162+
32713163 call_part , return_part = _map_file_search_grounding_metadata (grounding_metadata , 'google-gla' )
3272-
3164+
32733165 assert call_part is None
32743166 assert return_part is None
32753167
32763168
32773169def test_map_file_search_grounding_metadata_none ():
32783170 """Test that _map_file_search_grounding_metadata handles None metadata."""
3279- from pydantic_ai .models .google import _map_file_search_grounding_metadata
3280-
3171+ from pydantic_ai .models .google import _map_file_search_grounding_metadata # type: ignore[reportPrivateUsage]
3172+
32813173 call_part , return_part = _map_file_search_grounding_metadata (None , 'google-gla' )
3282-
3174+
32833175 assert call_part is None
32843176 assert return_part is None
0 commit comments