feat(planner): persist reusable action semantics
Tests / Test passed: 879

This commit is contained in:
2026-07-15 18:14:28 +08:00
parent 361dada276
commit d69be48f96
41 changed files with 733 additions and 116 deletions
+11 -1
View File
@@ -86,7 +86,9 @@ class WorldModel:
def _new_state(self) -> WorldState:
return WorldState.with_history_bound(self.config.history_size)
def _update_page(self, state: WorldState, semantic_scene: SemanticScene | None) -> None:
def _update_page(
self, state: WorldState, semantic_scene: SemanticScene | None
) -> None:
if semantic_scene is None:
return
page = semantic_scene.page.strip()
@@ -137,14 +139,22 @@ class WorldModel:
WorldEvent(
action=str(getattr(step, "action", "unknown")),
success=bool(getattr(result, "success", False)),
arguments=_step_arguments(step),
scene_summary=semantic_scene or scene,
rationale=getattr(step, "rationale", None),
thinking=getattr(step, "thinking", None),
purpose=getattr(step, "purpose", None),
expected_outcome=getattr(step, "expected_outcome", None),
page=state.current_page,
)
)
def _step_arguments(step: "PlannedStep") -> dict[str, Any]:
raw_arguments = getattr(step, "args", {})
return dict(raw_arguments) if isinstance(raw_arguments, dict) else {}
class TaskWorldView:
"""Per-task handle into a `WorldModel`, scoped explicitly by `task_id`.
+9 -1
View File
@@ -14,21 +14,29 @@ from world.config import DEFAULT_HISTORY_SIZE
class WorldEvent:
action: str
success: bool
arguments: dict[str, Any] = field(default_factory=dict)
# Optional for backward compatibility; new entries created by AIPlanner
# paths leave this as None and use rationale/thinking instead.
scene_summary: SemanticScene | Scene | None = None
rationale: str | None = None
thinking: str | None = None
purpose: str | None = None
expected_outcome: str | None = None
page: str | None = None
timestamp: datetime = field(default_factory=utc_now)
def to_dict(self) -> dict[str, Any]:
return {
"scene_summary": self.scene_summary.to_dict() if self.scene_summary is not None else None,
"scene_summary": self.scene_summary.to_dict()
if self.scene_summary is not None
else None,
"action": self.action,
"arguments": dict(self.arguments),
"success": self.success,
"rationale": self.rationale,
"thinking": self.thinking,
"purpose": self.purpose,
"expected_outcome": self.expected_outcome,
"page": self.page,
"timestamp": self.timestamp.isoformat(),
}