feat(runtime): add planner reflection history with rationale and thinking
Tests / Test failed: 2, passed: 849

- ToolCallDecision captures thinking blocks and pre-tool text output
- AnthropicToolCallingClient supports optional extended thinking (budget_tokens + beta header)
- PlannedStep carries rationale and thinking from each LLM decision
- WorldEvent replaces scene_summary with rationale/thinking/page fields (backward-compatible)
- AI planner system prompt instructs reflection before each tool call
- _history_summary() emits compact {page, rationale, action, success} dicts
- Cloud DB migration 0011 adds nullable rationale/thinking columns to planner_decision_log
- OpenAI client extracts reasoning_content into thinking field
This commit is contained in:
2026-07-15 12:43:22 +08:00
parent 96e403ee47
commit a5aeb8889c
26 changed files with 903 additions and 25 deletions
+4 -1
View File
@@ -135,9 +135,12 @@ class WorldModel:
) -> None:
state.history.append(
WorldEvent(
scene_summary=semantic_scene or scene,
action=str(getattr(step, "action", "unknown")),
success=bool(getattr(result, "success", False)),
scene_summary=semantic_scene or scene,
rationale=getattr(step, "rationale", None),
thinking=getattr(step, "thinking", None),
page=state.current_page,
)
)
+10 -2
View File
@@ -12,16 +12,24 @@ from world.config import DEFAULT_HISTORY_SIZE
@dataclass(frozen=True)
class WorldEvent:
scene_summary: SemanticScene | Scene
action: str
success: bool
# 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
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(),
"scene_summary": self.scene_summary.to_dict() if self.scene_summary is not None else None,
"action": self.action,
"success": self.success,
"rationale": self.rationale,
"thinking": self.thinking,
"page": self.page,
"timestamp": self.timestamp.isoformat(),
}