feat: a design-time coverage review, measured and left off
A reviewer role reads the requirements and recommendations against the Checks when the Target architecture is first submitted. Three runs of case 03: it did not stop the validator sending the design back, and the designs it reviewed ended with 87 and 93 Checks against 52, so they cost more. It stays behind DESIGN_COVERAGE_REVIEW, off (iteration 6 step 13). Also: the schema review no longer reads `true` or `false` in backticks as a setting name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,7 @@ ORCHESTRATOR = "orchestrator"
|
||||
PILLAR_ADVISOR = "pillar-advisor"
|
||||
REPLY_WRITER = "reply-writer"
|
||||
LESSON_CURATOR = "lesson-curator" # runs outside any Execution
|
||||
COVERAGE_REVIEWER = "coverage-reviewer" # reviews a design before its Approval
|
||||
PARTIALS_DIR = "partials"
|
||||
|
||||
_ALLOWED_FIELDS = {"role", "deliverable", "tools", "budget", "includes"}
|
||||
@@ -51,7 +52,7 @@ def load_roles(
|
||||
the lighter model the bundle names for its first attempt."""
|
||||
specialists = {spec.specialist: kind for kind, spec in DEPENDENCY_GRAPH.items()}
|
||||
required = {ORCHESTRATOR, PILLAR_ADVISOR, REPLY_WRITER, *specialists}
|
||||
optional = {LESSON_CURATOR}
|
||||
optional = {LESSON_CURATOR, COVERAGE_REVIEWER}
|
||||
learned = _deliverables_with_lessons(bundle) if lessons else set()
|
||||
|
||||
roles = {}
|
||||
|
||||
@@ -22,7 +22,7 @@ from langchain_core.runnables import RunnableConfig
|
||||
from langgraph.checkpoint.base import BaseCheckpointSaver
|
||||
from langgraph.types import Command
|
||||
|
||||
from app.adk.roles import load_roles
|
||||
from app.adk.roles import COVERAGE_REVIEWER, load_roles
|
||||
from app.adk.runtime import (
|
||||
AgentRuntime,
|
||||
Decider,
|
||||
@@ -50,6 +50,7 @@ from app.skills.agent_skills import discover_skills, skill_version
|
||||
from app.states.execution_state import check_customer_case
|
||||
from app.states.ledger import Ledger
|
||||
from app.tools.coverage import CoverageReview
|
||||
from app.tools.design_review import DesignCoverageReview
|
||||
from app.tools.execution import ORCHESTRATOR
|
||||
from app.tools.jev import JevDecider, JevLimits
|
||||
from app.tools.local import TerraformRunner, local_tools
|
||||
@@ -481,6 +482,10 @@ async def open_assembly(
|
||||
reviews.append(
|
||||
RequirementsReview(decider, act=settings.JEV_REQUIREMENTS_THRESHOLD)
|
||||
)
|
||||
if settings.DESIGN_COVERAGE_REVIEW and COVERAGE_REVIEWER in roles:
|
||||
# A model reads the requirements against the Checks, once, before the
|
||||
# design is approved: the reading the validator would make after the code.
|
||||
reviews.append(DesignCoverageReview(runtime, roles[COVERAGE_REVIEWER]))
|
||||
if settings.JEV_COVERAGE_REVIEW and isinstance(decider, JevDecider):
|
||||
# Optional, and off by default: Jev says which Check verifies each condition.
|
||||
reviews.append(CoverageReview(decider, none_at=settings.JEV_COVERAGE_THRESHOLD))
|
||||
|
||||
@@ -104,6 +104,12 @@ class Settings(BaseSettings):
|
||||
JEV_ACT_THRESHOLD: float = 0.75
|
||||
JEV_CLOSE_THRESHOLD: float = 0.15
|
||||
JEV_CONFIDENCE_THRESHOLD: float = 0.6
|
||||
# Have a model read the requirements and recommendations against the Checks
|
||||
# when the Target architecture is first submitted, and return what no Check
|
||||
# verifies to its author. The validator makes the same reading after the code
|
||||
# is written, when a gap costs a Revision of design, code and validation. One
|
||||
# model run in every Execution. Off until measured.
|
||||
DESIGN_COVERAGE_REVIEW: bool = False
|
||||
# Review a design's coverage at submission: for each condition a requirement
|
||||
# lists, which Check verifies it. Off until a full case has run with it.
|
||||
JEV_COVERAGE_REVIEW: bool = False
|
||||
|
||||
151
app/tools/design_review.py
Normal file
151
app/tools/design_review.py
Normal file
@@ -0,0 +1,151 @@
|
||||
"""A review of a design's coverage by a model, before anyone approves it.
|
||||
|
||||
The validator reads the requirements and recommendations against the Checks and
|
||||
proposes one for each condition nothing verifies. That reading needs no code, but it
|
||||
used to happen only after the code was written: in the runs of 2026-10-09 it sent
|
||||
the Target architecture back in four of seven, each time costing a Revision of the
|
||||
design, the code and the validation (iteration 6 step 12).
|
||||
|
||||
This is the same reading, made when the Target architecture is first submitted and
|
||||
returned to its author. It is a review like the others: what it raises is returned
|
||||
once and never blocks, and when it fails the submission stands.
|
||||
|
||||
It runs once in an Execution. A Revision is asked for by the validator or the user,
|
||||
who have just read the design; reviewing it again would pay for the same reading.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import Any
|
||||
|
||||
from app.adk.runtime import (
|
||||
AgentRuntime,
|
||||
AgentTask,
|
||||
RoleSpec,
|
||||
Submitted,
|
||||
ToolResult,
|
||||
ToolSpec,
|
||||
)
|
||||
from app.workflows.chain import (
|
||||
RECOMMENDATIONS_FILE,
|
||||
REQUIREMENTS_FILE,
|
||||
Upstream,
|
||||
read_list,
|
||||
)
|
||||
from app.workflows.deliverables import DeliverableKind
|
||||
from app.workflows.target_architecture import GRAPH_ATTACHMENT, GraphError, parse_graph
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
MAX_GAPS = 12
|
||||
|
||||
|
||||
class DesignCoverageReview:
|
||||
def __init__(self, runtime: AgentRuntime, role: RoleSpec) -> None:
|
||||
self._runtime = runtime
|
||||
self._role = role
|
||||
self._reviewed: set[str] = set()
|
||||
|
||||
async def __call__(
|
||||
self,
|
||||
kind: DeliverableKind,
|
||||
attachments: Mapping[str, str],
|
||||
upstream: Upstream | None,
|
||||
scope: str = "",
|
||||
) -> Sequence[str]:
|
||||
"""The conditions the reviewer finds no Check verifies, each as a line for
|
||||
the target architect. Empty when it finds none or could not review."""
|
||||
if kind is not DeliverableKind.TARGET_ARCHITECTURE or not upstream:
|
||||
return ()
|
||||
text = attachments.get(GRAPH_ATTACHMENT, "")
|
||||
try:
|
||||
graph = parse_graph(text)
|
||||
except GraphError:
|
||||
return ()
|
||||
if scope in self._reviewed:
|
||||
return ()
|
||||
self._reviewed.add(scope)
|
||||
|
||||
constraints = [
|
||||
item
|
||||
for item in read_list(upstream, "requirements", REQUIREMENTS_FILE)
|
||||
if item.get("kind") == "non_functional"
|
||||
] + read_list(upstream, "design_recommendations", RECOMMENDATIONS_FILE)
|
||||
known = {str(item.get("id")) for item in constraints}
|
||||
applies_to = {element.id for element in graph.elements} | {
|
||||
relationship.id for relationship in graph.relationships
|
||||
}
|
||||
|
||||
async def report_gaps(gaps: Any = None) -> ToolResult:
|
||||
if not isinstance(gaps, list):
|
||||
return ToolResult("Not recorded: `gaps` is a list; empty when none.")
|
||||
return ToolResult("Recorded.", Submitted(json.dumps(gaps)))
|
||||
|
||||
tool = ToolSpec(
|
||||
"report_gaps",
|
||||
"Give every gap you found, in one call. An empty list when the Checks "
|
||||
"verify every condition. Ends your turn.",
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"gaps": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"source": {
|
||||
"type": "string",
|
||||
"description": "The requirement or recommendation id",
|
||||
},
|
||||
"applies_to": {
|
||||
"type": "string",
|
||||
"description": "The Element or Relationship id",
|
||||
},
|
||||
"statement": {
|
||||
"type": "string",
|
||||
"description": "The Check that is missing",
|
||||
},
|
||||
},
|
||||
"required": ["source", "applies_to", "statement"],
|
||||
},
|
||||
}
|
||||
},
|
||||
"required": ["gaps"],
|
||||
},
|
||||
report_gaps,
|
||||
tier="execution",
|
||||
)
|
||||
task = AgentTask(
|
||||
role=self._role.name,
|
||||
prompt="Review whether the Target architecture's Checks verify every "
|
||||
"condition of the requirements and recommendations.",
|
||||
context={
|
||||
"constraints": constraints,
|
||||
"target_architecture": json.loads(text),
|
||||
},
|
||||
)
|
||||
outcome = await self._runtime.run(self._role, task, [tool])
|
||||
if not isinstance(outcome, Submitted):
|
||||
logger.info("[%s] design coverage review gave no answer", scope)
|
||||
return ()
|
||||
try:
|
||||
reported = json.loads(outcome.content)
|
||||
except ValueError:
|
||||
return ()
|
||||
concerns = []
|
||||
for gap in reported if isinstance(reported, list) else []:
|
||||
if not isinstance(gap, Mapping):
|
||||
continue
|
||||
source, where = str(gap.get("source", "")), str(gap.get("applies_to", ""))
|
||||
statement = " ".join(str(gap.get("statement", "")).split())
|
||||
# A gap must be about something that exists: an invented id is dropped.
|
||||
if source not in known or where not in applies_to or not statement:
|
||||
continue
|
||||
concerns.append(f"{source}: no Check verifies this on {where}: {statement}")
|
||||
logger.info(
|
||||
"[%s] design coverage review raised %d gap(s)", scope, len(concerns)
|
||||
)
|
||||
return tuple(concerns[:MAX_GAPS])
|
||||
@@ -36,6 +36,9 @@ _NAME = re.compile(
|
||||
r"(?![\w/\-])"
|
||||
)
|
||||
_PATH = re.compile(r"^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)*$")
|
||||
# Values a Check may put in backticks. `true` and `false` were raised as missing
|
||||
# settings in a run of 2026-10-10.
|
||||
_LITERALS = frozenset({"true", "false", "null", "none"})
|
||||
|
||||
|
||||
def named_settings(statement: str) -> tuple[str, ...]:
|
||||
@@ -48,7 +51,7 @@ def named_settings(statement: str) -> tuple[str, ...]:
|
||||
found: list[str] = []
|
||||
for span in _CODE.findall(statement):
|
||||
candidate = span.strip().split("=")[0].strip()
|
||||
if _PATH.match(candidate):
|
||||
if _PATH.match(candidate) and candidate not in _LITERALS:
|
||||
found.append(candidate)
|
||||
bare = _QUOTED.sub(" ", _CODE.sub(" ", statement))
|
||||
found += [match.group(1).rstrip(".") for match in _NAME.finditer(bare)]
|
||||
|
||||
Reference in New Issue
Block a user