79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
"""A review of the requirements: they describe the problem, not the solution.
|
|
|
|
Requirements discovery is kept apart from solutioning, so a requirement names no
|
|
product. That rule was an instruction the engine could not enforce; the evaluation
|
|
checked it only afterwards, against a list of product names. This asks the decider
|
|
(ADR-0007), once per requirement, whether it names a cloud product or managed
|
|
service. It never blocks: what it raises is returned to the Specialist once.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from collections.abc import Mapping, Sequence
|
|
from typing import Any
|
|
|
|
from execution_engine.adk.runtime import Decider, Question
|
|
from tests.reference_workflow.chain import REQUIREMENTS_FILE, read_list
|
|
from tests.reference_workflow.kinds import DeliverableKind
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
_TEXT = 200
|
|
|
|
|
|
class RequirementsReview:
|
|
def __init__(self, decider: Decider, *, act: float = 0.3) -> None:
|
|
self._decider = decider
|
|
# Lower than the router's threshold, from measurement on 2026-10-08: across
|
|
# 61 requirements from three passed runs the highest answer was 0.10, and
|
|
# requirements written to name a product scored 0.34, 0.61 and 0.93.
|
|
self._act = act
|
|
|
|
async def __call__(
|
|
self,
|
|
kind: DeliverableKind,
|
|
attachments: Mapping[str, str],
|
|
upstream: Mapping[str, Mapping[str, Any]] | None,
|
|
scope: str = "",
|
|
) -> Sequence[str]:
|
|
"""The requirements that name a product, each as a line for the Specialist."""
|
|
if kind != DeliverableKind.REQUIREMENTS:
|
|
return ()
|
|
items = [
|
|
item
|
|
for item in read_list(
|
|
{"requirements": {"attachments": attachments}},
|
|
"requirements",
|
|
REQUIREMENTS_FILE,
|
|
)
|
|
if isinstance(item.get("id"), str) and isinstance(item.get("text"), str)
|
|
]
|
|
if not items:
|
|
return ()
|
|
answers = await self._decider.decide(
|
|
"Requirements for a workload, written before any product is chosen.",
|
|
{
|
|
item["id"]: Question(
|
|
"noul",
|
|
f'Requirement: "{item["text"]}". Does it name a specific cloud '
|
|
"provider's product or managed service, as opposed to "
|
|
"describing what is needed?",
|
|
)
|
|
for item in items
|
|
},
|
|
scope=scope,
|
|
)
|
|
if not answers:
|
|
return ()
|
|
raised = [
|
|
f'{item["id"]} names a product or service: "{item["text"][:_TEXT]}". '
|
|
"Say what is needed, not what to use"
|
|
for item in items
|
|
if (answer := answers.get(item["id"])) is not None
|
|
and answer.is_yes(self._act)
|
|
]
|
|
if raised:
|
|
logger.info("[%s] requirements review raised %d", scope, len(raised))
|
|
return tuple(raised)
|