Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions openhands_cli/tui/utils/critic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from openhands_cli.tui.utils.critic.feedback import send_critic_inference_event
from openhands_cli.tui.utils.critic.refinement import (
CriticFeature,
build_refinement_message,
get_high_probability_issues,
should_trigger_refinement,
Expand All @@ -10,6 +11,7 @@


__all__ = [
"CriticFeature",
"build_refinement_message",
"create_critic_collapsible",
"get_high_probability_issues",
Expand Down
22 changes: 15 additions & 7 deletions openhands_cli/tui/utils/critic/refinement.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, TypedDict


if TYPE_CHECKING:
from openhands.sdk.critic.result import CriticResult


def _format_feature_for_prompt(feature: dict[str, Any]) -> str:
class CriticFeature(TypedDict, total=False):
"""TypedDict for critic feature structure from metadata."""

name: str
display_name: str
probability: float


def _format_feature_for_prompt(feature: CriticFeature) -> str:
"""Format a single feature for display in the refinement prompt.

Args:
Expand All @@ -36,7 +44,7 @@ def _format_feature_for_prompt(feature: dict[str, Any]) -> str:
def get_high_probability_issues(
critic_result: CriticResult,
issue_threshold: float,
) -> list[dict[str, Any]]:
) -> list[CriticFeature]:
"""Extract issues with probability above the threshold.

Looks for agent behavioral issues and other detected issues from the
Expand All @@ -47,7 +55,7 @@ def get_high_probability_issues(
issue_threshold: Minimum probability to consider an issue significant

Returns:
List of issue dicts with 'name', 'display_name', and 'probability'
List of CriticFeature dicts with 'name', 'display_name', and 'probability'
"""
if not critic_result.metadata:
return []
Expand All @@ -56,7 +64,7 @@ def get_high_probability_issues(
if not categorized:
return []

high_prob_issues: list[dict[str, Any]] = []
high_prob_issues: list[CriticFeature] = []

# Check agent behavioral issues (e.g., insufficient_testing, loop_behavior)
for issue in categorized.get("agent_behavioral_issues", []):
Expand All @@ -75,7 +83,7 @@ def build_refinement_message(
max_iterations: int = 3,
*,
issue_threshold: float = 0.75,
triggered_issues: list[dict[str, Any]] | None = None,
triggered_issues: list[CriticFeature] | None = None,
) -> str:
"""Build a follow-up message to send to the agent when refinement is needed.

Expand Down Expand Up @@ -132,7 +140,7 @@ def should_trigger_refinement(
threshold: float,
*,
issue_threshold: float = 0.75,
) -> tuple[bool, list[dict[str, Any]]]:
) -> tuple[bool, list[CriticFeature]]:
"""Check if iterative refinement should be triggered.

Refinement is triggered when:
Expand Down