Skip to content

Refactor: Improve logic and error handling in KAGIterativePipeline - #546

Merged
xionghuaidong merged 1 commit into
OpenSPG:0.8.0_devfrom
thesteganos:fix/iterative-pipeline-logic
Jun 2, 2025
Merged

Refactor: Improve logic and error handling in KAGIterativePipeline#546
xionghuaidong merged 1 commit into
OpenSPG:0.8.0_devfrom
thesteganos:fix/iterative-pipeline-logic

Conversation

@thesteganos

Copy link
Copy Markdown
Contributor

This commit addresses several issues I identified during a detailed review of kag/solver/pipeline/kag_iterative_pipeline.py:

  1. Correct max_iteration Docstring: The docstring for max_iteration in __init__ now correctly states (default: 5) to match the actual default value in the code.

  2. Improved Context Management: Tasks are now added to the context only after their successful execution. Previously, tasks were added before execution, which could lead to an inaccurate context if an error occurred. The final task is added before breaking the loop.

  3. Clearer Termination on Max Iterations:

    • I introduced a MaxIterationsReachedError custom exception.
    • The pipeline now tracks if it was terminated after the final step.
    • If the max_iteration limit is reached without the final step being called, the pipeline raises MaxIterationsReachedError instead of proceeding to generate a potentially misleading answer.

Design Note (Further Discussion Recommended):
A significant design concern remains regarding how KAGIterativePipeline processes tasks. I've observed that the pipeline currently only processes the first task in each iteration, discarding any others. This might be an underutilization of capabilities or a point of inefficiency. This behavior has not been changed but warrants further discussion and potential future refactoring if the pipeline is intended to handle more complex plans within a single iteration.

This commit addresses several issues I identified during a detailed review of `kag/solver/pipeline/kag_iterative_pipeline.py`:

1.  **Correct `max_iteration` Docstring:** The docstring for `max_iteration` in `__init__` now correctly states `(default: 5)` to match the actual default value in the code.

2.  **Improved Context Management:** Tasks are now added to the `context` only *after* their successful execution. Previously, tasks were added before execution, which could lead to an inaccurate context if an error occurred. The final task is added before breaking the loop.

3.  **Clearer Termination on Max Iterations:**
    *   I introduced a `MaxIterationsReachedError` custom exception.
    *   The pipeline now tracks if it was terminated after the final step.
    *   If the `max_iteration` limit is reached without the final step being called, the pipeline raises `MaxIterationsReachedError` instead of proceeding to generate a potentially misleading answer.

**Design Note (Further Discussion Recommended):**
A significant design concern remains regarding how `KAGIterativePipeline` processes tasks. I've observed that the pipeline currently only processes the first task in each iteration, discarding any others. This might be an underutilization of capabilities or a point of inefficiency. This behavior has not been changed but warrants further discussion and potential future refactoring if the pipeline is intended to handle more complex plans within a single iteration.

@royzhao royzhao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@caszkgui
caszkgui changed the base branch from master to 0.8.0_dev June 2, 2025 00:55

@caszkgui caszkgui left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@xionghuaidong
xionghuaidong merged commit 6b10e0b into OpenSPG:0.8.0_dev Jun 2, 2025
xionghuaidong pushed a commit that referenced this pull request Jun 26, 2025
)

This commit addresses several issues I identified during a detailed review of `kag/solver/pipeline/kag_iterative_pipeline.py`:

1.  **Correct `max_iteration` Docstring:** The docstring for `max_iteration` in `__init__` now correctly states `(default: 5)` to match the actual default value in the code.

2.  **Improved Context Management:** Tasks are now added to the `context` only *after* their successful execution. Previously, tasks were added before execution, which could lead to an inaccurate context if an error occurred. The final task is added before breaking the loop.

3.  **Clearer Termination on Max Iterations:**
    *   I introduced a `MaxIterationsReachedError` custom exception.
    *   The pipeline now tracks if it was terminated after the final step.
    *   If the `max_iteration` limit is reached without the final step being called, the pipeline raises `MaxIterationsReachedError` instead of proceeding to generate a potentially misleading answer.

**Design Note (Further Discussion Recommended):**
A significant design concern remains regarding how `KAGIterativePipeline` processes tasks. I've observed that the pipeline currently only processes the first task in each iteration, discarding any others. This might be an underutilization of capabilities or a point of inefficiency. This behavior has not been changed but warrants further discussion and potential future refactoring if the pipeline is intended to handle more complex plans within a single iteration.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
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.

4 participants