build(agent): molt-z#db0ec5 iteration
This commit is contained in:
parent
33065e5e15
commit
44cec57aea
|
|
@ -1,3 +1,3 @@
|
||||||
"""NovaPlan MVP package init"""
|
"""NovaPlan MVP package init"""
|
||||||
|
|
||||||
__all__ = ["planner", "contracts", "ledger", "adapters", "catopt_bridge"]
|
__all__ = ["planner", "contracts", "ledger", "adapters", "catopt_bridge", "dsl"]
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,68 @@
|
||||||
"""Minimal NovaPlan DSL scaffold.
|
"""Minimal NovaPlan DSL scaffolding.
|
||||||
|
|
||||||
This is intentionally tiny: a single, ergonomic shim to create a LocalProblem
|
This module provides lightweight dataclasses to model a canonical signal/plan
|
||||||
out of a high-level DSL-like description. It is designed for MVP experimentation
|
DSL that can be used by adapters and bridge components to represent local
|
||||||
and to bootstrap adapters, not for production parsing.
|
problems, signals, and planning hypotheses in a structured way.
|
||||||
|
|
||||||
|
The goal is to enable quick experimentation with interoperable representations
|
||||||
|
without pulling in heavy dependencies or reworking the core MVP logic.
|
||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Dict, Callable
|
import json
|
||||||
|
from dataclasses import dataclass, asdict
|
||||||
from nova_plan.planner import LocalProblem
|
from typing import List, Dict, Any
|
||||||
|
|
||||||
|
|
||||||
class LocalProblemDSL:
|
@dataclass
|
||||||
"""Tiny DSL to describe a LocalProblem and convert to a LocalProblem instance."""
|
class SignalNode:
|
||||||
|
id: str
|
||||||
|
metadata: Dict[str, Any] # arbitrary per-signal metadata (venue, ts, confidence, etc.)
|
||||||
|
|
||||||
def __init__(self, agent_id: str, objective_expr: str, variables: Dict[str, float], constraints: Dict[str, object] | None = None):
|
def to_json(self) -> str:
|
||||||
# Keep the input shape friendly for tests; the actual objective is not
|
return json.dumps(asdict(self))
|
||||||
# exercised in the MVP tests, so we keep a simple stub objective.
|
|
||||||
self.agent_id = agent_id
|
|
||||||
self.objective_expr = objective_expr
|
|
||||||
self.variables = variables
|
|
||||||
self.constraints = constraints or {}
|
|
||||||
|
|
||||||
def to_local_problem(self) -> LocalProblem:
|
|
||||||
"""Return a LocalProblem instance corresponding to this DSL description."""
|
|
||||||
# Minimal stub objective: ignore expression, provide a deterministic function.
|
|
||||||
def _objective(local_vars: Dict[str, float], shared_vars: Dict[str, float]) -> float:
|
|
||||||
return 0.0
|
|
||||||
|
|
||||||
return LocalProblem(id=self.agent_id, objective=_objective, variables=self.variables, constraints=self.constraints)
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["LocalProblemDSL"]
|
@dataclass
|
||||||
|
class Edge:
|
||||||
|
src: str
|
||||||
|
dst: str
|
||||||
|
weight: float = 1.0
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
return json.dumps(asdict(self))
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Scenario:
|
||||||
|
name: str
|
||||||
|
nodes: List[SignalNode]
|
||||||
|
edges: List[Edge]
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
data = {
|
||||||
|
"name": self.name,
|
||||||
|
"nodes": [asdict(n) for n in self.nodes],
|
||||||
|
"edges": [asdict(e) for e in self.edges],
|
||||||
|
}
|
||||||
|
return json.dumps(data)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class HedgePlan:
|
||||||
|
plan_id: str
|
||||||
|
scenario: Scenario
|
||||||
|
metadata: Dict[str, Any] # additional plan-level metadata
|
||||||
|
timestamp: float
|
||||||
|
|
||||||
|
def to_json(self) -> str:
|
||||||
|
data = {
|
||||||
|
"plan_id": self.plan_id,
|
||||||
|
"scenario": json.loads(self.scenario.to_json()),
|
||||||
|
"metadata": self.metadata,
|
||||||
|
"timestamp": self.timestamp,
|
||||||
|
}
|
||||||
|
return json.dumps(data)
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["SignalNode", "Edge", "Scenario", "HedgePlan"]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue