Files
nisse/nisse-dev/src/nisse_dev/loop/reader.py
T
dongarandClaude Opus 5.5 6ae2375194
CI / checks (push) Skipped
CI / checks (pull_request) Successful in 2m16s
CI / e2e (pull_request) Successful in 10m51s
M2.8: switch over to the new loop
nisse-dev now runs only the conversational loop. The gated state machine
it was built alongside is gone:

- Removed control.py, planner.py, executor.py, approvals.py, gates.py
  (command_form moves to loop/reader.py), publish.py and poller.py, the
  old assembly in agent.py (its shared helpers move to loop/build.py),
  the store's state-machine view (get_state, transition), their tests,
  the old end-to-end and live planning/milestone/gate tests, and
  specs/orchestrator.qnt with its scenarios.
- Roles are driver, helper, expert and classifier; driver is required.
  loop:, roles.planner, roles.executor and tuning.executor are refused
  with what to use instead; tuning.driver takes the turn cap and failure
  limit.
- The benchmark and the capability matrix measure the driver: the
  loop's own system prompt and tools, the task's plan as the agreed
  restatement. Task plans end with finish_milestone, so earlier runs
  show as (old); stored runs' executor tuning reads as the driver's.
- A delegation on the loop records what its helper's alias resolved to
  (L9), as the old path's did.
- The dump shows a work item's revision and what it waits for.
- Behaviour the old tests covered and the loop shares stays covered:
  driver runs that fail on a model call, stop mid-turn, reset the
  failure count; go-aheads ignoring case and punctuation; a request too
  big to fit is never sent; the assembly tests, now on build_loop_agent.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPQ14L3LikyefCMFBqEbKE
2026-10-08 03:12:58 +00:00

92 lines
3.2 KiB
Python

"""Reading a plain-language reply as a go-ahead (L5, D1).
"Yep, that's it" in reply to a restatement may be taken as `go`, because a
wrong reading costs only time. One short model call decides, and it decides
conservatively: only a clear yes counts. A question is never a go-ahead and
never reaches the model (L5: questions never change state).
The driver's model reads for now; the classifier role takes over in M2.6.
"""
from typing import Any
from nisse_dev.canonical import StoredEvent, ToolCall, UserMessage
from nisse_dev.llm import LLMClient, LLMError
def command_form(text: str) -> str:
"""How a message reads as a command: case, surrounding whitespace, runs
of inner whitespace and trailing '.' or '!' do not matter, so a phone's
"Go." is still a go-ahead (#64). Only for matching; what the operator
wrote is what gets recorded and passed on."""
return " ".join(text.strip().rstrip(".!").split()).lower()
VERDICT = {
"type": "function",
"function": {
"name": "verdict",
"description": "Your reading of the operator's reply.",
"parameters": {
"type": "object",
"properties": {
"answer": {
"type": "string",
"enum": ["yes", "no", "unclear"],
"description": "yes: a clear go-ahead on the proposal as it "
"stands. no: it asks for changes, disagrees or says to wait. "
"unclear: anything else.",
}
},
"required": ["answer"],
},
},
}
SYSTEM = """You read one reply from an operator to a software agent. The agent
put a proposal up for agreement; decide whether the reply clearly agrees to the
proposal as it stands, so the agent may start. A reply that asks for any
change, asks a question, adds a condition, or is about something else is not a
go-ahead. When in doubt, it is not. Answer with the verdict tool."""
def is_question(text: str) -> bool:
return text.rstrip().endswith("?")
class GoAheadReader:
def __init__(self, client: LLMClient, model: str) -> None:
self._client = client
self._model = model
def agrees(self, proposal: str, reply: str, model: str = "") -> bool:
"""``model``: the work item's pinned classifier (L9)."""
if is_question(reply):
return False
prompt = f"The proposal:\n\n{proposal}\n\nThe operator's reply:\n\n{reply}"
try:
produced = self._client.complete(
[
StoredEvent(
id=0,
ts="",
event=UserMessage(text=prompt, source="go-ahead reader"),
actor="orchestrator",
)
],
tools=[VERDICT],
model=model or self._model,
system=SYSTEM,
)
except LLMError:
return False # unread: the driver reads it as an answer instead
return any(_yes(event) for event in produced)
def _yes(event: Any) -> bool:
return (
isinstance(event, ToolCall)
and event.tool == "verdict"
and event.arguments.get("answer") == "yes"
)