-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: expose live_session_resumption_update in events for cross-connection resumption #4358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AshleyMaloney
wants to merge
4
commits into
google:main
Choose a base branch
from
AshleyMaloney:fix/expose-live-session-resumption-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2f77fbb
feat: expose live_session_resumption_update in events for cross-conne…
AshleyMaloney 3cb4a66
refactor: consolidate live_session_resumption_update handling in _pos…
AshleyMaloney ecfc3a1
test: add unit tests for _postprocess_live session resumption
AshleyMaloney 55b0c59
Merge branch 'main' into fix/expose-live-session-resumption-update
AshleyMaloney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
tests/unittests/flows/llm_flows/test_base_llm_flow_session_resumption.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from google.adk.agents.llm_agent import Agent | ||
| from google.adk.events.event import Event | ||
| from google.adk.flows.llm_flows.base_llm_flow import BaseLlmFlow | ||
| from google.adk.models.llm_request import LlmRequest | ||
| from google.adk.models.llm_response import LlmResponse | ||
| from google.genai import types | ||
| import pytest | ||
|
|
||
| from ... import testing_utils | ||
|
|
||
|
|
||
| class BaseLlmFlowForTesting(BaseLlmFlow): | ||
| """Test implementation of BaseLlmFlow for testing purposes.""" | ||
|
|
||
| pass | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_postprocess_live_yields_session_resumption_event(): | ||
| """Test _postprocess_live yields event for session resumption update.""" | ||
| # Create a resumption update as received from Gemini Live API | ||
| resumption_update = types.LiveServerSessionResumptionUpdate( | ||
| new_handle='test-handle-abc123', | ||
| resumable=True, | ||
| ) | ||
|
|
||
| # Create LlmResponse with only a resumption update (no content) | ||
| llm_response = LlmResponse(live_session_resumption_update=resumption_update) | ||
|
|
||
| # Set up invocation context | ||
| agent = Agent(name='test_agent', model='mock') | ||
| invocation_context = await testing_utils.create_invocation_context( | ||
| agent=agent, user_content='' | ||
| ) | ||
|
|
||
| # Create the mutable event that _postprocess_live populates | ||
| model_response_event = Event( | ||
| id=Event.new_id(), | ||
| invocation_id=invocation_context.invocation_id, | ||
| author=agent.name, | ||
| ) | ||
|
|
||
| flow = BaseLlmFlowForTesting() | ||
| llm_request = LlmRequest() | ||
| events = [] | ||
|
|
||
| # Collect events from _postprocess_live | ||
| async for event in flow._postprocess_live( | ||
| invocation_context, llm_request, llm_response, model_response_event | ||
| ): | ||
| events.append(event) | ||
|
|
||
| # Verify event is yielded with resumption update | ||
| assert len(events) == 1 | ||
| assert events[0].live_session_resumption_update == resumption_update | ||
| assert ( | ||
| events[0].live_session_resumption_update.new_handle | ||
| == 'test-handle-abc123' | ||
| ) | ||
| assert events[0].live_session_resumption_update.resumable is True | ||
|
|
||
| # Verify invocation context handle is updated for auto-resumption | ||
| assert ( | ||
| invocation_context.live_session_resumption_handle == 'test-handle-abc123' | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_postprocess_live_skips_empty_response(): | ||
| """Test _postprocess_live skips response with no content or resumption.""" | ||
| # Create LlmResponse with no content and no resumption update | ||
| llm_response = LlmResponse() | ||
|
|
||
| # Set up invocation context | ||
| agent = Agent(name='test_agent', model='mock') | ||
| invocation_context = await testing_utils.create_invocation_context( | ||
| agent=agent, user_content='' | ||
| ) | ||
|
|
||
| model_response_event = Event( | ||
| id=Event.new_id(), | ||
| invocation_id=invocation_context.invocation_id, | ||
| author=agent.name, | ||
| ) | ||
|
|
||
| flow = BaseLlmFlowForTesting() | ||
| llm_request = LlmRequest() | ||
| events = [] | ||
|
|
||
| # Collect events from _postprocess_live | ||
| async for event in flow._postprocess_live( | ||
| invocation_context, llm_request, llm_response, model_response_event | ||
| ): | ||
| events.append(event) | ||
|
|
||
| # Verify no event is yielded for empty response | ||
| assert len(events) == 0 | ||
|
|
||
| # Verify handle remains unset | ||
| assert invocation_context.live_session_resumption_handle is None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.