feat: all four evaluation cases pass; intake, checklist review, thresholds

Case 04 (interactive)
- A scripted answer may name who it is for, so facts written for
  requirements discovery are not given to a Specialist confirming a draft.
- A reply that restates what the agreed requirements already say is read
  as an answer, not a request for changes.
- With a user present, a first submission is refused until the user has
  been shown a draft of that Deliverable (CONFIRM_DRAFTS).

Routing and reviews
- Intake: a message that starts something is read first. A question is
  answered and starts nothing; a change to delivered work starts as a new
  request with a note, until Change requests are built.
- Requirements and recommendations list what infrastructure code can show
  (conditions) apart from what it cannot (outside_code); the latter needs
  no Check and validation proposes nothing for it.
- A requirements review, "names no products", behind its own switch (off).
- Each pillar advisor reviews its pillar's checklist; the engine writes the
  reviews into the design recommendations. The judged checklist check went
  from 9-45% a pillar to 100% in one run of case 04.

Evaluation
- Per-case thresholds for Revisions, seconds and tokens, set from every
  completed run on this build.
- A progress file after every agent run, so an interrupted run keeps its
  time and tokens.
- eval/calibrate_judge.py with a 32-question set awaiting a person's
  labels. Unlabelled: Jev stable at 1.00, Gemini 0.92, agreeing on 0.91.

Smaller
- An Execution that ends with warnings writes its Deliverables, with the
  warnings and each status in the manifest.
- CI installs the application's dependencies before linting and testing.
- A load-balancer pattern in the IaC patterns Skill.

Plans record nine runs of 2026-10-08. Iteration 6 is complete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 09:32:57 +01:00
parent d41607f505
commit 654370bb46
53 changed files with 2122 additions and 106 deletions

View File

@@ -105,6 +105,7 @@ def make_execution_nodes(
skill_versions: Mapping[str, str] | None = None,
orchestrator: OrchestratorPolicy | None = None,
submission_review: SubmissionReview | None = None,
confirm_drafts: bool = False,
) -> ExecutionNodes:
tool_factory = tool_factory or _no_tools
# How an Orchestrator turn is decided. The default drives the tools from the
@@ -180,6 +181,7 @@ def make_execution_nodes(
notes = list(state.get("notes", []))
pending_permission = state.get("pending_permission")
warnings = list(state.get("warnings", []))
shown = list(state.get("drafts_shown", []))
drafts = dict(state.get("drafts", {}))
outcomes = state.get("outcomes", [])
@@ -217,6 +219,9 @@ def make_execution_nodes(
"content": record["draft"],
"attachments": record.get("draft_attachments", {}),
}
# The user is being shown this Deliverable.
if kind.value not in shown:
shown.append(kind.value)
questions = record.get("questions") or [
(
f"The {record['role']} stopped: {record['summary']} "
@@ -229,6 +234,7 @@ def make_execution_nodes(
update: dict[str, Any] = {
"deliverables": deliverables,
"drafts": drafts,
"drafts_shown": shown,
"pending_questions": pending_questions,
"pending_permission": pending_permission,
"outcomes_applied": len(outcomes),
@@ -434,6 +440,11 @@ def make_execution_nodes(
working=working,
library=task_input.get("library"),
review=review if submission_review else None,
# With a user present, their first sight of a Deliverable comes
# before it is submitted, whatever the Specialist intends.
confirm_first=confirm_drafts
and not task_input["context"].get("pre_approved", True)
and not task_input.get("shown"),
),
refusals,
role.name,
@@ -559,7 +570,7 @@ def make_execution_nodes(
async def finalize(state: ExecutionState) -> dict[str, Any]:
ledger = Ledger.from_dict(state["ledger"])
_write_outputs(output_root, state)
_write_outputs(output_root, state, "completed", ledger)
close(state, "completed", has_files=True)
await record_progress(state, ledger, "completed")
await record_lessons(state, ledger, "completed")
@@ -567,7 +578,10 @@ def make_execution_nodes(
async def end_with_warnings(state: ExecutionState) -> dict[str, Any]:
ledger = Ledger.from_dict(state["ledger"])
close(state, "completed_with_warnings", has_files=False)
# What was produced is kept, marked as unfinished: a person deciding what to
# do next needs to read it, and it is the evidence of what went wrong.
wrote = _write_outputs(output_root, state, "completed_with_warnings", ledger)
close(state, "completed_with_warnings", has_files=wrote)
await record_progress(state, ledger, "completed_with_warnings")
await record_lessons(state, ledger, "completed_with_warnings")
return {"status": "completed_with_warnings"}
@@ -706,6 +720,9 @@ def _specialist_input(
"attempt": attempt,
"allow_cloud_read": state.get("allow_cloud_read"),
"working": dict(state.get("working", {}).get(kind.value, {})),
# Whether the user has been shown a draft of this Deliverable. Answering some
# other question about it, such as what to do after it stopped, is not that.
"shown": kind.value in state.get("drafts_shown", []),
"context": {
"workflow_request": state["workflow_request"],
"pre_approved": bool(state.get("pre_approved")),
@@ -762,7 +779,14 @@ def automatic_reply(
prompt: Mapping[str, Any], scripted_answers: Sequence[Sequence[str]] = ()
) -> dict[str, Any]:
"""The reply in a pre-approved Execution: approve, deny cloud reads, and answer
questions from scripted (pattern, answer) pairs where one matches."""
questions from scripted answers where one matches.
A scripted answer is (pattern, answer) or (pattern, answer, asker). It answers a
question its pattern matches; with an asker, only when that pattern also matches
who is asking (a Deliverable kind, or the orchestrator). The first that applies
wins. So facts written for requirements discovery are not given to a later
Specialist that only wants its draft confirmed.
"""
if "approval" in prompt:
return {
"approval": {"phase": prompt["approval"]["phase"], "decision": "approve"}
@@ -772,11 +796,13 @@ def automatic_reply(
lines = []
unanswered = False
for item in prompt.get("questions", []):
asker = str(item.get("from", ""))
answer = next(
(
scripted
for pattern, scripted in scripted_answers
if re.search(pattern, item["question"], re.IGNORECASE)
scripted[1]
for scripted in scripted_answers
if re.search(scripted[0], item["question"], re.IGNORECASE)
and (len(scripted) < 3 or re.search(scripted[2], asker, re.IGNORECASE))
),
None,
)
@@ -839,13 +865,21 @@ def _case(state: ExecutionState) -> str:
return state.get("customer_case") or UNASSIGNED_CASE
def _write_outputs(output_root: Path, state: ExecutionState) -> None:
"""Write a finished Execution's files under its Customer case, with a manifest
that ties the request to what was generated for it."""
def _write_outputs(
output_root: Path, state: ExecutionState, status: str, ledger: Ledger
) -> bool:
"""Write an Execution's files under its Customer case, with a manifest that ties
the request to what was generated for it. Returns whether anything was written.
An Execution that ended with warnings is written too. Its manifest carries the
warnings and each Deliverable's status, so nothing unapproved reads as final.
"""
customer_case = _case(state)
execution_id = state["execution_id"]
out_dir = execution_dir(output_root, execution_id, customer_case)
deliverables: Mapping[str, Mapping[str, Any]] = state.get("deliverables", {})
if not deliverables:
return False
files: dict[str, str] = {}
by_kind: dict[str, dict[str, Any]] = {}
guide = deliverables.get(DeliverableKind.SOLUTION_GUIDE.value)
@@ -856,7 +890,12 @@ def _write_outputs(output_root: Path, state: ExecutionState) -> None:
files[document] = deliverable["content"]
attachments = dict(deliverable.get("attachments", {}))
files.update(attachments)
by_kind[kind] = {"document": document, "attachments": sorted(attachments)}
by_kind[kind] = {
"document": document,
"attachments": sorted(attachments),
# submitted, or back in draft after something it depends on was reopened
"status": ledger.status(DeliverableKind(kind)).value,
}
for name, content in files.items():
path = out_dir / name
path.parent.mkdir(parents=True, exist_ok=True)
@@ -868,7 +907,11 @@ def _write_outputs(output_root: Path, state: ExecutionState) -> None:
"session_id": state.get("session_id"),
"intent_version": state.get("intent_version"),
"workflow_request": state["workflow_request"],
"status": "completed",
"status": status,
"warnings": list(state.get("warnings", [])),
"phases": {
phase.value: ledger.phase_status(phase).value for phase in PHASE_ORDER
},
"solution_guide": GUIDE_FILENAME if guide else None,
"deliverables": by_kind,
}
@@ -876,3 +919,4 @@ def _write_outputs(output_root: Path, state: ExecutionState) -> None:
(out_dir / MANIFEST_FILENAME).write_text(
json.dumps(manifest, indent=2, ensure_ascii=False), encoding="utf-8"
)
return True

122
app/nodes/intake.py Normal file
View File

@@ -0,0 +1,122 @@
"""Intake: what a message that starts something is asking for (ADR-0007).
Inside an Execution the router reads the user's replies. This is the same reading
one step earlier, for a message that arrives with no Execution in progress:
new request design this workload start an Execution
change request change what was delivered (ADR-0006; not built yet)
question what can you do, how long... answer; start nothing
Without a decision, and whenever the reading is not confident, the message is taken
as a new request: that is what every message was before, and starting work nobody
asked for is cheaper to put right than refusing work somebody did.
"""
from __future__ import annotations
import logging
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from pathlib import Path
from typing import Any
from app.adk.runtime import Decider, Question
from app.customer_case import IN_PROGRESS, read_history
from app.states.execution_state import UNASSIGNED_CASE
logger = logging.getLogger(__name__)
NEW_REQUEST = "new_request"
CHANGE_REQUEST = "change_request"
QUESTION = "question"
ABOUT = (
"I design cloud solution architectures. Tell me, at a high level, what you want "
"built, and I will work through requirements, a target architecture, "
"infrastructure code, validation and a packaged guide, asking for your approval "
"at each Phase. Nothing was started for this message."
)
CHANGE_NOTE = (
"This reads as a change to work already delivered for this Customer case. "
"Changing an earlier architecture in place is not available yet, so this is "
"being designed as a new request."
)
_MESSAGE_LIMIT = 8_000
_EARLIER_SHOWN = 5
@dataclass(frozen=True)
class IntakeReading:
kind: str # new_request | change_request | question
confidence: float = 0.0
judged: bool = False # False when no decision was available
earlier: int = 0 # finished Executions of the same Customer case
def finished_intents(output_root: Path, customer_case: str) -> list[Mapping[str, Any]]:
"""The case's earlier statements of intent whose Executions delivered something."""
if not customer_case or customer_case == UNASSIGNED_CASE:
return []
return [
item
for item in read_history(output_root, customer_case)["intents"]
if isinstance(item, Mapping)
and str(item.get("status", IN_PROGRESS)).startswith("completed")
]
class Intake:
def __init__(
self,
decider: Decider,
output_root: Path,
*,
act: float = 0.75,
) -> None:
self._decider = decider
self._output_root = output_root
# How sure the reading must be before anything but a new Execution is done.
self._act = act
async def read(
self, message: str, customer_case: str | None = None, scope: str = ""
) -> IntakeReading:
earlier = finished_intents(self._output_root, customer_case or "")
text = message.strip()
if not text:
return IntakeReading(NEW_REQUEST, earlier=len(earlier))
answers = await self._decider.decide(
_state(text, earlier),
{
"intake": Question(
"choice",
"What is the user's message? new_request: they describe "
"something they want designed or built. change_request: they "
"ask to change or extend an architecture already delivered to "
"them. question: they ask about the service or about earlier "
"work, and want an answer, not new work.",
(NEW_REQUEST, CHANGE_REQUEST, QUESTION),
)
},
scope=scope,
)
answer = (answers or {}).get("intake")
if answer is None:
return IntakeReading(NEW_REQUEST, earlier=len(earlier))
kind, confidence = str(answer.value), float(answer.confidence)
if kind != NEW_REQUEST and confidence < self._act:
kind = NEW_REQUEST # not sure enough to do anything but start
if kind == CHANGE_REQUEST and not earlier:
kind = NEW_REQUEST # there is nothing delivered to change
logger.info("[%s] intake: %s (%.2f)", scope, kind, confidence)
return IntakeReading(kind, confidence, judged=True, earlier=len(earlier))
def _state(message: str, earlier: Sequence[Mapping[str, Any]]) -> str:
lines = [f"Architectures already delivered to this user: {len(earlier)}."]
for item in list(earlier)[-_EARLIER_SHOWN:]:
request = " ".join(str(item.get("workflow_request", "")).split())[:300]
lines.append(f"- {request}")
lines.append(f"The user's message: {message[:_MESSAGE_LIMIT]}")
return "\n".join(lines)

View File

@@ -139,6 +139,9 @@ class Readings:
judged: dict[str, Any] = field(default_factory=dict) # what the decider answered
# How much of the agreed requirements is shown to the decider with a user's message.
_AGREED_LIMIT = 24_000
# The actions that reopen a Deliverable, and which one.
_REOPENS = (
"revise_requested",
@@ -356,6 +359,15 @@ class Router:
# our own question about a change they already asked for.
structured = reply.get("kind") == "changes" or bool(pending)
agreed = (
""
if structured
else str(
view.deliverables.get(DeliverableKind.REQUIREMENTS.value, {})
.get("attachments", {})
.get(REQUIREMENTS_FILE, "")
)[:_AGREED_LIMIT]
)
questions = {
"change_target": Question(
"choice",
@@ -375,9 +387,18 @@ class Router:
"Is the user asking for a change to work that has already been "
"submitted, as opposed to answering a question or adding information?",
)
if agreed:
# Someone who restates what is already agreed is answering, however
# much it sounds like a requirement.
questions["already_agreed"] = Question(
"noul",
"Does the user's message only confirm or repeat what the agreed "
"requirements above already say, asking for nothing different?",
)
state = (
f"Submitted Deliverables: {', '.join(kind.value for kind in candidates)}.\n"
f"Questions waiting for the user: {len(view.pending_questions)}.\n"
+ (f"The agreed requirements:\n{agreed}\n" if agreed else "")
+ f"Questions waiting for the user: {len(view.pending_questions)}.\n"
# What we asked is background. Only the user's own words are their
# message: our question echoed back is not something they said.
+ (
@@ -412,6 +433,10 @@ class Router:
}
probability = 1.0 if structured else float(answers["asks_change"].value)
disposition = self._thresholds.disposition(probability)
restated = answers.get("already_agreed")
if restated is not None and restated.is_yes(self._thresholds.act):
# It restates what is agreed: an answer, not a change.
disposition = CLOSE
target_answer = answers["change_target"]
target = DeliverableKind(str(target_answer.value))
readings.change_target = target