Files
cp1-agents/individual-agents/ALZ-F02: Assessment & Disposition Workflow Agent/scripts/build_workflow.py
Jonathan Boniface 66c32745aa
Some checks failed
check agents / check (push) Failing after 14s
F02: Assessment report and package (ADR 0014, 0015); register agents in KAB
- Report (cp1-assessment-report-agent 0.2.0, step s7): a model writes the
  Assessment report from facts worked out in code (register, gaps, scorecard,
  rule traces, checks, and what each application is from the Discovery
  package); code sets the verdict and renders the pages. The
  disposition_signoff review point moves from the critic to the report.
- Package (cp1-assessment-package-agent 0.1.1, step s8): after sign-off, every
  step's output in one package, with a register, a gaps register, the
  sign-off record, lineage and a sha256 per part, in code. Page step s9.
- scripts/kab_register_agents.py: registers deployed agents in KAB's agent
  catalog (an in-place workflow update doesn't).
- Runs exec_1b1257380df7 (014) and exec_374d5d577077 (015) completed on
  crucible-kab-dev: critic pass, report figures all in its facts, package
  complete with every digest recomputing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 20:19:10 +00:00

264 lines
18 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 report's step stops for the Engagement Lead's approval,
which is the `disposition_signoff` gate (ADR 0004, moved by ADR 0015). 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.
The report (s7, ADR 0015) is written by a model from facts worked out in code and carries the disposition_signoff
review point. Only after it is continued do the package (s8, ADR 0014: every step's output in one Assessment package,
in code, for Strategy and the later Features) and the approved report's page (s9) 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", "s8")
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"}),
]
# The report (ADR 0015) is written by a model from facts worked out in code, and carries the disposition_signoff review
# point, so the Engagement Lead signs off from it. After that review point: the package for Strategy and the later
# Features (ADR 0014), every input copied unchanged (cp1-assessment-package-agent/app/package.py INPUTS names the part
# each one belongs to), and the approved report as a page.
REPORT_STEP, PACKAGE_STEP, PAGE_STEP = "s7", "s8", "s9"
REVIEW_STEP = REPORT_STEP
PACKAGE_INPUTS = {
"intake_verified": "s0.verified", "discovery_run_id": "s0.discovery_run_id",
"discovery_package_version": "s0.package_version", "discovery_critic_verdict": "s0.critic_verdict",
"discovery_provider": "s0.provider", "discovery_parts_verified": "s0.parts_verified",
"discovery_absent_parts": "s0.absent_parts", "discovery_source_gaps": "s0.source_gaps",
"discovery_agent_versions": "s0.agent_versions",
"plan_status": "s1.status", "preconditions": "s1.preconditions", "rate_card_id": "s1.rate_card_id",
"in_cloud_estate": "s1.in_cloud_estate", "application_source": "s1.application_source",
"applications": "s1.applications", "tasks": "s1.tasks", "coverage_gaps": "s1.coverage_gaps",
"plan_summary": "s1.summary", "plan_note": "s1.findings_note",
"profiles": "s2.profiles", "profile_gaps": "s2.gaps", "profile_note": "s2.findings_note",
"scores": "s3.scores", "high_risk_tail": "s3.high_risk_tail", "risk_note": "s3.findings_note",
"posture_status": "s4.status", "security_provider": "s4.provider", "posture_score": "s4.posture_score",
"controls": "s4.controls", "security_findings": "s4.findings", "pillars": "s4.pillars",
"injection_flags": "s4.injection_flags", "security_note": "s4.findings_note",
"dispositions": "s5.dispositions", "producer_signoff_queue": "s5.signoff_queue", "scoring_note": "s5.scoring_note",
"verdict": "s6.verdict", "checks": "s6.checks", "rejected_dispositions": "s6.rejected_dispositions",
"signoff_queue": "s6.signoff_queue", "unverified_claims": "s6.unverified_claims",
"critic_model": "s6.critic_model", "executor_models": "s6.executor_models", "critic_summary": "s6.summary",
}
# The report also reads the Discovery package, to say what each application is (ADR 0015 addendum).
REPORT_INPUTS = {**PACKAGE_INPUTS, "discovery_documents": "p1.parsed_content"}
PACKAGE_INPUTS = {**PACKAGE_INPUTS, "report_markdown": f"{REPORT_STEP}.report_markdown"}
STEPS += [(REPORT_STEP, "cp1-assessment-report-agent", 7, REPORT_INPUTS),
(PACKAGE_STEP, "cp1-assessment-package-agent", 8, PACKAGE_INPUTS)]
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 in ("s1", REPORT_STEP, PACKAGE_STEP) else [])
+ (["artifact_ids"] if sid == PACKAGE_STEP and not artifact_ids else [])
+ (["rate_card_document"] if sid in RATE_CARD_STEPS else []), "from_steps": from_steps}
if sid in (REPORT_STEP, PACKAGE_STEP):
# Which agent versions produced the run, as built; for the package, a fixed Discovery artifact id too.
inputs["static"] = {"agent_versions": {f: field(ROOT / f / "agent.yaml", "version")
for _, f, _, _ in STEPS if f != folder},
**({"artifact_ids": list(artifact_ids)} if artifact_ids and sid == PACKAGE_STEP else {})}
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 == REVIEW_STEP:
hitl = {"enabled": True, "checkpoint_type": "approval",
"review_focus": "disposition_signoff: the Engagement Lead reads the Assessment report: the critic's "
"verdict and every disposition in the sign-off queue (confidence below 0.80, and "
"every repurchase or relocate). Continuing signs off that queue (ADR 0014) 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, PACKAGE_STEP: 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"})
# After the review point: the approved report as a page, as this run's own artifact (as Discovery's, F01 ADR 0012).
page = _activity_step(PAGE_STEP, "format_for_ui", "Format Assessment report for UI",
"The approved Assessment report, for display as a page.",
{"from_steps": {"input_data": f"{REPORT_STEP}.final_html"}, "static": {"format_type": "html"}},
{"type": "object", "properties": {"input_data": {"type": "string"}, "format_type": {"type": "string"}}},
{"type": "object", "properties": {"data": {"type": "object"}}}, y=-160)
page.update({"depends_on": [REPORT_STEP], "executionLevel": 8, "parallelGroup": 8,
"position": {"x": 320 * 7, "y": -160}})
steps.append(page)
connections.append({"source": REPORT_STEP, "target": PAGE_STEP})
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())