Skip to content

fix: correct include_contents behavior in ADK web (fixes google#3535)#4481

Open
dalagadenilesh wants to merge 3 commits intogoogle:mainfrom
dalagadenilesh:fix/inlcude_context_none
Open

fix: correct include_contents behavior in ADK web (fixes google#3535)#4481
dalagadenilesh wants to merge 3 commits intogoogle:mainfrom
dalagadenilesh:fix/inlcude_context_none

Conversation

@dalagadenilesh
Copy link

@dalagadenilesh dalagadenilesh commented Feb 13, 2026

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):

2. 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:

  • All unit tests pass locally.

Manual End-to-End (E2E) Tests:
N/A

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

@google-cla
Copy link

google-cla bot commented Feb 13, 2026

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Context Correction for Sub-Agents: Resolved an issue where sub-agents, after a transfer of control, were not receiving the latest user input in their context, instead retaining the last transfer_to_agent context from the parent agent.
  • Event Filtering Logic: Implemented new logic to prevent events related to 'transfer_to_agent' (either via event actions or a function call) from being included when determining the current turn's contents, ensuring accurate context for sub-agents.

🧠 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
  • src/google/adk/flows/llm_flows/contents.py
    • Added a new private helper function _is_direct_transfer to identify events related to agent transfers.
    • Modified the _get_current_turn_contents function to exclude events identified as direct transfers when constructing the current turn's context.
Activity
  • No review comments or activities have been recorded yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Feb 13, 2026
@adk-bot
Copy link
Collaborator

adk-bot commented Feb 13, 2026

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!

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 575 to 584
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'
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Suggested change
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
)
)
)

@adk-bot
Copy link
Collaborator

adk-bot commented Feb 13, 2026

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!

@adk-bot
Copy link
Collaborator

adk-bot commented Feb 13, 2026

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants