Files
cp1-agents/individual-agents/ALZ-F02: Assessment & Disposition Workflow Agent/scripts/build_workflow.py
Jonathan Boniface e22d037ab0 ALZ-F02 Assessment: individual agents, intake, rate card input, critic fixes
- Six declarative agents generated from the v1.1 stories (scaffold_from_stories.py, ADR 0001),
  and a 9-step workflow export (build_workflow.py).
- Code-only intake (ADR 0008) verifies the one Discovery package in code before any agent.
- The rate card is the run input rate_card_document; no upload step (ADR 0009).
- Critic 0.1.6 after live runs on crucible-kab-dev:
  - K-12 model independence checked at build time against each agent's deployed model
    (ADR 0010); the critic reports it from its two inputs;
  - receives in_cloud_estate for K-10; an unverified K-10 never fails the run alone;
  - K-08 allows the scoring note to list findings as advisory, as ALZ-ASM-04 must;
  - carries ALZ-ASM-03's and ALZ-ASM-04's rule sections, copied by the scaffold, so it can
    recalculate risk, confidence and TCO.
- The scaffold refuses to regenerate unless every story file is present.
- Case azure-crucible-kab-dev-assessment with an illustrative rate card.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 22:13:25 +00:00

212 lines
13 KiB
Python

#!/usr/bin/env python3
"""Write workflows/cp1-alz-assessment-individual.json: the KAB workflow export chaining the six Assessment agents.
The same export format as the ALZ-F01 individual workflow (export_version 2.0.0). There is no orchestrator: each
step is one agent, and each step's inputs are run inputs or named fields of earlier steps' outputs (`from_steps`).
Profiling, risk and security posture run in parallel; the critic's step stops for the Engagement Lead's approval,
which is the `disposition_signoff` gate (ADR 0004). The build refuses a critic on one of its executors' models (K-12, ADR
0010), reading each agent's deployed model from its kubernetes/configmap.yaml. Each step's schemas are read from its agent's schemas/ folder,
so run this again after changing them. Standard library only.
The intake (s0, ADR 0008) checks the Discovery package in code before the planner starts, and fails the run if the
package is missing, changed, incomplete, from a failed critic, or from another run.
Front steps (ADR 0002):
a1 Artifacts: the Discovery run's artifacts, by exact id -> a1.artifacts
p1 Parse Assessment Files over a1's records -> p1.parsed_content, p1.file_metadata
The Artifacts step has one output, `artifacts`: per-file records with base64 content (platform migration 024). p1
turns them into text, so no model copies Discovery's records on the way.
Run inputs: engagement_id, run_id, discovery_execution_id, discovery_approval_ref, rate_card_document (the rate
card's JSON as text, ADR 0009) and, unless --artifact-id fixes it in the export, artifact_ids (the Discovery package).
There is no upload: KAB hands every run input to every step, so an uploaded `file` would reach p1 and be parsed in
place of the package.
Usage (from the Feature folder): python3 scripts/build_workflow.py [--artifact-id ID ...] [--out FILE]
"""
from __future__ import annotations
import argparse
import json
import re
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[3] / "scripts"))
from kab_front_steps import AGENT_STEP_TIMEOUT_MINUTES, _activity_step # noqa: E402
ROOT = Path(__file__).resolve().parents[1]
NAME = "CP1 - Agentic Landing Zone - Assessment (individual agents)"
STAMP = "2026-11-02T12:00:00"
WF = ["engagement_id", "run_id", "discovery_execution_id"]
# The rate card is a run input, its JSON as text (ADR 0009): an uploaded `file` reaches every step, and the parse
# step that reads the Discovery package would read it instead.
RATE_CARD_STEPS = ("s1", "s5", "s6")
CRITIC_STATIC = {"critic_model": "gpt-5.4", "executor_models": ["gpt-5.6-sol"]} # ADR 0005
DOC = {"discovery_documents": "p1.parsed_content", "discovery_files": "p1.file_metadata"}
PLAN = {"tasks": "s1.tasks", "applications": "s1.applications"}
# (step id, agent folder, parallel group, inputs from earlier steps)
STEPS = [
# The intake checks the Discovery package in code first; a refused package fails this step (ADR 0008).
("s0", "cp1-assessment-intake-agent", 2, {"discovery_documents": "p1.parsed_content"}),
("s1", "cp1-assessment-planner-agent", 3, {**DOC}),
("s2", "cp1-cloud-readiness-profiler-agent", 4, {**DOC, **PLAN}),
("s3", "cp1-migration-risk-scorer-agent", 4, {**DOC, **PLAN}),
("s4", "cp1-security-posture-assessment-agent", 4, {**DOC, **PLAN, "in_cloud_estate": "s1.in_cloud_estate"}),
("s5", "cp1-disposition-tco-agent", 5, {**DOC, **PLAN, "rate_card_id": "s1.rate_card_id",
"profiles": "s2.profiles",
"scores": "s3.scores", "high_risk_tail": "s3.high_risk_tail",
"security_findings": "s4.findings"}),
("s6", "cp1-assessment-critic-agent", 6, {**DOC, **PLAN,
"coverage_gaps": "s1.coverage_gaps", "preconditions": "s1.preconditions",
"in_cloud_estate": "s1.in_cloud_estate",
"profiles": "s2.profiles", "profile_gaps": "s2.gaps",
"scores": "s3.scores", "high_risk_tail": "s3.high_risk_tail",
"posture_status": "s4.status", "security_findings": "s4.findings",
"dispositions": "s5.dispositions", "signoff_queue": "s5.signoff_queue"}),
]
FRONT_OUTPUTS = {"a1": {"artifacts"},
"p1": {"parsed_content", "file_metadata", "total_files", "total_content_length"}}
PARSE_OUT = {"type": "object", "properties": {
"parsed_content": {"type": "string", "description": "Combined parsed text content"},
"file_metadata": {"type": "array", "description": "Metadata about each parsed file"},
"total_files": {"type": "number"}, "total_content_length": {"type": "number"}}}
def model_of(folder: str) -> str:
"""The model an agent is deployed with: LITELLM_MODEL in its kubernetes/configmap.yaml."""
return field(ROOT / folder / "kubernetes" / "configmap.yaml", " LITELLM_MODEL")
def check_model_independence() -> None:
"""K-12, settled here rather than by the critic (ADR 0010): the critic's model is none of its executors' models.
The critic step's static `critic_model` and `executor_models` must also be the models the agents are deployed
with, so the names the critic is given are true.
"""
critic = CRITIC_STATIC["critic_model"]
assert model_of("cp1-assessment-critic-agent") == critic, f"the critic is deployed on {model_of('cp1-assessment-critic-agent')}, not {critic}"
for _, folder, _, _ in STEPS:
if folder != "cp1-assessment-critic-agent":
assert model_of(folder) in CRITIC_STATIC["executor_models"], f"{folder} runs {model_of(folder)}, not in executor_models"
assert critic not in CRITIC_STATIC["executor_models"], f"K-12: the critic's model {critic} is an executor model"
def field(path: Path, key: str) -> str:
return re.search(rf'^{key}:\s*"?([^"\n]+)"?$', path.read_text(), re.M).group(1)
def front(artifact_ids) -> list:
a1_inputs = {"static": {"artifact_ids": list(artifact_ids)}} if artifact_ids else {"from_workflow": ["artifact_ids"]}
a1 = _activity_step(
"a1", "select_artifacts", "Artifacts",
"The Discovery run's step outputs, by exact artifact id (never a name or a workflow id). Only a Discovery run "
"whose critic passed and which was approved should be selected.",
a1_inputs,
{"type": "object", "properties": {"artifact_ids": {
"type": "array", "items": {"type": "string"}, "label": "Discovery artifacts",
"description": "The Discovery run's artifacts", "uiFieldType": "artifact_picker"}},
"required": ["artifact_ids"]},
{"type": "object", "properties": {"artifacts": {"type": "array",
"description": "Per-file records with base64 content"}}},
y=160)
p1 = _activity_step(
"p1", "parse_assessment_files", "Parse Discovery outputs",
"Turns the selected Discovery artifacts into text for the agents.",
{"from_steps": {"files": "a1.artifacts"}},
{"type": "object", "properties": {"files": {"type": "array"}}}, PARSE_OUT, y=160)
p1.update({"executionLevel": 1, "parallelGroup": 1, "depends_on": ["a1"], "position": {"x": 0, "y": 160}})
a1["position"] = {"x": -320, "y": 160}
return [a1, p1]
def build(artifact_ids=()) -> dict:
check_model_independence()
by_id = {sid: folder for sid, folder, _, _ in STEPS}
steps = front(artifact_ids)
connections = [{"source": "a1", "target": "p1"}]
agents = []
for sid, folder, group, from_steps in STEPS:
agent = ROOT / folder
agent_id = folder.replace("-", "_")
display = field(agent / "agent.yaml", "display_name")
url = f"http://{folder}.agents.svc.cluster.local:8080"
input_schema = json.loads((agent / "schemas" / "input.json").read_text())
output_schema = json.loads((agent / "schemas" / "output.json").read_text())
for target, source in from_steps.items():
src_step, src_field = source.split(".")
assert target in input_schema["properties"], f"{sid}: {target} is not an input of {folder}"
if src_step in FRONT_OUTPUTS:
assert src_field in FRONT_OUTPUTS[src_step], f"{sid}: {source} is not an output of {src_step}"
continue
src_out = json.loads((ROOT / by_id[src_step] / "schemas" / "output.json").read_text())
assert src_field in src_out["properties"], f"{sid}: {source} is not an output of {by_id[src_step]}"
inputs = {"from_workflow": WF + (["discovery_approval_ref"] if sid == "s1" else [])
+ (["rate_card_document"] if sid in RATE_CARD_STEPS else []), "from_steps": from_steps}
if sid == "s6":
for k in CRITIC_STATIC:
assert k in input_schema["properties"], k
inputs["static"] = dict(CRITIC_STATIC)
for k in inputs["from_workflow"]:
assert k in input_schema["properties"], f"{sid}: run input {k} is not an input of {folder}"
# The planner waits for the intake: nothing reads Discovery until its package is checked (ADR 0008).
depends = sorted({s.split(".")[0] for s in from_steps.values()} | ({"s0"} if sid == "s1" else set()))
connections += [{"source": d, "target": sid} for d in depends]
hitl = {"enabled": False}
if sid == "s6":
hitl = {"enabled": True, "checkpoint_type": "approval",
"review_focus": "disposition_signoff: the Engagement Lead reads the critic's verdict and every "
"disposition in signoff_queue (confidence below 0.80, and every repurchase or "
"relocate) before Strategy starts. A fail verdict is never approved.",
"timeout_hours": 72, "allowed_actions": ["continue", "rerun", "abort"], "max_reruns": 2}
y = {"s2": -160, "s3": 0, "s4": 160}.get(sid, 0)
steps.append({
"id": sid, "agent": agent_id, "agent_type": agent_id, "name": f"{display} Step",
"timeout_minutes": AGENT_STEP_TIMEOUT_MINUTES, "type": "sequential", "executionLevel": group,
"parallelGroup": group, "depends_on": depends, "position": {"x": 320 * (group - 1), "y": y},
"inputs": inputs, "hitl": hitl,
"data": {"agentType": agent_id, "name": f"{display} Step",
"description": field(agent / "agent.yaml", "description"), "category": "agent",
"temporalActivityName": "generic_agent_call",
"endpoint": {"url": url, "method": "POST", "timeout": AGENT_STEP_TIMEOUT_MINUTES * 60,
"protocol": "JSONRPC", "protocol_version": "0.3.0"},
"agent_metadata": {"agent_name": agent_id},
"inputSchema": input_schema, "outputSchema": output_schema}})
agents.append({"name": agent_id, "display_name": display, "source_url": url, "category": "agent"})
description = (f"{NAME}: the Discovery run's outputs and the rate card in; then "
+ "; then ".join(field(ROOT / f / "agent.yaml", "display_name") for _, f, _, _ in STEPS) + ".")
tags = ["cp1", "public-cloud", "agentic-landing-zone"]
return {
"export_version": "2.0.0", "export_timestamp": STAMP, "source_environment": "unknown",
"workflow": {"name": NAME, "description": description, "version": "0.1.0",
"category": "cross-industry-catalog", "sub_category": "Public Cloud", "tags": tags},
"dependencies": {"activities": [], "agents": agents},
"template": {"name": NAME, "version": "0.1.0", "description": description,
"metadata": {"name": NAME, "description": description,
"category": {"main": "cross-industry-catalog", "sub": "Public Cloud"},
"sub_category": "Public Cloud", "status": "draft", "tags": tags,
"created": f"{STAMP}.000Z", "modified": f"{STAMP}.000Z", "display_order": 2,
"is_public": False, "edge_visuals": []},
"connections": connections, "steps": steps},
}
def main(argv=None) -> int:
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("--artifact-id", action="append", default=[],
help="fix a Discovery artifact id in the export (otherwise the run supplies artifact_ids)")
parser.add_argument("--out", type=Path, default=ROOT / "workflows" / "cp1-alz-assessment-individual.json")
args = parser.parse_args(argv)
export = build(args.artifact_id)
args.out.parent.mkdir(parents=True, exist_ok=True)
args.out.write_text(json.dumps(export, indent=2) + "\n")
template = export["template"]
print(f"wrote {args.out}: {len(template['steps'])} steps, {len(template['connections'])} connections")
return 0
if __name__ == "__main__":
raise SystemExit(main())