|
@@ -156,7 +156,10 @@ def _contract(
|
|
|
assert base_decision_id is not None
|
|
assert base_decision_id is not None
|
|
|
return {
|
|
return {
|
|
|
"task_kind": task_kind,
|
|
"task_kind": task_kind,
|
|
|
- "scope_ref": scope_ref,
|
|
|
|
|
|
|
+ "scope_selector": {
|
|
|
|
|
+ "anchor": "mission",
|
|
|
|
|
+ "path": scope_ref.removeprefix("script-build://scopes/").split("/")[:4],
|
|
|
|
|
+ },
|
|
|
"intent_class": (
|
|
"intent_class": (
|
|
|
"compose"
|
|
"compose"
|
|
|
if task_kind == "compose"
|
|
if task_kind == "compose"
|
|
@@ -167,19 +170,17 @@ def _contract(
|
|
|
"objective": objective or f"produce one concrete and independently verifiable {task_kind}",
|
|
"objective": objective or f"produce one concrete and independently verifiable {task_kind}",
|
|
|
"input_decision_ids": input_decision_ids,
|
|
"input_decision_ids": input_decision_ids,
|
|
|
"base_decision_id": base_decision_id,
|
|
"base_decision_id": base_decision_id,
|
|
|
- "gap_ref": None,
|
|
|
|
|
|
|
+ "gap_key": None,
|
|
|
"criteria": [
|
|
"criteria": [
|
|
|
{
|
|
{
|
|
|
- "criterion_id": f"{task_kind}-closed",
|
|
|
|
|
|
|
+ "client_key": f"{task_kind}-closed",
|
|
|
"description": "the immutable output is concrete and causally closed",
|
|
"description": "the immutable output is concrete and causally closed",
|
|
|
"hard": True,
|
|
"hard": True,
|
|
|
}
|
|
}
|
|
|
],
|
|
],
|
|
|
"goal_ids": list(goal_ids or ()),
|
|
"goal_ids": list(goal_ids or ()),
|
|
|
"supersedes_decision_ids": list(supersedes_decision_ids),
|
|
"supersedes_decision_ids": list(supersedes_decision_ids),
|
|
|
- "comparison_decision_ids": [
|
|
|
|
|
- str(item["decision_id"]) for item in comparison_decision_refs
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ "comparison_decision_ids": [str(item["decision_id"]) for item in comparison_decision_refs],
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -511,6 +512,35 @@ class _PhaseTwoScriptedLLM:
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ # Compose is now a deterministic Workbench Worker. A complete creative
|
|
|
|
|
+ # frontier produces one valid artifact instead of asking an LLM Worker
|
|
|
|
|
+ # to manufacture an invalid first candidate for this fixture.
|
|
|
|
|
+ if compose.status is TaskStatus.COMPLETED:
|
|
|
|
|
+ compose_decision, _compose_ref = _accepted_ref(ledger, compose)
|
|
|
|
|
+ if portfolio.current_spec_version == 1:
|
|
|
|
|
+ return self._call(
|
|
|
|
|
+ "decide_script_task",
|
|
|
|
|
+ {
|
|
|
|
|
+ "task_id": portfolio.task_id,
|
|
|
|
|
+ "action": "revise",
|
|
|
|
|
+ "reason": "pin the uniquely adopted StructuredScript",
|
|
|
|
|
+ "selected_decision_ids": [compose_decision],
|
|
|
|
|
+ },
|
|
|
|
|
+ )
|
|
|
|
|
+ if portfolio.status in {TaskStatus.PENDING, TaskStatus.NEEDS_REPLAN}:
|
|
|
|
|
+ return self._call("dispatch_script_tasks", {"task_ids": [portfolio.task_id]})
|
|
|
|
|
+ if portfolio.status is TaskStatus.AWAITING_DECISION:
|
|
|
|
|
+ return self._accept(portfolio, ledger)
|
|
|
|
|
+ assert portfolio.status is TaskStatus.COMPLETED
|
|
|
|
|
+ return self._call(
|
|
|
|
|
+ "decide_script_task",
|
|
|
|
|
+ {
|
|
|
|
|
+ "task_id": root.task_id,
|
|
|
|
|
+ "action": "block",
|
|
|
|
|
+ "reason": PHASE_TWO_CANDIDATE_PORTFOLIO_READY,
|
|
|
|
|
+ },
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
replacement = by_objective(replacement_objective)
|
|
replacement = by_objective(replacement_objective)
|
|
|
if replacement is None:
|
|
if replacement is None:
|
|
|
raise AssertionError("failed Compose must SPLIT one bounded replacement Task")
|
|
raise AssertionError("failed Compose must SPLIT one bounded replacement Task")
|
|
@@ -661,11 +691,8 @@ class _PhaseTwoScriptedLLM:
|
|
|
return self._call("submit_attempt", {})
|
|
return self._call("submit_attempt", {})
|
|
|
if kind == "direction":
|
|
if kind == "direction":
|
|
|
if not isinstance(last, dict) or "artifact_ref" not in last:
|
|
if not isinstance(last, dict) or "artifact_ref" not in last:
|
|
|
- accepted = cast(Sequence[Mapping[str, Any]], prompt["accepted_child_results"])
|
|
|
|
|
- evidence_refs = cast(
|
|
|
|
|
- Sequence[Mapping[str, Any]],
|
|
|
|
|
- cast(Mapping[str, Any], accepted[0]["submission"])["evidence_refs"],
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ role_context = cast(Mapping[str, Any], prompt["role_context"])
|
|
|
|
|
+ accepted = cast(Sequence[Mapping[str, Any]], role_context["accepted_inputs"])
|
|
|
return self._call(
|
|
return self._call(
|
|
|
"save_direction_candidate",
|
|
"save_direction_candidate",
|
|
|
{
|
|
{
|
|
@@ -681,22 +708,24 @@ class _PhaseTwoScriptedLLM:
|
|
|
],
|
|
],
|
|
|
"constraints": [
|
|
"constraints": [
|
|
|
{
|
|
{
|
|
|
- "constraint_id": "grounded-direction",
|
|
|
|
|
|
|
+ "client_key": "grounded-direction",
|
|
|
"statement": "the direction is concrete and testable",
|
|
"statement": "the direction is concrete and testable",
|
|
|
"rationale": "accepted evidence must remain traceable",
|
|
"rationale": "accepted evidence must remain traceable",
|
|
|
}
|
|
}
|
|
|
],
|
|
],
|
|
|
"preferences": [],
|
|
"preferences": [],
|
|
|
- "evidence_refs": [evidence_refs[0]["uri"]],
|
|
|
|
|
|
|
+ "strategy_handles": [],
|
|
|
|
|
+ "evidence_decision_ids": [accepted[0]["decision_id"]],
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
|
goal_map = cast(Mapping[str, str], last["goal_ids_by_client_key"])
|
|
goal_map = cast(Mapping[str, str], last["goal_ids_by_client_key"])
|
|
|
self.direction_goal_id = goal_map["observable-opening"]
|
|
self.direction_goal_id = goal_map["observable-opening"]
|
|
|
return self._call("submit_attempt", {})
|
|
return self._call("submit_attempt", {})
|
|
|
if kind == "structure":
|
|
if kind == "structure":
|
|
|
- if not isinstance(last, dict):
|
|
|
|
|
|
|
+ if not isinstance(last, dict) or last.get("status") != "saved":
|
|
|
|
|
+ role_context = cast(Mapping[str, Any], prompt["role_context"])
|
|
|
return self._call(
|
|
return self._call(
|
|
|
- "create_script_paragraphs",
|
|
|
|
|
|
|
+ "save_script_paragraphs",
|
|
|
{
|
|
{
|
|
|
"paragraphs": [
|
|
"paragraphs": [
|
|
|
{
|
|
{
|
|
@@ -707,6 +736,7 @@ class _PhaseTwoScriptedLLM:
|
|
|
"scope": "opening",
|
|
"scope": "opening",
|
|
|
"beats": ["setup", "reversal"],
|
|
"beats": ["setup", "reversal"],
|
|
|
},
|
|
},
|
|
|
|
|
+ "level": 1,
|
|
|
"theme_elements": [
|
|
"theme_elements": [
|
|
|
{
|
|
{
|
|
|
"原子点": "assumption changes after evidence",
|
|
"原子点": "assumption changes after evidence",
|
|
@@ -732,58 +762,76 @@ class _PhaseTwoScriptedLLM:
|
|
|
{"原子点": "measured surprise", "维度": "tone"}
|
|
{"原子点": "measured surprise", "维度": "tone"}
|
|
|
],
|
|
],
|
|
|
}
|
|
}
|
|
|
- ]
|
|
|
|
|
|
|
+ ],
|
|
|
|
|
+ "expected_state_revision": role_context["state_revision"],
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
|
return self._call("submit_attempt", {})
|
|
return self._call("submit_attempt", {})
|
|
|
if kind == "paragraph":
|
|
if kind == "paragraph":
|
|
|
- if isinstance(last, dict) and last.get("updated") == 1:
|
|
|
|
|
|
|
+ if isinstance(last, dict) and last.get("status") == "saved":
|
|
|
return self._call("submit_attempt", {})
|
|
return self._call("submit_attempt", {})
|
|
|
- if not isinstance(last, dict) or "paragraphs" not in last:
|
|
|
|
|
- return self._call("read_attempt_workspace", {})
|
|
|
|
|
- paragraphs = cast(Sequence[Mapping[str, Any]], last["paragraphs"])
|
|
|
|
|
- assert len(paragraphs) == 1
|
|
|
|
|
|
|
+ role_context = cast(Mapping[str, Any], prompt["role_context"])
|
|
|
|
|
+ paragraphs = cast(Sequence[Mapping[str, Any]], role_context["paragraph_targets"])
|
|
|
replacement = "replace the placeholder" in str(spec["objective"])
|
|
replacement = "replace the placeholder" in str(spec["objective"])
|
|
|
|
|
+ paragraph: dict[str, Any] = {
|
|
|
|
|
+ "theme": (
|
|
|
|
|
+ "The retrieved observable reversal changes the opening claim."
|
|
|
|
|
+ if replacement
|
|
|
|
|
+ else "A familiar expectation changes after a visible detail."
|
|
|
|
|
+ ),
|
|
|
|
|
+ "form": "A concrete setup followed by one concise reversal.",
|
|
|
|
|
+ "function": "Give the audience an immediate reason to continue.",
|
|
|
|
|
+ "feeling": "Measured surprise grounded in observation.",
|
|
|
|
|
+ "description": "The opening overturns one assumption with evidence.",
|
|
|
|
|
+ "full_description": (
|
|
|
|
|
+ "Use the accepted retrieval evidence to replace the unrealized opening and "
|
|
|
|
|
+ "show exactly how the observed detail changes the interpretation."
|
|
|
|
|
+ if replacement
|
|
|
|
|
+ else "Start from the familiar expectation, name the visible detail, and show "
|
|
|
|
|
+ "exactly how that detail changes the interpretation."
|
|
|
|
|
+ ),
|
|
|
|
|
+ }
|
|
|
|
|
+ if paragraphs:
|
|
|
|
|
+ paragraph["paragraph_target_key"] = paragraphs[0]["paragraph_target_key"]
|
|
|
|
|
+ else:
|
|
|
|
|
+ paragraph.update(
|
|
|
|
|
+ {
|
|
|
|
|
+ "client_key": "opening",
|
|
|
|
|
+ "paragraph_index": 1,
|
|
|
|
|
+ "name": "Opening",
|
|
|
|
|
+ "content_range": {"scope": "opening", "beats": ["setup", "reversal"]},
|
|
|
|
|
+ "level": 1,
|
|
|
|
|
+ "theme_elements": [
|
|
|
|
|
+ {"原子点": "visible reversal", "维度": "claim", "维度类型": "主维度"}
|
|
|
|
|
+ ],
|
|
|
|
|
+ "form_elements": [
|
|
|
|
|
+ {"原子点": "setup and reversal", "维度": "shape", "维度类型": "主维度"}
|
|
|
|
|
+ ],
|
|
|
|
|
+ "function_elements": [
|
|
|
|
|
+ {"原子点": "create curiosity", "维度": "job", "维度类型": "主维度"}
|
|
|
|
|
+ ],
|
|
|
|
|
+ "feeling_elements": [{"原子点": "measured surprise", "维度": "tone"}],
|
|
|
|
|
+ }
|
|
|
|
|
+ )
|
|
|
return self._call(
|
|
return self._call(
|
|
|
- "batch_update_script_paragraphs",
|
|
|
|
|
|
|
+ "save_script_paragraphs",
|
|
|
{
|
|
{
|
|
|
- "updates": [
|
|
|
|
|
- {
|
|
|
|
|
- "paragraph_id": paragraphs[0]["paragraph_id"],
|
|
|
|
|
- "theme": (
|
|
|
|
|
- "The retrieved observable reversal changes the opening claim."
|
|
|
|
|
- if replacement
|
|
|
|
|
- else "A familiar expectation changes after a visible detail."
|
|
|
|
|
- ),
|
|
|
|
|
- "form": "A concrete setup followed by one concise reversal.",
|
|
|
|
|
- "function": "Give the audience an immediate reason to continue.",
|
|
|
|
|
- "feeling": "Measured surprise grounded in observation.",
|
|
|
|
|
- "description": "The opening overturns one assumption with evidence.",
|
|
|
|
|
- "full_description": (
|
|
|
|
|
- "Use the accepted retrieval evidence to replace the unrealized "
|
|
|
|
|
- "opening and show exactly how the observed detail changes the "
|
|
|
|
|
- "interpretation."
|
|
|
|
|
- if replacement
|
|
|
|
|
- else "Start from the familiar expectation, name the visible "
|
|
|
|
|
- "detail, and show exactly how that detail changes the "
|
|
|
|
|
- "interpretation."
|
|
|
|
|
- ),
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ "paragraphs": [paragraph],
|
|
|
|
|
+ "expected_state_revision": role_context["state_revision"],
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
|
if kind == "element-set":
|
|
if kind == "element-set":
|
|
|
- if isinstance(last, dict) and last.get("linked") == 1:
|
|
|
|
|
|
|
+ if isinstance(last, dict) and last.get("created") == 1 and last.get("linked") == 1:
|
|
|
return self._call("submit_attempt", {})
|
|
return self._call("submit_attempt", {})
|
|
|
- if not isinstance(last, dict):
|
|
|
|
|
- return self._call("read_attempt_workspace", {})
|
|
|
|
|
- if "paragraphs" in last and "elements" in last:
|
|
|
|
|
- paragraphs = cast(Sequence[Mapping[str, Any]], last["paragraphs"])
|
|
|
|
|
- elements = cast(Sequence[Mapping[str, Any]], last["elements"])
|
|
|
|
|
- if not elements:
|
|
|
|
|
- return self._call(
|
|
|
|
|
- "create_script_element",
|
|
|
|
|
|
|
+ role_context = cast(Mapping[str, Any], prompt["role_context"])
|
|
|
|
|
+ paragraphs = cast(Sequence[Mapping[str, Any]], role_context["paragraph_targets"])
|
|
|
|
|
+ assert len(paragraphs) == 1
|
|
|
|
|
+ return self._call(
|
|
|
|
|
+ "save_script_elements",
|
|
|
|
|
+ {
|
|
|
|
|
+ "elements": [
|
|
|
{
|
|
{
|
|
|
|
|
+ "client_key": "reversal",
|
|
|
"name": "Observable reversal",
|
|
"name": "Observable reversal",
|
|
|
"dimension_primary": "实质",
|
|
"dimension_primary": "实质",
|
|
|
"dimension_secondary": "opening-evidence",
|
|
"dimension_secondary": "opening-evidence",
|
|
@@ -792,35 +840,23 @@ class _PhaseTwoScriptedLLM:
|
|
|
},
|
|
},
|
|
|
"topic_support": {"strength": "high"},
|
|
"topic_support": {"strength": "high"},
|
|
|
"weight_score": {"value": 0.9},
|
|
"weight_score": {"value": 0.9},
|
|
|
- "support_elements": [
|
|
|
|
|
- {"ref": "decode-index://fixture/opening-reversal"}
|
|
|
|
|
- ],
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- assert len(paragraphs) == 1 and len(elements) == 1
|
|
|
|
|
- return self._call(
|
|
|
|
|
- "batch_link_paragraph_elements",
|
|
|
|
|
- {
|
|
|
|
|
- "links": [
|
|
|
|
|
- {
|
|
|
|
|
- "paragraph_id": paragraphs[0]["paragraph_id"],
|
|
|
|
|
- "element_ids": [elements[0]["element_id"]],
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- if "element_id" in last:
|
|
|
|
|
- return self._call("read_attempt_workspace", {})
|
|
|
|
|
|
|
+ "support_elements": [{"source_handle": "accepted-opening"}],
|
|
|
|
|
+ }
|
|
|
|
|
+ ],
|
|
|
|
|
+ "links": [
|
|
|
|
|
+ {
|
|
|
|
|
+ "paragraph_target_key": paragraphs[0]["paragraph_target_key"],
|
|
|
|
|
+ "element_client_keys": ["reversal"],
|
|
|
|
|
+ }
|
|
|
|
|
+ ],
|
|
|
|
|
+ "expected_state_revision": role_context["state_revision"],
|
|
|
|
|
+ },
|
|
|
|
|
+ )
|
|
|
if kind == "compare":
|
|
if kind == "compare":
|
|
|
if isinstance(last, dict) and "artifact_ref" in last:
|
|
if isinstance(last, dict) and "artifact_ref" in last:
|
|
|
return self._call("submit_attempt", {})
|
|
return self._call("submit_attempt", {})
|
|
|
- if not isinstance(last, list):
|
|
|
|
|
- return self._call("read_pinned_candidates", {})
|
|
|
|
|
- candidates = [
|
|
|
|
|
- str(item["artifact_ref"]["uri"])
|
|
|
|
|
- for item in last
|
|
|
|
|
- if item["task_kind"] == "paragraph"
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ role_context = cast(Mapping[str, Any], prompt["role_context"])
|
|
|
|
|
+ candidates = list(role_context["task"]["comparison_decision_ids"])
|
|
|
assert len(candidates) == 2
|
|
assert len(candidates) == 2
|
|
|
return self._call(
|
|
return self._call(
|
|
|
"save_comparison_candidate",
|
|
"save_comparison_candidate",
|
|
@@ -830,7 +866,7 @@ class _PhaseTwoScriptedLLM:
|
|
|
"criterion_id": "compare-closed",
|
|
"criterion_id": "compare-closed",
|
|
|
"candidate_results": [
|
|
"candidate_results": [
|
|
|
{
|
|
{
|
|
|
- "artifact_ref": candidate,
|
|
|
|
|
|
|
+ "decision_id": candidate,
|
|
|
"reason": "reviewed against the same frozen criterion",
|
|
"reason": "reviewed against the same frozen criterion",
|
|
|
}
|
|
}
|
|
|
for candidate in candidates
|
|
for candidate in candidates
|
|
@@ -840,38 +876,11 @@ class _PhaseTwoScriptedLLM:
|
|
|
"conflicts": [
|
|
"conflicts": [
|
|
|
"candidate B realizes the retrieved evidence while candidate A does not"
|
|
"candidate B realizes the retrieved evidence while candidate A does not"
|
|
|
],
|
|
],
|
|
|
- "recommendation": candidates[-1],
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- if kind == "compose":
|
|
|
|
|
- if isinstance(last, dict) and "artifact_ref" in last:
|
|
|
|
|
- return self._call("submit_attempt", {})
|
|
|
|
|
- if not isinstance(last, dict) or last.get("schema_version") != "active-frontier/v1":
|
|
|
|
|
- return self._call("read_active_frontier", {})
|
|
|
|
|
- self.compose_candidates_saved += 1
|
|
|
|
|
- return self._call(
|
|
|
|
|
- "save_structured_script_candidate",
|
|
|
|
|
- {
|
|
|
|
|
- "acceptance_notes": [
|
|
|
|
|
- "TODO replace this placeholder opening with retrieved evidence."
|
|
|
|
|
- if self.compose_candidates_saved == 1
|
|
|
|
|
- else "The adopted replacement is concrete and fully rendered."
|
|
|
|
|
- ]
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- if kind == "candidate-portfolio":
|
|
|
|
|
- if isinstance(last, dict) and "artifact_ref" in last:
|
|
|
|
|
- return self._call("submit_attempt", {})
|
|
|
|
|
- if not isinstance(last, list):
|
|
|
|
|
- return self._call("read_pinned_candidates", {})
|
|
|
|
|
- assert sorted(item["task_kind"] for item in last) == ["compose", "direction"]
|
|
|
|
|
- return self._call(
|
|
|
|
|
- "save_candidate_portfolio",
|
|
|
|
|
- {
|
|
|
|
|
- "superseded_decision_ids": [],
|
|
|
|
|
- "unresolved_defects": [],
|
|
|
|
|
|
|
+ "recommended_decision_id": candidates[-1],
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
|
|
|
+ if kind in {"compose", "candidate-portfolio"}:
|
|
|
|
|
+ raise AssertionError(f"{kind} must be executed by DeterministicWorker")
|
|
|
raise AssertionError(f"unexpected Worker kind {kind}; tools={sorted(names)}")
|
|
raise AssertionError(f"unexpected Worker kind {kind}; tools={sorted(names)}")
|
|
|
|
|
|
|
|
def _validator(self, messages) -> dict[str, Any]:
|
|
def _validator(self, messages) -> dict[str, Any]:
|
|
@@ -885,11 +894,10 @@ class _PhaseTwoScriptedLLM:
|
|
|
if not isinstance(last, dict) or "rule_results" not in last:
|
|
if not isinstance(last, dict) or "rule_results" not in last:
|
|
|
return self._call("deterministic_precheck", {})
|
|
return self._call("deterministic_precheck", {})
|
|
|
criteria = cast(Sequence[Mapping[str, Any]], spec["acceptance_criteria"])
|
|
criteria = cast(Sequence[Mapping[str, Any]], spec["acceptance_criteria"])
|
|
|
|
|
+ role_context = cast(Mapping[str, Any], prompt["role_context"])
|
|
|
|
|
+ evidence_handle = role_context["evidence_handles"][0]["evidence_handle"]
|
|
|
failed_rules = [item for item in last["rule_results"] if item["verdict"] != "passed"]
|
|
failed_rules = [item for item in last["rule_results"] if item["verdict"] != "passed"]
|
|
|
if failed_rules:
|
|
if failed_rules:
|
|
|
- artifact_snapshot = cast(Mapping[str, Any], prompt["artifact_snapshot"])
|
|
|
|
|
- refs = cast(Sequence[Mapping[str, Any]], artifact_snapshot["artifact_refs"])
|
|
|
|
|
- assert len(refs) == 1
|
|
|
|
|
return self._call(
|
|
return self._call(
|
|
|
"submit_validation",
|
|
"submit_validation",
|
|
|
{
|
|
{
|
|
@@ -906,11 +914,14 @@ class _PhaseTwoScriptedLLM:
|
|
|
{
|
|
{
|
|
|
"defect_code": "REALIZATION_PLACEHOLDER",
|
|
"defect_code": "REALIZATION_PLACEHOLDER",
|
|
|
"criterion_id": criteria[0]["criterion_id"],
|
|
"criterion_id": criteria[0]["criterion_id"],
|
|
|
- "scope_ref": "script-build://scopes/full/opening",
|
|
|
|
|
|
|
+ "scope_selector": {
|
|
|
|
|
+ "anchor": "mission",
|
|
|
|
|
+ "path": ["full", "opening"],
|
|
|
|
|
+ },
|
|
|
"observed_excerpt": (
|
|
"observed_excerpt": (
|
|
|
"TODO replace this placeholder opening with retrieved evidence."
|
|
"TODO replace this placeholder opening with retrieved evidence."
|
|
|
),
|
|
),
|
|
|
- "evidence_refs": [dict(refs[0])],
|
|
|
|
|
|
|
+ "evidence_handle_ids": [evidence_handle],
|
|
|
"severity": "hard",
|
|
"severity": "hard",
|
|
|
"invalidated_inputs": [],
|
|
"invalidated_inputs": [],
|
|
|
"recommended_action_class": "split",
|
|
"recommended_action_class": "split",
|
|
@@ -920,12 +931,6 @@ class _PhaseTwoScriptedLLM:
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
|
assert all(item["verdict"] == "passed" for item in last["rule_results"])
|
|
assert all(item["verdict"] == "passed" for item in last["rule_results"])
|
|
|
- artifact_snapshot = cast(Mapping[str, Any], prompt["artifact_snapshot"])
|
|
|
|
|
- evidence_refs = [
|
|
|
|
|
- *cast(Sequence[Mapping[str, Any]], artifact_snapshot["artifact_refs"]),
|
|
|
|
|
- *cast(Sequence[Mapping[str, Any]], artifact_snapshot["evidence_refs"]),
|
|
|
|
|
- ]
|
|
|
|
|
- assert evidence_refs
|
|
|
|
|
return self._call(
|
|
return self._call(
|
|
|
"submit_validation",
|
|
"submit_validation",
|
|
|
{
|
|
{
|
|
@@ -935,7 +940,7 @@ class _PhaseTwoScriptedLLM:
|
|
|
"criterion_id": item["criterion_id"],
|
|
"criterion_id": item["criterion_id"],
|
|
|
"verdict": "passed",
|
|
"verdict": "passed",
|
|
|
"reason": "the immutable artifact passed deterministic and semantic review",
|
|
"reason": "the immutable artifact passed deterministic and semantic review",
|
|
|
- "evidence_refs": [dict(evidence_refs[0])],
|
|
|
|
|
|
|
+ "evidence_handle_ids": [evidence_handle],
|
|
|
}
|
|
}
|
|
|
for item in criteria
|
|
for item in criteria
|
|
|
],
|
|
],
|
|
@@ -989,9 +994,7 @@ class _PhaseThreeScriptedLLM(_PhaseTwoScriptedLLM):
|
|
|
"save_root_delivery_manifest",
|
|
"save_root_delivery_manifest",
|
|
|
{"build_summary": "final summary", "blocking_defects": []},
|
|
{"build_summary": "final summary", "blocking_defects": []},
|
|
|
)
|
|
)
|
|
|
- if isinstance(last, dict) and "direction_ref" in last:
|
|
|
|
|
- return self._call("legacy_projection_dry_run", {"build_summary": "final summary"})
|
|
|
|
|
- return self._call("read_accepted_portfolio", {})
|
|
|
|
|
|
|
+ return self._call("legacy_projection_dry_run", {"build_summary": "final summary"})
|
|
|
|
|
|
|
|
|
|
|
|
|
class _OrderedExplorationScriptedLLM(_PhaseTwoScriptedLLM):
|
|
class _OrderedExplorationScriptedLLM(_PhaseTwoScriptedLLM):
|
|
@@ -1267,119 +1270,6 @@ class _OrderedExplorationScriptedLLM(_PhaseTwoScriptedLLM):
|
|
|
},
|
|
},
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
- def _worker(self, messages, names: set[str]) -> dict[str, Any]:
|
|
|
|
|
- prompt = _role_prompt(messages)
|
|
|
|
|
- spec = cast(Mapping[str, Any], prompt["task_spec"])
|
|
|
|
|
- refs = cast(Sequence[str], spec["context_refs"])
|
|
|
|
|
- kind = next(item.rsplit("/", 1)[-1] for item in refs if "/task-kinds/" in item)
|
|
|
|
|
- last = _last_tool_value(messages)
|
|
|
|
|
- if kind == "paragraph":
|
|
|
|
|
- assert "create_script_paragraph" not in names
|
|
|
|
|
- assert "create_script_paragraphs" in names
|
|
|
|
|
- assert "create_script_element" not in names
|
|
|
|
|
- if kind not in self.worker_kinds:
|
|
|
|
|
- self.worker_kinds.append(kind)
|
|
|
|
|
- if isinstance(last, dict) and last.get("updated") == 1:
|
|
|
|
|
- return self._call("submit_attempt", {})
|
|
|
|
|
- if not isinstance(last, dict) or "paragraphs" not in last:
|
|
|
|
|
- return self._call("read_attempt_workspace", {})
|
|
|
|
|
- paragraphs = cast(Sequence[Mapping[str, Any]], last["paragraphs"])
|
|
|
|
|
- if not paragraphs:
|
|
|
|
|
- return self._call(
|
|
|
|
|
- "create_script_paragraphs",
|
|
|
|
|
- {
|
|
|
|
|
- "paragraphs": [
|
|
|
|
|
- {
|
|
|
|
|
- "client_key": "opening",
|
|
|
|
|
- "paragraph_index": 1,
|
|
|
|
|
- "name": "Exploratory opening",
|
|
|
|
|
- "content_range": {
|
|
|
|
|
- "scope": "opening",
|
|
|
|
|
- "beats": ["setup", "reversal"],
|
|
|
|
|
- },
|
|
|
|
|
- "theme_elements": [
|
|
|
|
|
- {"原子点": "visible reversal", "维度": "claim"}
|
|
|
|
|
- ],
|
|
|
|
|
- "form_elements": [
|
|
|
|
|
- {"原子点": "setup and reversal", "维度": "shape"}
|
|
|
|
|
- ],
|
|
|
|
|
- "function_elements": [
|
|
|
|
|
- {"原子点": "create curiosity", "维度": "job"}
|
|
|
|
|
- ],
|
|
|
|
|
- "feeling_elements": [
|
|
|
|
|
- {"原子点": "measured surprise", "维度": "tone"}
|
|
|
|
|
- ],
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- return self._call(
|
|
|
|
|
- "batch_update_script_paragraphs",
|
|
|
|
|
- {
|
|
|
|
|
- "updates": [
|
|
|
|
|
- {
|
|
|
|
|
- "paragraph_id": paragraphs[0]["paragraph_id"],
|
|
|
|
|
- "theme": "One visible detail overturns the familiar assumption.",
|
|
|
|
|
- "form": "Concrete setup followed by a concise reversal.",
|
|
|
|
|
- "function": "Give the audience a grounded reason to continue.",
|
|
|
|
|
- "feeling": "Measured surprise.",
|
|
|
|
|
- "description": "A complete opening increment.",
|
|
|
|
|
- "full_description": (
|
|
|
|
|
- "The opening names the visible detail and explains exactly how "
|
|
|
|
|
- "it changes the audience's initial interpretation."
|
|
|
|
|
- ),
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- if kind == "element-set":
|
|
|
|
|
- assert "create_script_element" in names
|
|
|
|
|
- assert "batch_link_paragraph_elements" in names
|
|
|
|
|
- assert "create_script_paragraph" not in names
|
|
|
|
|
- if kind not in self.worker_kinds:
|
|
|
|
|
- self.worker_kinds.append(kind)
|
|
|
|
|
- if isinstance(last, dict) and "artifact_ref" in last:
|
|
|
|
|
- return self._call("submit_attempt", {})
|
|
|
|
|
- if isinstance(last, dict) and last.get("linked") == 1:
|
|
|
|
|
- return self._call("submit_attempt", {})
|
|
|
|
|
- if not isinstance(last, dict):
|
|
|
|
|
- return self._call(
|
|
|
|
|
- "create_script_element",
|
|
|
|
|
- {
|
|
|
|
|
- "name": "Observable reversal",
|
|
|
|
|
- "dimension_primary": "实质",
|
|
|
|
|
- "dimension_secondary": "opening evidence",
|
|
|
|
|
- "commonality_analysis": {"summary": "visible detail changes belief"},
|
|
|
|
|
- "topic_support": {"strength": "high"},
|
|
|
|
|
- "weight_score": {"value": 0.9},
|
|
|
|
|
- "support_elements": [{"ref": "decode-index://fixture/opening-reversal"}],
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- if "element_id" in last:
|
|
|
|
|
- return self._call("read_attempt_workspace", {})
|
|
|
|
|
- if "paragraphs" in last and "elements" in last:
|
|
|
|
|
- paragraphs = cast(Sequence[Mapping[str, Any]], last["paragraphs"])
|
|
|
|
|
- elements = cast(Sequence[Mapping[str, Any]], last["elements"])
|
|
|
|
|
- assert len(elements) == 1
|
|
|
|
|
- if not paragraphs:
|
|
|
|
|
- return self._call("submit_attempt", {})
|
|
|
|
|
- return self._call(
|
|
|
|
|
- "batch_link_paragraph_elements",
|
|
|
|
|
- {
|
|
|
|
|
- "links": [
|
|
|
|
|
- {
|
|
|
|
|
- "paragraph_id": paragraphs[0]["paragraph_id"],
|
|
|
|
|
- "element_ids": [elements[0]["element_id"]],
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
- },
|
|
|
|
|
- )
|
|
|
|
|
- if kind == "structure":
|
|
|
|
|
- assert "create_script_paragraph" not in names
|
|
|
|
|
- assert "create_script_paragraphs" in names
|
|
|
|
|
- assert "create_script_element" not in names
|
|
|
|
|
- return super()._worker(messages, names)
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
class _PrincipalProvider:
|
|
class _PrincipalProvider:
|
|
|
async def current(self, request_context: Any = None) -> Principal:
|
|
async def current(self, request_context: Any = None) -> Principal:
|
|
@@ -1593,7 +1483,11 @@ async def test_real_runner_creative_exploration_order_does_not_choose_adoption_o
|
|
|
assert attempt.worker_preset == expected_presets[kind]
|
|
assert attempt.worker_preset == expected_presets[kind]
|
|
|
worker_trace = await reopened_traces.get_trace(attempt.worker_trace_id)
|
|
worker_trace = await reopened_traces.get_trace(attempt.worker_trace_id)
|
|
|
assert worker_trace is not None and worker_trace.status == "completed"
|
|
assert worker_trace is not None and worker_trace.status == "completed"
|
|
|
- assert await reopened_traces.get_trace_messages(attempt.worker_trace_id)
|
|
|
|
|
|
|
+ messages = await reopened_traces.get_trace_messages(attempt.worker_trace_id)
|
|
|
|
|
+ if worker_trace.context.get("deterministic_worker"):
|
|
|
|
|
+ assert messages == []
|
|
|
|
|
+ else:
|
|
|
|
|
+ assert messages
|
|
|
validation = next(
|
|
validation = next(
|
|
|
ledger.validations[item]
|
|
ledger.validations[item]
|
|
|
for item in task.validation_ids
|
|
for item in task.validation_ids
|
|
@@ -1746,9 +1640,6 @@ async def test_mission_service_real_runner_auto_continues_phase_one_to_phase_two
|
|
|
"structure",
|
|
"structure",
|
|
|
"paragraph",
|
|
"paragraph",
|
|
|
"element-set",
|
|
"element-set",
|
|
|
- "compose",
|
|
|
|
|
- "compare",
|
|
|
|
|
- "candidate-portfolio",
|
|
|
|
|
]
|
|
]
|
|
|
assert llm.validator_kinds == [
|
|
assert llm.validator_kinds == [
|
|
|
"decode-retrieval",
|
|
"decode-retrieval",
|
|
@@ -1756,13 +1647,12 @@ async def test_mission_service_real_runner_auto_continues_phase_one_to_phase_two
|
|
|
"structure",
|
|
"structure",
|
|
|
"paragraph",
|
|
"paragraph",
|
|
|
"element-set",
|
|
"element-set",
|
|
|
- "compare",
|
|
|
|
|
"compose",
|
|
"compose",
|
|
|
"candidate-portfolio",
|
|
"candidate-portfolio",
|
|
|
]
|
|
]
|
|
|
assert llm.submit_attempt_arguments
|
|
assert llm.submit_attempt_arguments
|
|
|
assert all(not item for item in llm.submit_attempt_arguments)
|
|
assert all(not item for item in llm.submit_attempt_arguments)
|
|
|
- assert llm.compose_candidates_saved == 2
|
|
|
|
|
|
|
+ assert llm.compose_candidates_saved == 0
|
|
|
assert llm.tool_calls_by_name.get("create_script_paragraph", 0) == 0
|
|
assert llm.tool_calls_by_name.get("create_script_paragraph", 0) == 0
|
|
|
|
|
|
|
|
compose_task = next(
|
|
compose_task = next(
|
|
@@ -1770,15 +1660,12 @@ async def test_mission_service_real_runner_auto_continues_phase_one_to_phase_two
|
|
|
for task in ledger.tasks.values()
|
|
for task in ledger.tasks.values()
|
|
|
if task.task_id != ledger.root_task_id and _task_kind(task) == "compose"
|
|
if task.task_id != ledger.root_task_id and _task_kind(task) == "compose"
|
|
|
)
|
|
)
|
|
|
- assert compose_task.current_spec_version == 3
|
|
|
|
|
- assert len(compose_task.attempt_ids) == 2
|
|
|
|
|
|
|
+ assert compose_task.current_spec_version == 2
|
|
|
|
|
+ assert len(compose_task.attempt_ids) == 1
|
|
|
assert [ledger.validations[item].verdict for item in compose_task.validation_ids] == [
|
|
assert [ledger.validations[item].verdict for item in compose_task.validation_ids] == [
|
|
|
- ValidationVerdict.FAILED,
|
|
|
|
|
ValidationVerdict.PASSED,
|
|
ValidationVerdict.PASSED,
|
|
|
]
|
|
]
|
|
|
assert [ledger.decisions[item].action for item in compose_task.decision_ids] == [
|
|
assert [ledger.decisions[item].action for item in compose_task.decision_ids] == [
|
|
|
- DecisionAction.REVISE,
|
|
|
|
|
- DecisionAction.SPLIT,
|
|
|
|
|
DecisionAction.REVISE,
|
|
DecisionAction.REVISE,
|
|
|
DecisionAction.ACCEPT,
|
|
DecisionAction.ACCEPT,
|
|
|
]
|
|
]
|
|
@@ -1788,21 +1675,7 @@ async def test_mission_service_real_runner_auto_continues_phase_one_to_phase_two
|
|
|
for task in ledger.tasks.values()
|
|
for task in ledger.tasks.values()
|
|
|
if task.task_id != ledger.root_task_id and _task_kind(task) == "paragraph"
|
|
if task.task_id != ledger.root_task_id and _task_kind(task) == "paragraph"
|
|
|
]
|
|
]
|
|
|
- assert len(paragraph_tasks) == 2
|
|
|
|
|
- replacement = next(
|
|
|
|
|
- task for task in paragraph_tasks if "replace the placeholder" in task.current_spec.objective
|
|
|
|
|
- )
|
|
|
|
|
- phase_two_retrieval = next(
|
|
|
|
|
- task
|
|
|
|
|
- for task in ledger.tasks.values()
|
|
|
|
|
- if task.task_id != ledger.root_task_id
|
|
|
|
|
- and _task_kind(task) == "decode-retrieval"
|
|
|
|
|
- and task.parent_task_id == replacement.task_id
|
|
|
|
|
- )
|
|
|
|
|
- replacement_attempt = ledger.attempts[replacement.attempt_ids[-1]]
|
|
|
|
|
- assert replacement_attempt.accepted_child_decision_ids == (
|
|
|
|
|
- phase_two_retrieval.decision_ids[-1],
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ assert len(paragraph_tasks) == 1
|
|
|
assert (
|
|
assert (
|
|
|
len(
|
|
len(
|
|
|
[
|
|
[
|
|
@@ -1811,7 +1684,7 @@ async def test_mission_service_real_runner_auto_continues_phase_one_to_phase_two
|
|
|
if task.task_id != ledger.root_task_id and _task_kind(task) == "compare"
|
|
if task.task_id != ledger.root_task_id and _task_kind(task) == "compare"
|
|
|
]
|
|
]
|
|
|
)
|
|
)
|
|
|
- == 1
|
|
|
|
|
|
|
+ == 0
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
expected_identities = {
|
|
expected_identities = {
|
|
@@ -1820,6 +1693,13 @@ async def test_mission_service_real_runner_auto_continues_phase_one_to_phase_two
|
|
|
for attempt in ledger.attempts.values():
|
|
for attempt in ledger.attempts.values():
|
|
|
worker_trace = await trace_store.get_trace(attempt.worker_trace_id)
|
|
worker_trace = await trace_store.get_trace(attempt.worker_trace_id)
|
|
|
assert worker_trace is not None
|
|
assert worker_trace is not None
|
|
|
|
|
+ if worker_trace.context.get("deterministic_worker"):
|
|
|
|
|
+ assert worker_trace.total_tokens == 0
|
|
|
|
|
+ assert attempt.worker_preset in {
|
|
|
|
|
+ "script_compose_worker",
|
|
|
|
|
+ "script_candidate_portfolio_worker",
|
|
|
|
|
+ }
|
|
|
|
|
+ continue
|
|
|
assert (
|
|
assert (
|
|
|
worker_trace.context["role_prompt_identity"]
|
|
worker_trace.context["role_prompt_identity"]
|
|
|
== expected_identities[attempt.worker_preset]
|
|
== expected_identities[attempt.worker_preset]
|
|
@@ -1883,7 +1763,11 @@ async def test_mission_service_real_runner_auto_continues_phase_one_to_phase_two
|
|
|
for attempt in phase_two_attempts:
|
|
for attempt in phase_two_attempts:
|
|
|
worker_trace = await reopened_traces.get_trace(attempt.worker_trace_id)
|
|
worker_trace = await reopened_traces.get_trace(attempt.worker_trace_id)
|
|
|
assert worker_trace is not None and worker_trace.status == "completed"
|
|
assert worker_trace is not None and worker_trace.status == "completed"
|
|
|
- assert await reopened_traces.get_trace_messages(attempt.worker_trace_id)
|
|
|
|
|
|
|
+ messages = await reopened_traces.get_trace_messages(attempt.worker_trace_id)
|
|
|
|
|
+ if worker_trace.context.get("deterministic_worker"):
|
|
|
|
|
+ assert messages == []
|
|
|
|
|
+ else:
|
|
|
|
|
+ assert messages
|
|
|
validation = next(
|
|
validation = next(
|
|
|
ledger.validations[item]
|
|
ledger.validations[item]
|
|
|
for item in ledger.tasks[attempt.task_id].validation_ids
|
|
for item in ledger.tasks[attempt.task_id].validation_ids
|
|
@@ -1928,7 +1812,6 @@ async def test_mission_service_real_runner_auto_continues_phase_one_to_phase_two
|
|
|
assert {
|
|
assert {
|
|
|
ArtifactKind.DIRECTION.value,
|
|
ArtifactKind.DIRECTION.value,
|
|
|
ArtifactKind.PARAGRAPH.value,
|
|
ArtifactKind.PARAGRAPH.value,
|
|
|
- ArtifactKind.COMPARISON.value,
|
|
|
|
|
ArtifactKind.STRUCTURED_SCRIPT.value,
|
|
ArtifactKind.STRUCTURED_SCRIPT.value,
|
|
|
ArtifactKind.CANDIDATE_PORTFOLIO.value,
|
|
ArtifactKind.CANDIDATE_PORTFOLIO.value,
|
|
|
} <= kinds
|
|
} <= kinds
|