Skip to content

Conversation

devin2255
Copy link

No description provided.

Copy link

@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 @devin2255, 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 introduces a new PlanReflectionPlanner aimed at improving the robustness and accuracy of agent responses. By explicitly integrating reflection and replanning phases into the existing ReAct framework, the agent can now dynamically evaluate its progress, identify issues, and adjust its strategy, leading to more refined and insightful outcomes.

Highlights

  • New Planner Introduction: Introduced a new PlanReflectionPlanner designed to enhance the agent's reasoning by incorporating explicit reflection and replanning steps into the ReAct cycle.
  • Enhanced Planning Process: The new planner defines a structured, multi-phase process including Initial Planning, Execution, Reflection, Replanning, Iterative Execution, and Final Answer, with specific tags for each phase.
  • Module Export: The PlanReflectionPlanner has been added to the __all__ list in src/google/adk/planners/__init__.py to make it discoverable and usable within the planners module.
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.

@adk-bot
Copy link
Collaborator

adk-bot commented Sep 4, 2025

Response from ADK Triaging Agent

Hello @devin2255, thank you for creating this PR!

To help reviewers evaluate your contribution, could you please address the following points from our contribution guidelines?

  • Associated Issue: This PR introduces a new feature. Could you please create an issue that describes this feature and associate it with this PR?
  • Testing Plan: Please add a "Testing Plan" section to your PR description explaining how you've tested these changes.
  • Demonstration: Since this is a new feature, could you please provide logs or screenshots to demonstrate how it works?

You can find more details in our contribution guidelines. This information will help reviewers to review your PR more efficiently. Thanks!

Copy link

@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 introduces a PlanReflectionPlanner to enforce a reflection step in the ReAct cycle. The implementation is mostly solid, but I've found a critical bug in the response processing logic that could lead to dropped function calls. I've also included several suggestions to improve code consistency, readability, and adherence to Python best practices, such as using consistent comment language, optimizing tag checking, and cleaning up string formatting. Please review the detailed comments.


self._handle_non_function_call_parts(response_parts[i], preserved_parts)

if first_fc_part_index > 0:

Choose a reason for hiding this comment

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

critical

There's a logic error in how function call parts are processed. If the first part in response_parts is a function call, first_fc_part_index will be 0, and the condition if first_fc_part_index > 0: will be false. This causes the subsequent loop that processes consecutive function calls to be skipped, potentially leading to dropped function calls from the response.

Suggested change
if first_fc_part_index > 0:
if first_fc_part_index != -1:

from ..models.llm_request import LlmRequest
from .base_planner import BasePlanner

# 使用与 PlanReActPlanner 兼容的标签

Choose a reason for hiding this comment

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

medium

This comment is in Chinese. For consistency with the rest of the codebase, which is primarily in English, please translate it.

Suggested change
# 使用与 PlanReActPlanner 兼容的标签
# Use tags compatible with PlanReActPlanner

Comment on lines 72 to 74
def _handle_non_function_call_parts(
self, response_part: types.Part, preserved_parts: list[types.Part]
):

Choose a reason for hiding this comment

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

medium

The type hint list[types.Part] is used here, but other parts of the file (e.g., line 36) use List[types.Part] from the typing module. For consistency and compatibility with Python versions before 3.9, it's better to use List from typing.

Suggested change
def _handle_non_function_call_parts(
self, response_part: types.Part, preserved_parts: list[types.Part]
):
def _handle_non_function_call_parts(
self, response_part: types.Part, preserved_parts: List[types.Part]
):

preserved_parts.append(types.Part(text=final_answer_text))
else:
response_text = response_part.text or ''
# 包含所有标签,包括 REFLECTION_TAG

Choose a reason for hiding this comment

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

medium

This comment is in Chinese. For consistency with the rest of the codebase, which is in English, please translate it.

Suggested change
# 包含所有标签,包括 REFLECTION_TAG
# Contains all tags, including REFLECTION_TAG

Comment on lines +89 to +100
if response_text and (
any(
response_text.startswith(tag)
for tag in [
PLANNING_TAG,
REASONING_TAG,
ACTION_TAG,
REFLECTION_TAG,
REPLANNING_TAG,
]
)
):

Choose a reason for hiding this comment

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

medium

The current implementation for checking if response_text starts with a specific tag creates a new list of tags and uses any() with a generator expression on every call. This can be made more efficient and readable. The startswith() string method can accept a tuple of prefixes, which is more performant than iterating with any(). Consider defining the tags as a constant tuple at the class or module level for further optimization.

            if response_text and response_text.startswith((
                PLANNING_TAG,
                REASONING_TAG,
                ACTION_TAG,
                REFLECTION_TAG,
                REPLANNING_TAG,
            )):

"""Marks the response part as thought."""
if response_part.text:
response_part.thought = True
return

Choose a reason for hiding this comment

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

medium

This return statement is redundant in a function that does not return a value. It can be safely removed to make the code cleaner.

def _build_reflection_planner_instruction(self) -> str:
"""Builds the reflection planner instruction with stronger enforcement."""

high_level_preamble = f"""

Choose a reason for hiding this comment

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

medium

The multiline strings for the prompts (like high_level_preamble, planning_preamble, etc.) contain significant leading whitespace in the source code, which can affect readability. Consider using textwrap.dedent to remove common leading whitespace from every line in these strings. This will allow you to indent the string content in your code to match the surrounding code, improving readability, without the indentation appearing in the final string.

Example:

import textwrap

my_string = textwrap.dedent("""
    This is an example.
    The leading whitespace will be removed.
""")


planning_preamble = f"""
{PLANNING_TAG} Requirements:
Create a numbered plan that breaks down the user query into actionable steps. Each step should specify which tools to use.

Choose a reason for hiding this comment

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

medium

There is trailing whitespace at the end of this line. It should be removed for code cleanliness.

Create a numbered plan that breaks down the user query into actionable steps. Each step should specify which tools to use.


replanning_preamble = f"""
{REPLANNING_TAG} Requirements (conditional):
Only if reflection reveals issues, create a revised plan and execute it with new {ACTION_TAG} and {REASONING_TAG} sections.

Choose a reason for hiding this comment

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

medium

There is trailing whitespace at the end of this line. It should be removed for code cleanliness.

Only if reflection reveals issues, create a revised plan and execute it with new {ACTION_TAG} and {REASONING_TAG} sections.

1. Code comments are in English
2. Remove extra spaces
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.

2 participants