fix: correct include_contents behavior in ADK web (fixes google#3535)#4481
fix: correct include_contents behavior in ADK web (fixes google#3535)#4481dalagadenilesh wants to merge 3 commits intogoogle:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello @dalagadenilesh, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the ADK web's context generation for sub-agents. By refining how events are included in a sub-agent's context, it ensures that when control is transferred, the sub-agent correctly receives the most recent user input, leading to more accurate and relevant responses. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Response from ADK Triaging Agent Hello @dalagadenilesh, thank you for creating this PR! Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). You can visit https://cla.developers.google.com/ to see your current agreements or to sign a new one. In addition, could you please provide a testing plan for this change? This will help reviewers to review your PR more efficiently. Thanks! |
There was a problem hiding this comment.
Code Review
This pull request aims to correct the include_contents behavior for agent transfers by preventing transfer events from being considered the start of a new turn. The approach is to introduce a new helper function, _is_direct_transfer, to identify these events and filter them out.
My review focuses on making the new helper function more robust. The current implementation could miss some transfer events, and I've provided a suggestion to address this.
| def _is_direct_transfer(event : Event) -> bool: | ||
| "Weather the event is direct transfer event" | ||
| return bool( | ||
| event.actions.transfer_to_agent | ||
| or ( | ||
| event.content.parts | ||
| and event.content.parts[0].function_call | ||
| and event.content.parts[0].function_call.name == 'transfer_to_agent' | ||
| ) | ||
| ) |
There was a problem hiding this comment.
This implementation for checking a transfer_to_agent function call is a bit brittle as it only checks the first part of the event content (event.content.parts[0]). If the LLM generates any text before the function call, this check will fail.
A more robust approach would be to check all parts for the specific function call.
I've also corrected a typo in the docstring ("Weather" -> "Whether"), converted it to a standard PEP 257 docstring, and fixed a minor style issue in the type hint.
| def _is_direct_transfer(event : Event) -> bool: | |
| "Weather the event is direct transfer event" | |
| return bool( | |
| event.actions.transfer_to_agent | |
| or ( | |
| event.content.parts | |
| and event.content.parts[0].function_call | |
| and event.content.parts[0].function_call.name == 'transfer_to_agent' | |
| ) | |
| ) | |
| def _is_direct_transfer(event: Event) -> bool: | |
| """Whether the event is a direct transfer event.""" | |
| return bool( | |
| event.actions.transfer_to_agent | |
| or ( | |
| event.content | |
| and event.content.parts | |
| and any( | |
| p.function_call and p.function_call.name == 'transfer_to_agent' | |
| for p in event.content.parts | |
| ) | |
| ) | |
| ) |
|
Response from ADK Triaging Agent Hello @dalagadenilesh, thank you for creating this PR! Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). In addition, could you please provide a testing plan, including unit tests and manual end-to-end tests? This information will help reviewers to review your PR more efficiently. Thanks! |
|
Response from ADK Triaging Agent Hello @dalagadenilesh, thank you for creating this PR! Could you please provide a testing plan for this change? This will help reviewers to understand how you have tested this fix and how they can reproduce the tests. You can find more information about testing requirements in our contribution guidelines. Additionally, it looks like you haven't filled out the checklist in the PR description yet. Please take a moment to do so. Thanks! |
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
include_contentsparameters tononefor LlmAgent, the behavior is not aligned with the declaration in the manual. #35352. Or, if no issue exists, describe the change:
Problem:
The issue is that if a sub-agent is transferred to take over control, the context should include the user input. But the actual context for this sub-agent doesn't contain the latest user input, but the last transfer_to_agent context from the parent agent.
Solution:
Solution is to avoid adding events with either transfer_to_agent exits or name of the agent function call is 'transfer_to_agent'
Testing Plan
N/A
Unit Tests:
Manual End-to-End (E2E) Tests:
N/A
Checklist
Additional context