A caller restates a request to say how requirements have changed, naming a completed Execution of the same Customer case as the Baseline. - app/baseline.py reads a Baseline from its files and refuses one that does not exist, did not complete or belongs to another case, before anything runs or is recorded. A Baseline is never modified. - Requirements carry a change (unchanged, added, changed, removed) and a reason. Submission is refused when a Baseline requirement disappears, an id is reused, or an unchanged requirement's text differs. A removed requirement stays on record and asks nothing downstream. - Each Specialist starts from its delivered version; the graph and the code are its working copy, and the description is carried over when the design's shape is the same. - app/workflows/changes.py compares versions by id and traces what each changed requirement reaches; anything else that changed is listed as unrequested. Approvals show the change for their Phase, and changes.json is written with the full Deliverables. - Intake no longer starts a message read as a change: it names the Execution to give as the Baseline. - A fifth evaluation case runs a request and then a change to it, with four checks that the change is recorded, reaches Checks, stays contained and costs less than its Baseline. Tested with scripted agents only; no Change request has run with real models. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
138 lines
5.4 KiB
Python
138 lines
5.4 KiB
Python
"""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 name the Baseline to change (ADR-0006)
|
|
question what can you do, how long... answer; start nothing
|
|
|
|
A change is never started from earlier work on a guess: the caller chooses the
|
|
Baseline. So a message read as a change is answered with the Execution it would
|
|
change and how to name it, and starts 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."
|
|
)
|
|
|
|
|
|
def change_note(baseline: str) -> str:
|
|
"""What a caller is told when their message reads as a change to delivered work."""
|
|
return (
|
|
"This reads as a change to the architecture already delivered for this "
|
|
f"Customer case, in Execution {baseline}. Nothing was started. To change "
|
|
f'that architecture from where it stood, send this again with "baseline" '
|
|
f'set to "{baseline}". To design it as new work instead, send it again '
|
|
'with "new_request" set to true.'
|
|
)
|
|
|
|
|
|
_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
|
|
latest: str | None = None # the most recent of them: what a change would change
|
|
|
|
|
|
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)
|
|
latest = str(earlier[-1].get("execution_id")) if earlier else None
|
|
return IntakeReading(
|
|
kind, confidence, judged=True, earlier=len(earlier), latest=latest
|
|
)
|
|
|
|
|
|
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)
|