47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Toy rover planner adapter.
|
|
|
|
The RoverAdapter demonstrates a minimal adapter that maps a LocalProblem
|
|
from a rover domain into a canonical representation and can propose a
|
|
PlanDelta. It purposely avoids heavy dependencies and is deterministic
|
|
for testability.
|
|
"""
|
|
from dataclasses import dataclass
|
|
from typing import Dict, Any
|
|
|
|
from ..core import LocalProblem, PlanDelta
|
|
|
|
|
|
@dataclass
|
|
class RoverAdapter:
|
|
name: str = "rover_planner"
|
|
|
|
def to_canonical(self, lp: LocalProblem) -> Dict[str, Any]:
|
|
"""Map a rover LocalProblem to a tiny canonical schema.
|
|
|
|
The canonical mapping includes an adapter tag, core identifiers, and
|
|
a simple summary of assets and objective to be used by downstream
|
|
components.
|
|
"""
|
|
return {
|
|
"adapter": self.name,
|
|
"id": lp.id,
|
|
"domain": lp.domain,
|
|
"assets_summary": list(lp.assets.keys()),
|
|
"objective": lp.objective,
|
|
}
|
|
|
|
def propose_delta(self, lp: LocalProblem, author: str = "rover") -> PlanDelta:
|
|
"""Produce a deterministic PlanDelta for tests and demos.
|
|
|
|
This toy implementation produces a delta that instructs a rover to
|
|
hold position if a "battery" asset exists and its value is low.
|
|
"""
|
|
delta = {}
|
|
battery = lp.assets.get("battery")
|
|
if isinstance(battery, (int, float)) and battery < 20:
|
|
delta["action"] = "hold_position"
|
|
delta["reason"] = "low_battery"
|
|
else:
|
|
delta["action"] = "proceed"
|
|
return PlanDelta(delta=delta, author=author, contract_id=lp.id)
|