Skip to content

fix(solver): Enhance robustness and clarity in kg-solver components - #548

Merged
xionghuaidong merged 1 commit into
OpenSPG:0.8.0_devfrom
thesteganos:fix-solver-robustness
Jun 2, 2025
Merged

fix(solver): Enhance robustness and clarity in kg-solver components#548
xionghuaidong merged 1 commit into
OpenSPG:0.8.0_devfrom
thesteganos:fix-solver-robustness

Conversation

@thesteganos

Copy link
Copy Markdown
Contributor

This commit addresses several issues identified during a code analysis, focusing on improving the robustness, error handling, and clarity of various components within the KAG solver.

The following changes have been made:

  1. KAGIterativePlanner:

    • Corrected is_static() method to return False, aligning with its iterative behavior.
  2. KAGRetrievedResponse:

    • Removed a misleading note about an f-string formatting error from the to_string() method's docstring, as the error was not present in the code.
  3. KAGStaticPlanner:

    • Improved finish_judger error handling: If the LLM call to judge the answer fails, it now logs a warning and returns False (treating the answer as potentially bad) instead of defaulting to True.
  4. ChunkRetrievedExecutor:

    • Clarified schema name: Changed the name field in its schema dictionary from "Retriever" to "ChunkRetriever" to better differentiate it from other retriever executors like KagHybridExecutor.
  5. PyBasedMathExecutor:

    • Added a configurable timeout (defaulting to 5 seconds) to the subprocess.run() call within the run_py_code function. This prevents indefinite hangs from long-running or stuck Python scripts generated by the LLM. Includes handling for subprocess.TimeoutExpired.
  6. DefaultStaticPlanningPrompt:

    • Enhanced parse_response method: Implemented more robust JSON decoding and structural validation for the LLM-generated DAG plan. It now raises more descriptive ValueError exceptions, including details of the malformed data, when KeyError or TypeError occurs during task creation from the DAG, aiding in debugging.

This commit addresses several issues identified during a code analysis, focusing on improving the robustness, error handling, and clarity of various components within the KAG solver.

The following changes have been made:

1.  **KAGIterativePlanner**:
    *   Corrected `is_static()` method to return `False`, aligning with its iterative behavior.

2.  **KAGRetrievedResponse**:
    *   Removed a misleading note about an f-string formatting error from the `to_string()` method's docstring, as the error was not present in the code.

3.  **KAGStaticPlanner**:
    *   Improved `finish_judger` error handling: If the LLM call to judge the answer fails, it now logs a warning and returns `False` (treating the answer as potentially bad) instead of defaulting to `True`.

4.  **ChunkRetrievedExecutor**:
    *   Clarified schema name: Changed the `name` field in its schema dictionary from "Retriever" to "ChunkRetriever" to better differentiate it from other retriever executors like `KagHybridExecutor`.

5.  **PyBasedMathExecutor**:
    *   Added a configurable timeout (defaulting to 5 seconds) to the `subprocess.run()` call within the `run_py_code` function. This prevents indefinite hangs from long-running or stuck Python scripts generated by the LLM. Includes handling for `subprocess.TimeoutExpired`.

6.  **DefaultStaticPlanningPrompt**:
    *   Enhanced `parse_response` method: Implemented more robust JSON decoding and structural validation for the LLM-generated DAG plan. It now raises more descriptive `ValueError` exceptions, including details of the malformed data, when `KeyError` or `TypeError` occurs during task creation from the DAG, aiding in debugging.
@caszkgui
caszkgui changed the base branch from master to 0.8.0_dev June 2, 2025 00:53

@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 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 changed the title Fix: Enhance robustness and clarity in kg-solver components Fix(solver): Enhance robustness and clarity in kg-solver components Jun 2, 2025
@xionghuaidong xionghuaidong changed the title Fix(solver): Enhance robustness and clarity in kg-solver components fix(solver): Enhance robustness and clarity in kg-solver components Jun 2, 2025
@xionghuaidong
xionghuaidong merged commit 1b8cb6e 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 identified during a code analysis, focusing on improving the robustness, error handling, and clarity of various components within the KAG solver.

The following changes have been made:

1.  **KAGIterativePlanner**:
    *   Corrected `is_static()` method to return `False`, aligning with its iterative behavior.

2.  **KAGRetrievedResponse**:
    *   Removed a misleading note about an f-string formatting error from the `to_string()` method's docstring, as the error was not present in the code.

3.  **KAGStaticPlanner**:
    *   Improved `finish_judger` error handling: If the LLM call to judge the answer fails, it now logs a warning and returns `False` (treating the answer as potentially bad) instead of defaulting to `True`.

4.  **ChunkRetrievedExecutor**:
    *   Clarified schema name: Changed the `name` field in its schema dictionary from "Retriever" to "ChunkRetriever" to better differentiate it from other retriever executors like `KagHybridExecutor`.

5.  **PyBasedMathExecutor**:
    *   Added a configurable timeout (defaulting to 5 seconds) to the `subprocess.run()` call within the `run_py_code` function. This prevents indefinite hangs from long-running or stuck Python scripts generated by the LLM. Includes handling for `subprocess.TimeoutExpired`.

6.  **DefaultStaticPlanningPrompt**:
    *   Enhanced `parse_response` method: Implemented more robust JSON decoding and structural validation for the LLM-generated DAG plan. It now raises more descriptive `ValueError` exceptions, including details of the malformed data, when `KeyError` or `TypeError` occurs during task creation from the DAG, aiding in debugging.

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.

3 participants