forked from google/adk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
[pull] main from google:main #5
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
Merge #3576 **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: #3557 - Related: #_issue_number_ **2. Or, if no issue exists, describe the change:** _If applicable, please follow the issue templates to provide as much detail as possible._ **Problem:** When creating a BaseAgent with multiple sub-agents, there was no validation to ensure that all sub-agents have unique names. This could lead to confusion when trying to find or reference specific sub-agents by name, as duplicate names would make it ambiguous which agent is being referenced. **Solution:** Added a @field_validator for the sub_agents field in BaseAgent that validates all sub-agents have unique names. The validator: Checks for duplicate names in the sub-agents list Raises a ValueError with a clear error message listing all duplicate names found Returns the validated list if all names are unique Handles edge cases like empty lists gracefully ### Testing Plan _Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes._ **Unit Tests:** - [x] I have added or updated unit tests for my change. - [x] All unit tests pass locally. _Please include a summary of passed `pytest` results._ Added 4 new test cases in tests/unittests/agents/test_base_agent.py: test_validate_sub_agents_unique_names_single_duplicate: Verifies that a single duplicate name raises ValueError test_validate_sub_agents_unique_names_multiple_duplicates: Verifies that multiple duplicate names are all reported in the error message test_validate_sub_agents_unique_names_no_duplicates: Verifies that unique names pass validation successfully test_validate_sub_agents_unique_names_empty_list: Verifies that empty sub-agents list passes validation All tests pass locally. You can run with: pytest tests/unittests/agents/test_base_agent.py::test_validate_sub_agents_unique_names_single_duplicate tests/unittests/agents/test_base_agent.py::test_validate_sub_agents_unique_names_multiple_duplicates tests/unittests/agents/test_base_agent.py::test_validate_sub_agents_unique_names_no_duplicates tests/unittests/agents/test_base_agent.py::test_validate_sub_agents_unique_names_empty_list -v **Manual End-to-End (E2E) Tests:** _Please provide instructions on how to manually test your changes, including any necessary setup or configuration. Please provide logs or screenshots to help reviewers better understand the fix._ Test Case 1: Duplicate names should raise error from google.adk.agents import Agent agent1 = Agent(name="sub_agent", model="gemini-2.5-flash") agent2 = Agent(name="sub_agent", model="gemini-2.5-flash") # Same name # This should raise ValueError try: parent = Agent( name="parent", model="gemini-2.5-flash", sub_agents=[agent1, agent2] ) except ValueError as e: print(f"Expected error: {e}") # Output: Found duplicate sub-agent names: `sub_agent`. All sub-agents must have unique names. Test Case 2: Unique names should work from google.adk.agents import Agent agent1 = Agent(name="agent1", model="gemini-2.5-flash") agent2 = Agent(name="agent2", model="gemini-2.5-flash") # This should work without error parent = Agent( name="parent", model="gemini-2.5-flash", sub_agents=[agent1, agent2] ) print("Success: Unique names validated correctly") ### 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 change adds validation at the BaseAgent level, so it automatically applies to all agent types that inherit from BaseAgent (e.g., LlmAgent, LoopAgent, etc.). The validation uses Pydantic's field validator system, which runs during object initialization, ensuring the constraint is enforced early and consistently. The error message clearly identifies which names are duplicated, making it easy for developers to fix the issue: COPYBARA_INTEGRATE_REVIEW=#3576 from sarojrout:feat/validate-unique-sub-agent-names 07adf1f PiperOrigin-RevId: 835358118
… provided in FunctionDeclaration Co-authored-by: Xuan Yang <xygoogle@google.com> PiperOrigin-RevId: 835379243
This change replaces the use of `ChatCompletionDeveloperMessage` with `ChatCompletionSystemMessage` and sets the role to "system" for providing system instructions to LiteLLM models Close #3657 Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 835388738
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 : )