forked from google/adk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] main from google:main #66
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
Merged
Merged
Conversation
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
…ng, and fix serialization
* **Async Safety:** Improved TraceManager context variable handling to ensure correct context isolation in concurrent asynchronous operations. This was achieved by using immutable tuples for the span stack and making copies of context dictionaries before modification.
* **Enhanced Logging:** The BigQueryAgentAnalyticsPlugin now captures richer metadata, including:
* Root agent name (via a new context variable).
* LLM model name and version.
* Usage metadata from LLM requests and responses.
* **Serialization Fix:** Updated BigQueryAgentAnalyticsPlugin to prevent JSON serialization errors when logging custom objects (e.g., Dataclasses). These are now automatically converted to dictionaries or string representations to ensure successful insertion into BigQuery.
PiperOrigin-RevId: 855415320
Merge #3756 move event iteration inside api_client context in get_session Move event iteration inside the api_client context manager in VertexAiSessionService.get_session() to prevent client closure during multi-page event fetching. **Please ensure you have read the [contribution guide](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) before creating a pull request.** ### Link to Issue or Description of Change **1. Link to an existing issue (if applicable):** - Closes: #3757 **2. Or, if no issue exists, describe the change:** **Problem:** When a session contains more than 100 events (requiring pagination), `VertexAiSessionService.get_session()` fails with: ``` RuntimeError: Cannot send a request, as the client has been closed. ``` The root cause is that the `events_iterator` is consumed **outside** the `async with self._get_api_client() as api_client:` context block. When the iterator needs to fetch page 2, 3, etc., the API client has already been closed because the `async with` block has exited. ```python # Current buggy flow: async with self._get_api_client() as api_client: get_session_response, events_iterator = await asyncio.gather(...) # ← Client closed here async for event in events_iterator: # ← Fails on page 2+ (client closed) session.events.append(...) ``` **Solution:** Move the session creation, user validation, and event iteration **inside** the `async with` block so the API client remains open during the entire pagination process: ```python async with self._get_api_client() as api_client: get_session_response, events_iterator = await asyncio.gather(...) # Validation and session creation... async for event in events_iterator: # ← Now works for all pages session.events.append(...) # Client closed after all events are fetched ``` ### Testing Plan **Unit Tests:** - [x] I have added or updated unit tests for my change. - [x] All unit tests pass locally. ```bash pytest tests/unittests/sessions/test_vertex_ai_session_service.py -v ``` **Added regression test:** `test_get_session_pagination_keeps_client_open` - Creates a `MockAsyncClientWithPagination` that tracks whether it's inside the `async with` context - Raises `RuntimeError` if iteration happens outside the context (matching real httpx behavior) - Simulates 3 pages of events (100 + 100 + 50 = 250 events) - Verifies all 250 events are successfully retrieved **Manual End-to-End (E2E) Tests:** 1. Deploy an ADK agent to Vertex AI Agent Engine 2. Create a session and send 100+ messages to accumulate >100 events 3. Verify `get_session()` successfully retrieves all events without error **Before fix:** ``` RuntimeError: Cannot send a request, as the client has been closed. ``` **After fix:** - Session with 201 events (3 pages) loads successfully - All events are retrieved and appended to the session ### Checklist - [x] I have read the [CONTRIBUTING.md](https://github.com/google/adk-python/blob/main/CONTRIBUTING.md) document. - [x] I have performed a self-review of my own code. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have added tests that prove my fix is effective or that my feature works. - [x] New and existing unit tests pass locally with my changes. - [x] I have manually tested my changes end-to-end. - [x] Any dependent changes have been merged and published in downstream modules. ### Additional context This bug affects any production deployment where users have extended conversations. Sessions accumulating >100 events (which triggers pagination) become completely unusable as the agent cannot load the session to process new messages. The fix is minimal and maintains backward compatibility - it only changes the scope of the `async with` block without altering any logic or return values. **Affected versions:** Tested on google-adk 1.19.0, but the bug exists in earlier versions as well. COPYBARA_INTEGRATE_REVIEW=#3756 from AlexisMarasigan:fix/vertex-ai-session-service-paginatio 01fbafa PiperOrigin-RevId: 855451813
Co-authored-by: Liang Wu <wuliang@google.com> PiperOrigin-RevId: 855464349
activity_start, activity_end , and blob is sent via send_realtime_input, according to the docstring : https://github.com/googleapis/python-genai/blob/d98c757c7d9a88026ac0f9eb2b1b578e2e7f3bfe/google/genai/live.py#L251, they should be send separately, so makes sense they are mutally exclusive. And we already make them exclusive in our current logic: https://github.com/google/adk-python/blob/6c0bf85042c38c7bafe1c183f1bba8bee1ba3570/src/google/adk/flows/llm_flows/base_llm_flow.py#L264-L272, make it clear in docstring Co-authored-by: Xiang (Sean) Zhou <seanzhougoogle@google.com> PiperOrigin-RevId: 855492864
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )