Skip to content

Conversation

JinXingJX
Copy link

Only allow transfer to parent agent when both conditions are met:

  • Parent agent exists (agent.parentAgent() != null)
  • Transfer to parent is allowed (!agent.disallowTransferToParent())

This prevents unwanted transfers to parent agents when explicitly disabled. Aligns Java implementation with Python version for consistency.

Only allow transfer to parent agent when both conditions are met:
- Parent agent exists (agent.parentAgent() != null)
- Transfer to parent is allowed (!agent.disallowTransferToParent())

This prevents unwanted transfers to parent agents when explicitly disabled.
Aligns Java implementation with Python version for consistency.
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.

Summary of Changes

Hello @JinXingJX, 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 refines the agent transfer mechanism by introducing a new condition that prevents an agent from transferring to its parent if such a transfer is explicitly disallowed. This change ensures that transfers only occur when both a parent agent exists and the transfer is permitted, enhancing consistency and control over agent interactions.

Highlights

  • Agent Transfer Logic Update: The condition for allowing an agent to transfer to its parent has been updated to include a check for !agent.disallowTransferToParent(). This prevents transfers to parent agents when they are explicitly disabled, aligning the Java implementation with its Python counterpart.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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.

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 adds a check for disallowTransferToParent when constructing the LLM prompt, ensuring that instructions to transfer to a parent agent are only provided when it's allowed. This change correctly aligns the prompt generation logic with the agent transfer target selection logic, preventing potentially confusing instructions for the LLM. I have added one comment pointing out a related, pre-existing issue in the prompt text that could be addressed to further improve clarity.

@@ -87,7 +87,7 @@ private String buildTargetAgentsInstructions(LlmAgent agent, List<BaseAgent> tra
"If another agent is better for answering the question according to its description, call"
+ " `transferToAgent` function to transfer the question to that agent. When"
+ " transferring, do not generate any text other than the function call.\n");
if (agent.parentAgent() != null) {
if (agent.parentAgent() != null && !agent.disallowTransferToParent()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The added condition !agent.disallowTransferToParent() is correct and aligns the behavior with getTransferTargets.

On a related note, the instruction generated within this if block (on lines 94-96) seems to contain a contradiction. It says, ...If you don't have parent agent, try answer by yourself, but this code block is only entered if agent.parentAgent() != null. This might confuse the LLM.

Since you are working in this area, you might consider removing the contradictory part of the instruction to improve prompt clarity. For example:

sb.append(
    ".If neither the other agents nor you are best for answering the question according to"
        + " the descriptions, transfer to your parent agent.\n");

@JinXingJX JinXingJX changed the title Add disallowTransferToParent check to parent agent transfer condition fix:Add disallowTransferToParent check to parent agent transfer condition Aug 28, 2025
@JinXingJX JinXingJX force-pushed the fix/agent-transfer-parent-consistency branch 3 times, most recently from 8a507a4 to 32500f4 Compare September 2, 2025 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant