mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
91ec80c606b812a6e92e62056e3ee546db1414ff
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
b57a3d43e4 |
feat: Allow google search tool to set different model
Merge https://github.com/google/adk-python/pull/4136 **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):** Allow google search tool to set different model #4135 **2. Or, if no issue exists, describe the change:** _If applicable, please follow the issue templates to provide as much detail as possible._ **Problem:** Currently, the Google Search tool inherits and uses the same LLM model set from the parent agent for processing and summarizing search results. This creates a limitation for users who wish to decouple the agent's reasoning model from the model used for search summarization (e.g., for cost optimization or using a lightweight model for simpler summarization tasks). **Solution:** I have updated the Google Search tool to accept an optional LLM model parameter. Custom Model: Users can now explicitly specify which model should be used for processing search results. Default Behavior: If no model is specified, the tool defaults to the parent agent's model, ensuring backward compatibility. ``` # If a custom model is specified, use it instead of the original model if self.model is not None: llm_request.model = self.model ``` ### Testing Plan Added a new test case test_process_llm_request_with_custom_model in [test_google_search_tool.py] that verifies: When a custom model parameter is provided to GoogleSearchTool, it overrides the model from the incoming llm_request during process_llm_request The tool correctly uses the custom model for LLM calls while maintaining other request parameters **Unit Tests:** - [X] I have added or updated unit tests for my change. - [X] All unit tests pass locally. (base) wanglu2:adk-python/ (feature/allow-google-search-tool-set-different-llm✗) $ uv run pytest ./tests/unittests/tools/test_google_search_tool.py [22:07:32] ======================================================================== test session starts ======================================================================== platform darwin -- Python 3.13.1, pytest-9.0.2, pluggy-1.6.0 rootdir: /Users/wanglu2/Documents/Git/adk-python configfile: pyproject.toml plugins: mock-3.15.1, anyio-4.12.0, xdist-3.8.0, asyncio-1.3.0, langsmith-0.6.0 asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function collected 21 items tests/unittests/tools/test_google_search_tool.py ..................... [100%] ======================================================================== 21 passed in 7.91s ========================================================================= ### 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. - [ ] Any dependent changes have been merged and published in downstream modules. ### Additional context Co-authored-by: Kathy Wu <wukathy@google.com> COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/4136 from lwangverizon:feature/allow-google-search-tool-set-different-llm 239ea9577bd7befc9a3574aca48dc8243d55192c PiperOrigin-RevId: 859265757 |
||
|
|
8e69a58df4 |
feat: Add support to automatically create a session if one does not exist
feature/auto-create-new-session Merge https://github.com/google/adk-python/pull/4072 **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 **2. Or, if no issue exists, describe the change:** **Problem:** When building frontend applications with ADK, there's a limitation where frontends cannot always guarantee that `create_session` is called before initiating a conversation. This creates friction in the user experience because: - Users may refresh the page or navigate directly to a conversation URL with a specific session_id - Frontend state management may lose track of whether a session was already created - Mobile apps or single-page applications have complex lifecycle management where ensuring `create_session` is called first adds unnecessary complexity - This forces developers to implement additional logic to check session existence before every conversation Currently, if `get_session` is called with a non-existent session_id, it returns `None`, requiring the frontend to explicitly handle this case and call `create_session` separately. **Solution:** Modified the `get_session` method in `DatabaseSessionService` to automatically create a session if it doesn't exist in the database. This "get or create" pattern is common in many frameworks and provides a more developer-friendly API. The implementation: 1. Attempts to fetch the session from the database 2. If the session doesn't exist (returns `None`), automatically calls `create_session` with the provided parameters 3. Retrieves and returns the newly created session 4. Maintains backward compatibility - existing code continues to work without changes This allows frontends to simply call `get_session` with a session_id and be confident that the session will be available, regardless of whether it was previously created. **Benefits:** - Simplifies frontend integration by removing the need to track session creation state - Reduces API calls (no need to check existence before calling get_session) - Follows the principle of least surprise - getting a session with an ID should work reliably - No breaking changes to existing code that checks for `None` return values ### Testing Plan **Unit Tests:** - [x] I have added or updated unit tests for my change. - [x] All unit tests pass locally. **pytest results:** COPYBARA_INTEGRATE_REVIEW=https://github.com/google/adk-python/pull/4072 from lwangverizon:feature/auto-create-new-session 5475c6ae91d12332598d521302736eb1db79a8be PiperOrigin-RevId: 856019482 |