1616
1717This script tests the following features:
18181. Basic text generation
19- 2. Google Search tool (via bypass_multi_tools_limit)
19+ 2. Google Search tool
20203. Multi-turn conversations with stateful interactions
21214. Google Search tool (additional coverage)
22225. Custom function tool (get_current_weather)
2323
24- NOTE: The Interactions API does NOT support mixing custom function calling tools
25- with built-in tools. To work around this, we use bypass_multi_tools_limit=True
26- on GoogleSearchTool, which converts it to a function calling tool (via
27- GoogleSearchAgentTool). The bypass only triggers when len(agent.tools) > 1,
28- so we include both GoogleSearchTool and get_current_weather in the agent.
29-
3024NOTE: Code execution via UnsafeLocalCodeExecutor is not compatible with function
3125calling mode because the model tries to call a function instead of outputting
3226code in markdown.
4135import logging
4236from pathlib import Path
4337import time
44- from typing import Optional
4538
4639from dotenv import load_dotenv
4740from google .adk .agents .run_config import RunConfig
4841from google .adk .cli .utils import logs
4942from google .adk .runners import InMemoryRunner
5043from google .adk .runners import Runner
5144from google .genai import types
45+ import httpx
5246
5347from .agent import root_agent
5448
@@ -67,7 +61,8 @@ async def call_agent_async(
6761 prompt : str ,
6862 agent_name : str = "" ,
6963 show_interaction_id : bool = True ,
70- ) -> tuple [str , Optional [str ]]:
64+ additional_parts : list [types .Part ] | None = None ,
65+ ) -> tuple [str , str | None ]:
7166 """Call the agent asynchronously with the user's prompt.
7267
7368 Args:
@@ -77,13 +72,16 @@ async def call_agent_async(
7772 prompt: The prompt to send
7873 agent_name: The expected agent name for filtering responses
7974 show_interaction_id: Whether to show interaction IDs in output
75+ additional_parts: Optional list of additional content parts (e.g. files)
8076
8177 Returns:
8278 A tuple of (response_text, interaction_id)
8379 """
84- content = types .Content (
85- role = "user" , parts = [types .Part .from_text (text = prompt )]
86- )
80+ parts = [types .Part .from_text (text = prompt )]
81+ if additional_parts :
82+ parts .extend (additional_parts )
83+
84+ content = types .Content (role = "user" , parts = parts )
8785
8886 final_response_text = ""
8987 last_interaction_id = None
@@ -264,6 +262,39 @@ async def test_custom_function_tool(runner: Runner, session_id: str):
264262 return interaction_id
265263
266264
265+ async def test_pdf_summarization (runner : Runner , session_id : str ) -> str | None :
266+ """Test PDF summarization using the Interactions API."""
267+ print ("\n " + "=" * 60 )
268+ print ("TEST 6: PDF Summarization" )
269+ print ("=" * 60 )
270+
271+ url = "https://storage.googleapis.com/cloud-samples-data/generative-ai/pdf/2403.05530.pdf"
272+ print (f"Downloading { url } ..." )
273+ async with httpx .AsyncClient () as client :
274+ response = await client .get (
275+ url , headers = {"User-Agent" : "Mozilla/5.0" }, follow_redirects = True
276+ )
277+ response .raise_for_status ()
278+ pdf_bytes = response .content
279+
280+ pdf_part = types .Part .from_bytes (data = pdf_bytes , mime_type = "application/pdf" )
281+ response , interaction_id = await call_agent_async (
282+ runner ,
283+ USER_ID ,
284+ session_id ,
285+ "Please summarize the attached PDF document." ,
286+ additional_parts = [pdf_part ],
287+ )
288+
289+ assert response , "Expected a non-empty response"
290+ assert len (response ) > 0 , f"Expected summary in response: { response } "
291+ assert (
292+ "gemini" in response .lower () or "multimodal" in response .lower ()
293+ ), f"Expected summary of PDF in response: { response } "
294+ print ("PASSED: PDF Summarization works" )
295+ return interaction_id
296+
297+
267298def check_interactions_api_available () -> bool :
268299 """Check if the interactions API is available in the SDK."""
269300 try :
@@ -311,6 +342,7 @@ async def run_all_tests():
311342 await test_multi_turn_conversation (runner , session .id )
312343 await test_google_search_tool (runner , session .id )
313344 await test_custom_function_tool (runner , session .id )
345+ await test_pdf_summarization (runner , session .id )
314346
315347 print ("\n " + "=" * 60 )
316348 print ("ALL TESTS PASSED (Interactions API)" )
0 commit comments