KAG icon indicating copy to clipboard operation
KAG copied to clipboard

Refactor: Improve logic and error handling in KAGIterativePipeline

Open thesteganos opened this issue 7 months ago • 0 comments

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.

thesteganos avatar May 21 '25 06:05 thesteganos