feat: overlay Skills, and five more Jev decisions (iterations 4 and 5)
Iteration 4: - Overlay Skills (step 12): an Execution names an organisation's standards Skill from the folders the deployment configures; recorded with its version. An example standards Skill and an evaluation case that uses it. - Lessons (step 10): a prove command that compares a run with lessons against one without, and triage of evidence an existing lesson already covers. Iteration 5: - Step 8: the references of a Specialist's Skills its task needs are named in its context as read_first. - Step 14: a remote MCP server's reply that instructs the agent is withheld; the user's own text is flagged as a risk and nothing more. - Step 15: in a Change request, items only reworded are listed apart from real changes. - Step 19: each Execution's design recommendations are judged when it ends and the scores kept in its record. The evaluation takes its rubric from the same place. Each question was calibrated against live Jev; none has run in a case. Steps 6, 7, 9, 13 and 18 stay planned, with the reasons in the plan map. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
97
tests/execution/test_assessment.py
Normal file
97
tests/execution/test_assessment.py
Normal file
@@ -0,0 +1,97 @@
|
||||
"""Every Execution is judged as it ends (iteration 5 step 19)."""
|
||||
|
||||
import json
|
||||
|
||||
from langgraph.checkpoint.memory import InMemorySaver
|
||||
|
||||
from app.adk.fake_runtime import FakeAgentRuntime, FakeDecider, sample_submission
|
||||
from app.adk.runtime import Answer, NoDecider, RoleSpec
|
||||
from app.agent import ExecutionEngine
|
||||
from app.nodes.router import Router, Thresholds
|
||||
from app.recorder import InMemoryRecorder
|
||||
from app.tools.assessment import QUALITY_RUBRIC, assess
|
||||
from app.workflows.deliverables import DEPENDENCY_GRAPH
|
||||
|
||||
ROLES = {
|
||||
"orchestrator": RoleSpec("orchestrator", "Unused.", budget=40),
|
||||
**{
|
||||
spec.specialist: RoleSpec(spec.specialist, "Produce.", budget=15)
|
||||
for spec in DEPENDENCY_GRAPH.values()
|
||||
},
|
||||
}
|
||||
ADVICE = {"design_recommendations": {"content": "Use two zones for the database."}}
|
||||
|
||||
|
||||
def graded(level: float) -> FakeDecider:
|
||||
return FakeDecider({key: Answer(level, 0.9) for key in QUALITY_RUBRIC})
|
||||
|
||||
|
||||
async def test_the_rubric_is_scored_from_nought_to_one_with_its_mean():
|
||||
decider = graded(3.0)
|
||||
decider.answers["specific"] = Answer(1.5, 0.9)
|
||||
|
||||
assessment = await assess(decider, ADVICE)
|
||||
|
||||
assert assessment == {
|
||||
"recommendations_quality": {
|
||||
"specific": 0.5,
|
||||
"actionable": 1.0,
|
||||
"trade_offs": 1.0,
|
||||
"traceable": 1.0,
|
||||
},
|
||||
"mean": 0.88,
|
||||
"meets_bar": True,
|
||||
}
|
||||
document, _, _ = decider.asked[0]
|
||||
assert document == "Use two zones for the database."
|
||||
|
||||
|
||||
async def test_a_weak_design_is_reported_as_below_the_bar():
|
||||
assessment = await assess(graded(1.0), ADVICE)
|
||||
|
||||
assert assessment["mean"] == 0.33 and assessment["meets_bar"] is False
|
||||
|
||||
|
||||
async def test_nothing_to_judge_or_no_decision_gives_no_assessment():
|
||||
assert await assess(graded(3.0), {}) is None
|
||||
assert await assess(NoDecider(), ADVICE) is None
|
||||
|
||||
|
||||
def engine(tmp_path, decider, **options) -> ExecutionEngine:
|
||||
return ExecutionEngine(
|
||||
runtime=FakeAgentRuntime(
|
||||
{
|
||||
spec.specialist: [[sample_submission(kind)]]
|
||||
for kind, spec in DEPENDENCY_GRAPH.items()
|
||||
}
|
||||
),
|
||||
roles=ROLES,
|
||||
recorder=InMemoryRecorder(),
|
||||
checkpointer=InMemorySaver(),
|
||||
output_root=tmp_path,
|
||||
orchestrator=Router(NoDecider(), None, Thresholds()),
|
||||
decider=decider,
|
||||
**options,
|
||||
)
|
||||
|
||||
|
||||
async def test_a_completed_execution_carries_its_assessment(tmp_path):
|
||||
result = await engine(tmp_path, graded(1.0), assess_at_end=True).start(
|
||||
"Ingest webhooks", pre_approved=True
|
||||
)
|
||||
|
||||
# A low score is reported and the Execution still completes.
|
||||
assert result.status == "completed"
|
||||
assert result.state["assessment"]["meets_bar"] is False
|
||||
manifest = json.loads(next(tmp_path.rglob("execution.json")).read_text())
|
||||
assert manifest["assessment"] == result.state["assessment"]
|
||||
|
||||
|
||||
async def test_an_execution_is_not_judged_unless_that_is_switched_on(tmp_path):
|
||||
decider = graded(3.0)
|
||||
|
||||
result = await engine(tmp_path, decider).start("Ingest webhooks", pre_approved=True)
|
||||
|
||||
assert result.state["assessment"] is None and decider.asked == []
|
||||
manifest = json.loads(next(tmp_path.rglob("execution.json")).read_text())
|
||||
assert manifest["assessment"] is None
|
||||
@@ -713,3 +713,52 @@ async def test_a_first_consultation_is_given_no_hint(tmp_path):
|
||||
await engine.start("Ingest webhooks", pre_approved=True)
|
||||
|
||||
assert seen["pillars_to_consult"] is None and decider.asked == []
|
||||
|
||||
|
||||
# --- changed, or only reworded? ---------------------------------------------------------
|
||||
|
||||
|
||||
async def test_an_item_that_was_only_reworded_is_listed_apart_from_real_changes():
|
||||
from app.adk.fake_runtime import FakeDecider
|
||||
from app.adk.runtime import Answer
|
||||
from app.tools.meaning import settle_meaning
|
||||
from app.workflows.changes import change_summary
|
||||
|
||||
def revise(graph):
|
||||
graph["checks"][0]["statement"] = "The service runs at least three instances."
|
||||
graph["checks"][1]["statement"] = "This service alone uses the identity."
|
||||
|
||||
before, after = versions(revise)
|
||||
summary = change_summary(before, after)
|
||||
assert summary["checks"]["changed"] == ["K-1", "K-2"]
|
||||
decider = FakeDecider({"K-1": Answer(0.95, 0.9), "K-2": Answer(0.1, 0.8)})
|
||||
|
||||
settled = await settle_meaning(decider, summary, before, after, scope="v2")
|
||||
|
||||
assert settled["checks"]["changed"] == ["K-1"]
|
||||
assert settled["checks"]["reworded"] == ["K-2"]
|
||||
assert settled["meaning"] == {"K-1": 0.95, "K-2": 0.1}
|
||||
# K-2 was outside the reach of what changed; reworded, it is no longer unrequested.
|
||||
assert settled["unrequested"] == {}
|
||||
_, questions, scope = decider.asked[0]
|
||||
assert scope == "v2"
|
||||
assert "The identity is used by this service only." in questions["K-2"].instructions
|
||||
assert "This service alone uses the identity." in questions["K-2"].instructions
|
||||
# The summary given in is not altered.
|
||||
assert summary["checks"]["changed"] == ["K-1", "K-2"]
|
||||
|
||||
|
||||
async def test_without_a_decision_everything_that_differs_stays_changed():
|
||||
from app.tools.meaning import settle_meaning
|
||||
from app.workflows.changes import change_summary
|
||||
|
||||
def revise(graph):
|
||||
graph["checks"][1]["statement"] = "This service alone uses the identity."
|
||||
|
||||
before, after = versions(revise)
|
||||
summary = change_summary(before, after)
|
||||
|
||||
settled = await settle_meaning(NoDecider(), summary, before, after)
|
||||
|
||||
assert settled["checks"]["changed"] == ["K-2"]
|
||||
assert "reworded" not in settled["checks"] and "meaning" not in settled
|
||||
|
||||
169
tests/execution/test_overlay_skills.py
Normal file
169
tests/execution/test_overlay_skills.py
Normal file
@@ -0,0 +1,169 @@
|
||||
"""Overlay Skills (ADR-0004): an organisation's standards, named per Execution.
|
||||
|
||||
They come only from folders the deployment configures. A caller names one; it can
|
||||
never supply one, and an unknown name refuses the start.
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from langgraph.checkpoint.memory import InMemorySaver
|
||||
|
||||
from app.adk.fake_runtime import FakeAgentRuntime, sample_submission
|
||||
from app.adk.runtime import NoDecider, RoleSpec
|
||||
from app.agent import ExecutionEngine, discover_overlays, skill_dirs
|
||||
from app.config import Settings
|
||||
from app.nodes.router import Router, Thresholds
|
||||
from app.providers import load_provider
|
||||
from app.recorder import InMemoryRecorder
|
||||
from app.workflows.deliverables import DEPENDENCY_GRAPH
|
||||
|
||||
ROLES = {
|
||||
"orchestrator": RoleSpec("orchestrator", "Unused.", budget=40),
|
||||
**{
|
||||
spec.specialist: RoleSpec(
|
||||
spec.specialist, "Produce.", budget=15, skills=("provider-skill",)
|
||||
)
|
||||
for spec in DEPENDENCY_GRAPH.values()
|
||||
},
|
||||
}
|
||||
OVERLAYS = {"acme-standards": "abc123", "project-x": "def456"}
|
||||
|
||||
|
||||
class Recording(FakeAgentRuntime):
|
||||
def __init__(self, turns):
|
||||
super().__init__(turns)
|
||||
self.skills: dict[str, tuple[str, ...]] = {}
|
||||
|
||||
async def run(self, role, task, tools):
|
||||
self.skills[role.name] = role.skills
|
||||
return await super().run(role, task, tools)
|
||||
|
||||
|
||||
def engine(tmp_path: Path, **options) -> tuple[ExecutionEngine, Recording]:
|
||||
runtime = Recording(
|
||||
{
|
||||
spec.specialist: [[sample_submission(kind)]]
|
||||
for kind, spec in DEPENDENCY_GRAPH.items()
|
||||
}
|
||||
)
|
||||
built = ExecutionEngine(
|
||||
runtime=runtime,
|
||||
roles=ROLES,
|
||||
recorder=InMemoryRecorder(),
|
||||
checkpointer=InMemorySaver(),
|
||||
output_root=tmp_path,
|
||||
orchestrator=Router(NoDecider(), None, Thresholds()),
|
||||
overlays=OVERLAYS,
|
||||
**options,
|
||||
)
|
||||
return built, runtime
|
||||
|
||||
|
||||
async def test_every_specialist_loads_the_overlays_the_execution_names(tmp_path):
|
||||
built, runtime = engine(tmp_path)
|
||||
|
||||
result = await built.start(
|
||||
"Ingest webhooks",
|
||||
customer_case="acme",
|
||||
pre_approved=True,
|
||||
execution_id="v1",
|
||||
overlay_skills=["acme-standards"],
|
||||
)
|
||||
|
||||
assert result.status == "completed"
|
||||
assert set(runtime.skills.values()) == {("provider-skill", "acme-standards")}
|
||||
analyst = next(run for run in runtime.runs if run.role == "requirements-analyst")
|
||||
assert analyst.task.context["overlay_skills"] == ["acme-standards"]
|
||||
# The Execution records which overlays it loaded, and the version of each.
|
||||
assert result.state["overlay_skills"] == {"acme-standards": "abc123"}
|
||||
manifest = json.loads(
|
||||
(tmp_path / "deliverables/cases/acme/executions/v1/execution.json").read_text()
|
||||
)
|
||||
assert manifest["overlay_skills"] == {"acme-standards": "abc123"}
|
||||
lessons = json.loads((tmp_path / "lessons/candidates/acme/v1.json").read_text())
|
||||
assert lessons["skill_versions"]["acme-standards"] == "abc123"
|
||||
|
||||
|
||||
async def test_an_unknown_overlay_refuses_the_start(tmp_path):
|
||||
built, runtime = engine(tmp_path)
|
||||
|
||||
with pytest.raises(ValueError, match="Unknown overlay Skills: evil-skill"):
|
||||
await built.start("Ingest webhooks", overlay_skills=["evil-skill"])
|
||||
with pytest.raises(ValueError, match="must be a list of Skill names"):
|
||||
await built.start("Ingest webhooks", overlay_skills="acme-standards")
|
||||
|
||||
assert runtime.runs == []
|
||||
assert not (tmp_path / "deliverables").exists()
|
||||
|
||||
|
||||
async def test_the_deployments_default_overlays_are_loaded_with_the_callers(tmp_path):
|
||||
built, runtime = engine(tmp_path, default_overlays=["acme-standards"])
|
||||
|
||||
result = await built.start(
|
||||
"Ingest webhooks", pre_approved=True, overlay_skills=["project-x"]
|
||||
)
|
||||
|
||||
assert list(result.state["overlay_skills"]) == ["acme-standards", "project-x"]
|
||||
assert runtime.skills["iac-author"] == (
|
||||
"provider-skill",
|
||||
"acme-standards",
|
||||
"project-x",
|
||||
)
|
||||
|
||||
|
||||
async def test_without_overlays_a_role_has_only_its_own_skills(tmp_path):
|
||||
built, runtime = engine(tmp_path)
|
||||
|
||||
result = await built.start("Ingest webhooks", pre_approved=True)
|
||||
|
||||
assert result.state["overlay_skills"] == {}
|
||||
assert set(runtime.skills.values()) == {("provider-skill",)}
|
||||
|
||||
|
||||
def test_a_default_overlay_the_deployment_does_not_have_is_an_error(tmp_path):
|
||||
with pytest.raises(ValueError, match="Unknown default overlay Skills: nope"):
|
||||
engine(tmp_path, default_overlays=["nope"])
|
||||
|
||||
|
||||
# --- where overlays come from ------------------------------------------------------------
|
||||
|
||||
|
||||
def overlay(folder: Path, name: str) -> None:
|
||||
(folder / name).mkdir(parents=True)
|
||||
(folder / name / "SKILL.md").write_text(
|
||||
f"---\nname: {name}\ndescription: Standards for {name}.\n---\n# {name}\n"
|
||||
)
|
||||
|
||||
|
||||
def test_overlays_are_found_only_in_the_folders_the_deployment_names(tmp_path):
|
||||
overlay(tmp_path / "overlays", "acme-standards")
|
||||
overlay(tmp_path / "elsewhere", "not-configured")
|
||||
settings = Settings(OVERLAY_SKILLS_DIRS=str(tmp_path / "overlays"))
|
||||
bundle = load_provider("gcp")
|
||||
|
||||
found = discover_overlays(settings, bundle)
|
||||
|
||||
assert list(found) == ["acme-standards"]
|
||||
assert skill_dirs(settings, bundle)["acme-standards"] == (
|
||||
tmp_path / "overlays" / "acme-standards"
|
||||
)
|
||||
assert set(bundle.skills) < set(skill_dirs(settings, bundle))
|
||||
|
||||
|
||||
def test_an_overlay_may_not_take_a_provider_skills_name(tmp_path):
|
||||
overlay(tmp_path / "overlays", "requirements-chain")
|
||||
settings = Settings(OVERLAY_SKILLS_DIRS=str(tmp_path / "overlays"))
|
||||
|
||||
with pytest.raises(ValueError, match="reuse the names of provider Skills"):
|
||||
discover_overlays(settings, load_provider("gcp"))
|
||||
|
||||
|
||||
def test_the_example_overlay_is_a_valid_skill_and_is_not_loaded_by_default():
|
||||
settings = Settings()
|
||||
|
||||
assert "example-organisation-standards" in discover_overlays(
|
||||
settings, load_provider("gcp")
|
||||
)
|
||||
assert Settings(DEFAULT_OVERLAY_SKILLS="").default_overlays() == []
|
||||
121
tests/execution/test_skill_routing.py
Normal file
121
tests/execution/test_skill_routing.py
Normal file
@@ -0,0 +1,121 @@
|
||||
"""Which references a Specialist is told to read first (iteration 5 step 8)."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from langgraph.checkpoint.memory import InMemorySaver
|
||||
|
||||
from app.adk.fake_runtime import FakeAgentRuntime, FakeDecider, sample_submission
|
||||
from app.adk.runtime import Answer, NoDecider, RoleSpec
|
||||
from app.agent import ExecutionEngine
|
||||
from app.nodes.router import Router, Thresholds
|
||||
from app.recorder import InMemoryRecorder
|
||||
from app.tools.skill_routing import read_first, references_of, routable
|
||||
from app.workflows.deliverables import DEPENDENCY_GRAPH
|
||||
from app.workflows.deliverables import DeliverableKind as K
|
||||
|
||||
PATTERNS = {
|
||||
"references/cloud-sql.md": "Cloud SQL. A private PostgreSQL instance.",
|
||||
"references/pubsub.md": "Pub/Sub. A topic and a subscription.",
|
||||
}
|
||||
|
||||
|
||||
def skill(root: Path, name: str, references: dict[str, str]) -> Path:
|
||||
folder = root / name
|
||||
(folder / "references").mkdir(parents=True)
|
||||
(folder / "SKILL.md").write_text(f"---\nname: {name}\ndescription: d\n---\n")
|
||||
for file, text in references.items():
|
||||
(folder / "references" / file).write_text(text)
|
||||
return folder
|
||||
|
||||
|
||||
def test_a_reference_is_described_by_its_title_and_first_paragraph(tmp_path):
|
||||
folder = skill(
|
||||
tmp_path,
|
||||
"patterns",
|
||||
{"kms.md": "# Cloud KMS\n\nA key ring and a key.\n\n- A rule.\n"},
|
||||
)
|
||||
|
||||
assert references_of(folder) == {
|
||||
"references/kms.md": "Cloud KMS. A key ring and a key"
|
||||
}
|
||||
|
||||
|
||||
def test_only_a_skill_with_enough_references_is_routed_within(tmp_path):
|
||||
many = skill(tmp_path, "many", {f"r{n}.md": f"# R{n}\n\nText.\n" for n in range(4)})
|
||||
few = skill(tmp_path, "few", {"one.md": "# One\n\nText.\n"})
|
||||
none = tmp_path / "none"
|
||||
none.mkdir()
|
||||
|
||||
assert list(routable({"many": many, "few": few, "none": none})) == ["many"]
|
||||
|
||||
|
||||
async def test_the_references_a_task_needs_are_named():
|
||||
decider = FakeDecider(
|
||||
{
|
||||
"patterns/references/cloud-sql.md": Answer(1.8, 0.9),
|
||||
"patterns/references/pubsub.md": Answer(0.1, 0.9),
|
||||
}
|
||||
)
|
||||
|
||||
chosen = await read_first(decider, "Write the code.", {"patterns": PATTERNS})
|
||||
|
||||
assert chosen == [{"skill": "patterns", "resource": "references/cloud-sql.md"}]
|
||||
_, questions, _ = decider.asked[0]
|
||||
assert "Cloud SQL. A private PostgreSQL instance." in (
|
||||
questions["patterns/references/cloud-sql.md"].instructions
|
||||
)
|
||||
|
||||
|
||||
async def test_without_a_decision_nothing_is_named():
|
||||
assert await read_first(NoDecider(), "Write.", {"patterns": PATTERNS}) is None
|
||||
|
||||
|
||||
async def test_a_specialist_with_routable_skills_is_told_where_to_start(tmp_path):
|
||||
roles = {
|
||||
"orchestrator": RoleSpec("orchestrator", "Unused.", budget=40),
|
||||
**{
|
||||
spec.specialist: RoleSpec(spec.specialist, "Produce.", budget=15)
|
||||
for spec in DEPENDENCY_GRAPH.values()
|
||||
},
|
||||
}
|
||||
seen: dict[str, object] = {}
|
||||
|
||||
def recording(kind):
|
||||
def turn(task):
|
||||
seen[kind.value] = task.context["read_first"]
|
||||
return [sample_submission(kind)]
|
||||
|
||||
return turn
|
||||
|
||||
decider = FakeDecider(
|
||||
{
|
||||
"patterns/references/cloud-sql.md": Answer(0.2, 0.9),
|
||||
"patterns/references/pubsub.md": Answer(1.9, 0.9),
|
||||
}
|
||||
)
|
||||
author = DEPENDENCY_GRAPH[K.DEPLOYMENT_GUIDANCE].specialist
|
||||
engine = ExecutionEngine(
|
||||
runtime=FakeAgentRuntime(
|
||||
{
|
||||
spec.specialist: [recording(kind)]
|
||||
for kind, spec in DEPENDENCY_GRAPH.items()
|
||||
}
|
||||
),
|
||||
roles=roles,
|
||||
recorder=InMemoryRecorder(),
|
||||
checkpointer=InMemorySaver(),
|
||||
output_root=tmp_path,
|
||||
orchestrator=Router(NoDecider(), None, Thresholds()),
|
||||
decider=decider,
|
||||
skill_references={author: {"patterns": PATTERNS}},
|
||||
)
|
||||
|
||||
await engine.start("Ingest webhooks", pre_approved=True)
|
||||
|
||||
assert seen[K.DEPLOYMENT_GUIDANCE.value] == [
|
||||
{"skill": "patterns", "resource": "references/pubsub.md"}
|
||||
]
|
||||
assert seen[K.REQUIREMENTS.value] is None
|
||||
state, _, _ = decider.asked[0]
|
||||
assert state.startswith("Write the deployment guidance Deliverable")
|
||||
assert "Elements of the Target architecture:" in state
|
||||
Reference in New Issue
Block a user