Files
agentic-mobile-control/runtime/planner.py
T
q792602257 a5aeb8889c
Tests / Test failed: 2, passed: 849
feat(runtime): add planner reflection history with rationale and thinking
- 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
2026-07-15 12:43:22 +08:00

54 lines
1.6 KiB
Python

from __future__ import annotations
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any
from core.models import Scene
from runtime.context import TaskContext
if TYPE_CHECKING:
from world.models import WorldState
@dataclass(frozen=True)
class PlannedStep:
action: str
description: str
args: dict[str, Any] = field(default_factory=dict)
expected_text: str | None = None
# The actual prompt sent to the LLM for this step (AI planners only).
# ``None`` for non-LLM planners; TaskRunner falls back to the task goal.
prompt: str | None = None
# Pre-tool text block emitted by the model before the tool call.
# None when the model omits a text block or for non-LLM planners.
rationale: str | None = None
# Extended thinking / reasoning content from the model.
# None when not enabled or not present.
thinking: str | None = None
class Planner:
def plan(
self,
*,
goal: str,
scene: Scene,
context: TaskContext,
world: "WorldState | None" = None,
screenshot: bytes | None = None,
) -> list[PlannedStep]:
if context.step_results:
return []
return [
PlannedStep(
action="describe_screen",
description=f"Observe current screen for goal: {goal}",
args={},
)
]
def goal_reached(self, *, goal: str, scene: Scene, context: TaskContext) -> bool:
return bool(context.step_results) and all(
result.success for result in context.step_results
)