Replaces the stub Planner's fixed describe_screen/[] behavior with a real decision-maker: AIPlanner uses native tool/function calling (Anthropic or OpenAI, pluggable via AI_PLANNER_PROVIDER) to select exactly one grounded action per turn, with an explicit finish_task(success, reason) tool for completion/failure instead of an ambiguous "no tool call" signal. Default disabled (AI_PLANNER_ENABLED=false) and additive; TaskRunner falls back to the existing stub Planner unchanged when disabled. Amends CONSTITUTION.md's Perception Boundary with one narrow exception: only the AI Planner may receive the current step's raw screenshot bytes alongside Scene, for vision-grounded coordinate grounding. Also fixes a latent gap in TaskRunner.run(): observe/plan exceptions are now caught per iteration and turned into a failed task with a failure_reason, instead of propagating uncaught. openspec change: ai-planner-runtime. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
45 lines
1.1 KiB
Python
45 lines
1.1 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
|
|
|
|
|
|
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
|
|
)
|