wren node: Train in the panel, as a run of wren's training flow

POST/GET /flows/{name}/nodes/{id}/train submit wren_train on the node's
targets, examples and tests and read its latest run (run.for_node,
cause "train"); "Use this model" writes `model` into the draft.
This commit is contained in:
2026-10-25 01:18:54 +02:00
parent 07fa5a2dc2
commit e9941b770d
11 changed files with 671 additions and 3 deletions
+29
View File
@@ -46,6 +46,13 @@ def _wren() -> Any:
return wren
def pack_meta(path: Any) -> dict[str, Any]:
"""What a model records of its training: its targets, threshold and,
when it had tests, ``test_exact_match``."""
found: dict[str, Any] = _wren().load_pack(path)["meta"]
return found
#: The input the command arrives on, and the only one that wakes the node.
PROMPT = "prompt"
#: The output the calls are reported on, and the two that say what came of
@@ -55,6 +62,8 @@ REPLY = "reply"
UNHANDLED = "unhandled"
#: The reply when nothing was done and nothing reads ``unhandled``.
CANT = "Sorry, I can't do that yet."
#: wren's training flow, which wren registers: ``fluksio sync wren.flow``.
TRAIN_FLOW = "wren_train"
_TARGET_TYPES = {DType.BOOL, DType.INT, DType.FLOAT, DType.STR}
@@ -260,6 +269,17 @@ class WrenNode(Node):
description="Your own words, and words heard wrong, in the model's: "
'{"traverse": "living room light", "page too": "patio"}.',
)
examples: list[dict[str, Any]] = Field(
default_factory=list,
description="Training only: commands to learn, targets named by port, "
'as {"state": {"user_location": "kitchen"}, "command": "lights on", '
'"calls": [["kitchen_light", true]]}.',
)
tests: list[dict[str, Any]] = Field(
default_factory=list,
description="Training only: commands a new model is scored on, like "
'examples. "calls": [] is one it must pass on.',
)
__slots__ = ("cfg", "targets", "pack", "untrained")
@@ -339,6 +359,15 @@ class WrenNode(Node):
name=name or "wren",
)
def installation(self) -> dict[str, Any]:
"""What wren's training flow learns from: the targets, each with a
value, and the ``examples`` and ``tests``."""
return {
"targets": [t | {"value": _unset(t)} for t in self.targets.values()],
"examples": self.cfg.examples,
"tests": self.cfg.tests,
}
async def start(self, app: FastAPI | None = None) -> None:
store = getattr(app.state, "artifact_store", None) if app else None
self.pack = self._load(store)
+3
View File
@@ -951,6 +951,7 @@ class RunService:
idempotency_key: str | None = None,
parent_id: str | None = None,
passed: list[str] | None = None,
for_node: str | None = None,
) -> Run:
"""Journal a run and wake an engine up for it. Never blocks on it.
@@ -993,6 +994,7 @@ class RunService:
actor=actor,
idempotency_key=idempotency_key,
parent_id=parent_id,
for_node=for_node,
)
with Session(db_engine) as session:
session.add(run)
@@ -1249,6 +1251,7 @@ class RunService:
# What its parent's caller chose. A parent from before that was
# recorded falls back to the names its params carry.
passed=source.passed,
for_node=source.for_node,
)
def _flow_of(self, run_id: str) -> str | None: