build(agent): new-agents-4#58ba63 iteration
This commit is contained in:
parent
4a31a63dac
commit
2460a221ed
|
|
@ -0,0 +1,69 @@
|
|||
"""Demo: Cross-Domain NovaPlan Interop (Rover <-> Habitat).
|
||||
|
||||
This tiny script demonstrates a minimal end-to-end flow across two domain adapters
|
||||
using the existing bridge primitives. It serves as a quick sanity-check for the
|
||||
interoperability story and is safe to run in unit-test contexts.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
|
||||
from nova_plan.planner import LocalProblem
|
||||
from nova_plan.contracts import PlanDelta
|
||||
from nova_plan.catopt_bridge import to_object, delta_to_morphism
|
||||
from nova_plan.energi_bridge import EnergiBridge
|
||||
from nova_plan.adapters.rover_adapter import RoverAdapter
|
||||
from nova_plan.adapters.habitat_adapter import HabitatAdapter
|
||||
|
||||
|
||||
def run_demo() -> None:
|
||||
# Create a tiny local rover problem
|
||||
def rover_objective(local_vars, shared):
|
||||
# simple quadratic in speed toward a desired velocity in shared space
|
||||
v = local_vars.get("speed", 0.0)
|
||||
w = shared.get("speed", 0.0)
|
||||
return (v - w) ** 2
|
||||
|
||||
lp = LocalProblem(
|
||||
id="rover-1",
|
||||
objective=rover_objective,
|
||||
variables={"speed": 1.0},
|
||||
constraints=None,
|
||||
)
|
||||
|
||||
# Canonical object for interoperability
|
||||
canonical_obj = to_object(lp)
|
||||
|
||||
# Create a PlanDelta from this local problem
|
||||
delta = PlanDelta(agent_id=lp.id, delta={"speed": lp.variables["speed"]}, timestamp=time.time(), contract_id="rover-1")
|
||||
morph = delta_to_morphism(delta, contract_id="rover-1")
|
||||
|
||||
# Initialize adapters (toy stubs)
|
||||
rover = RoverAdapter("rover-1")
|
||||
habitat = HabitatAdapter("hab-ctrl-01")
|
||||
|
||||
# Rover consumes the morphism-like delta (as a planning task)
|
||||
rover_status = rover.get_status()
|
||||
rover_ack = rover.plan_task({"morphism": morph})
|
||||
|
||||
# Habitat module consumes a related task derived from the delta
|
||||
habitat_status = habitat.get_status()
|
||||
habitat_ack = habitat.plan_task({"task_from_delta": morph.data})
|
||||
|
||||
# Simple printout for inspection
|
||||
print("Canonical Object:", canonical_obj)
|
||||
print("Canonical Morphism:", morph)
|
||||
print("Rover status:", rover_status)
|
||||
print("Rover ack:", rover_ack)
|
||||
print("Habitat status:", habitat_status)
|
||||
print("Habitat ack:", habitat_ack)
|
||||
|
||||
# Demonstrate EnergiBridge contract publishing (signed CaC artifact)
|
||||
eb = EnergiBridge()
|
||||
signed_contract = eb.register_contract("demo-cross-domain-contract", {"type": "DemoCrossDomain"}, key="demo-key-123")
|
||||
print("SignedCaCContract:", signed_contract)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_demo()
|
||||
Loading…
Reference in New Issue