|
16 | 16 | from google.adk.events.event import Event |
17 | 17 | from google.adk.events.event_actions import EventActions |
18 | 18 | from google.adk.flows.llm_flows import contents |
| 19 | +from google.adk.flows.llm_flows.contents import request_processor |
19 | 20 | from google.adk.flows.llm_flows.functions import REQUEST_CONFIRMATION_FUNCTION_CALL_NAME |
20 | 21 | from google.adk.flows.llm_flows.functions import REQUEST_EUC_FUNCTION_CALL_NAME |
21 | 22 | from google.adk.models.llm_request import LlmRequest |
@@ -433,6 +434,58 @@ async def test_rewind_events_are_filtered_out(): |
433 | 434 | ] |
434 | 435 |
|
435 | 436 |
|
| 437 | +@pytest.mark.asyncio |
| 438 | +async def test_other_agent_empty_content(): |
| 439 | + """Test that other agent messages with only thoughts or empty content are filtered out.""" |
| 440 | + agent = Agent(model="gemini-2.5-flash", name="current_agent") |
| 441 | + llm_request = LlmRequest(model="gemini-2.5-flash") |
| 442 | + invocation_context = await testing_utils.create_invocation_context( |
| 443 | + agent=agent |
| 444 | + ) |
| 445 | + # Add events: user message, other agents with empty content, user message |
| 446 | + events = [ |
| 447 | + Event( |
| 448 | + invocation_id="inv1", |
| 449 | + author="user", |
| 450 | + content=types.UserContent("Hello"), |
| 451 | + ), |
| 452 | + # Other agent with only thoughts |
| 453 | + Event( |
| 454 | + invocation_id="inv2", |
| 455 | + author="other_agent1", |
| 456 | + content=types.ModelContent([ |
| 457 | + types.Part(text="This is a private thought", thought=True), |
| 458 | + types.Part(text="Another private thought", thought=True), |
| 459 | + ]), |
| 460 | + ), |
| 461 | + # Other agent with empty text and thoughts |
| 462 | + Event( |
| 463 | + invocation_id="inv3", |
| 464 | + author="other_agent2", |
| 465 | + content=types.ModelContent([ |
| 466 | + types.Part(text="", thought=False), |
| 467 | + types.Part(text="Secret thought", thought=True), |
| 468 | + ]), |
| 469 | + ), |
| 470 | + Event( |
| 471 | + invocation_id="inv4", |
| 472 | + author="user", |
| 473 | + content=types.UserContent("World"), |
| 474 | + ), |
| 475 | + ] |
| 476 | + invocation_context.session.events = events |
| 477 | + |
| 478 | + # Process the request |
| 479 | + async for _ in request_processor.run_async(invocation_context, llm_request): |
| 480 | + pass |
| 481 | + |
| 482 | + # Verify empty content events are completely filtered out |
| 483 | + assert llm_request.contents == [ |
| 484 | + types.UserContent("Hello"), |
| 485 | + types.UserContent("World"), |
| 486 | + ] |
| 487 | + |
| 488 | + |
436 | 489 | @pytest.mark.asyncio |
437 | 490 | async def test_events_with_empty_content_are_skipped(): |
438 | 491 | """Test that events with empty content (state-only changes) are skipped.""" |
@@ -471,6 +524,14 @@ async def test_events_with_empty_content_are_skipped(): |
471 | 524 | author="user", |
472 | 525 | content=types.Content(parts=[types.Part(text="")], role="model"), |
473 | 526 | ), |
| 527 | + # Event with content that has multiple empty text parts |
| 528 | + Event( |
| 529 | + invocation_id="inv6_2", |
| 530 | + author="user", |
| 531 | + content=types.Content( |
| 532 | + parts=[types.Part(text=""), types.Part(text="")], role="model" |
| 533 | + ), |
| 534 | + ), |
474 | 535 | # Event with content that has only inline data part |
475 | 536 | Event( |
476 | 537 | invocation_id="inv7", |
@@ -502,6 +563,15 @@ async def test_events_with_empty_content_are_skipped(): |
502 | 563 | role="user", |
503 | 564 | ), |
504 | 565 | ), |
| 566 | + # Event with mixed empty and non-empty text parts |
| 567 | + Event( |
| 568 | + invocation_id="inv9", |
| 569 | + author="user", |
| 570 | + content=types.Content( |
| 571 | + parts=[types.Part(text=""), types.Part(text="Mixed content")], |
| 572 | + role="user", |
| 573 | + ), |
| 574 | + ), |
505 | 575 | ] |
506 | 576 | invocation_context.session.events = events |
507 | 577 |
|
@@ -534,4 +604,8 @@ async def test_events_with_empty_content_are_skipped(): |
534 | 604 | ], |
535 | 605 | role="user", |
536 | 606 | ), |
| 607 | + types.Content( |
| 608 | + parts=[types.Part(text=""), types.Part(text="Mixed content")], |
| 609 | + role="user", |
| 610 | + ), |
537 | 611 | ] |
0 commit comments