111 lines
4.5 KiB
Python
111 lines
4.5 KiB
Python
from __future__ import annotations
|
|
|
|
from graph.spec import ExecutionGraphSpec, GraphEdgeSpec, GraphNodeSpec
|
|
|
|
|
|
def story_authoring_graph_v1() -> ExecutionGraphSpec:
|
|
node_ids = [
|
|
"build_context",
|
|
"plan_chapter",
|
|
"approve_plan",
|
|
"draft_chapter",
|
|
"extract_continuity",
|
|
"review_chapter",
|
|
"judge_chapter",
|
|
"revise_chapter",
|
|
"approve_chapter",
|
|
"commit_chapter",
|
|
"publish_story",
|
|
"complete",
|
|
"reject",
|
|
]
|
|
nodes = {
|
|
node_id: GraphNodeSpec(
|
|
node_id,
|
|
f"story_{node_id}",
|
|
{"checkpointed": True, "human_gate": node_id.startswith("approve_")},
|
|
)
|
|
for node_id in node_ids
|
|
}
|
|
edges = [
|
|
GraphEdgeSpec("build_context", "plan_chapter", "success"),
|
|
GraphEdgeSpec("plan_chapter", "approve_plan", "success"),
|
|
GraphEdgeSpec("approve_plan", "draft_chapter", "approve"),
|
|
GraphEdgeSpec("approve_plan", "plan_chapter", "request_revision"),
|
|
GraphEdgeSpec("approve_plan", "reject", "reject"),
|
|
GraphEdgeSpec("draft_chapter", "extract_continuity", "success"),
|
|
GraphEdgeSpec("extract_continuity", "review_chapter", "fan_out"),
|
|
GraphEdgeSpec("review_chapter", "judge_chapter", "success"),
|
|
GraphEdgeSpec("judge_chapter", "revise_chapter", "revise"),
|
|
GraphEdgeSpec("judge_chapter", "approve_chapter", "human_review"),
|
|
GraphEdgeSpec("revise_chapter", "extract_continuity", "success"),
|
|
GraphEdgeSpec("approve_chapter", "commit_chapter", "approve"),
|
|
GraphEdgeSpec("approve_chapter", "revise_chapter", "request_revision"),
|
|
GraphEdgeSpec("approve_chapter", "reject", "reject"),
|
|
GraphEdgeSpec("commit_chapter", "publish_story", "success"),
|
|
GraphEdgeSpec("publish_story", "complete", "success"),
|
|
]
|
|
spec = ExecutionGraphSpec(
|
|
name="story_authoring",
|
|
version=1,
|
|
graph_type="STORY_AUTHORING",
|
|
entry="build_context",
|
|
nodes=nodes,
|
|
edges=edges,
|
|
terminal_nodes=["complete", "reject"],
|
|
metadata={
|
|
"description": "Checkpoint-native story plan, draft, parallel review, approval, and publish workflow."
|
|
},
|
|
)
|
|
spec.validate()
|
|
return spec
|
|
|
|
|
|
def story_authoring_graph_v2() -> ExecutionGraphSpec:
|
|
node_ids = [
|
|
"build_context", "plan_chapter", "approve_plan", "draft_chapter",
|
|
"extract_continuity", "review_draft", "decide_patch", "apply_patch",
|
|
"extract_patched_continuity", "verify_patch", "approve_chapter",
|
|
"commit_chapter", "publish_story", "complete", "manual_revision", "reject",
|
|
]
|
|
nodes = {
|
|
node_id: GraphNodeSpec(
|
|
node_id,
|
|
f"story_{node_id}",
|
|
{"checkpointed": True, "human_gate": node_id.startswith("approve_")},
|
|
)
|
|
for node_id in node_ids
|
|
}
|
|
edges = [
|
|
GraphEdgeSpec("build_context", "plan_chapter", "success"),
|
|
GraphEdgeSpec("plan_chapter", "approve_plan", "success"),
|
|
GraphEdgeSpec("approve_plan", "draft_chapter", "approve"),
|
|
GraphEdgeSpec("approve_plan", "plan_chapter", "request_revision"),
|
|
GraphEdgeSpec("approve_plan", "reject", "reject"),
|
|
GraphEdgeSpec("draft_chapter", "extract_continuity", "success"),
|
|
GraphEdgeSpec("extract_continuity", "review_draft", "success"),
|
|
GraphEdgeSpec("review_draft", "decide_patch", "success"),
|
|
GraphEdgeSpec("decide_patch", "apply_patch", "patch"),
|
|
GraphEdgeSpec("decide_patch", "approve_chapter", "human_review"),
|
|
GraphEdgeSpec("apply_patch", "extract_patched_continuity", "applied"),
|
|
GraphEdgeSpec("apply_patch", "approve_chapter", "failed"),
|
|
GraphEdgeSpec("extract_patched_continuity", "verify_patch", "success"),
|
|
GraphEdgeSpec("verify_patch", "approve_chapter", "success"),
|
|
GraphEdgeSpec("approve_chapter", "commit_chapter", "approve"),
|
|
GraphEdgeSpec("approve_chapter", "manual_revision", "request_revision"),
|
|
GraphEdgeSpec("approve_chapter", "reject", "reject"),
|
|
GraphEdgeSpec("commit_chapter", "publish_story", "success"),
|
|
GraphEdgeSpec("publish_story", "complete", "success"),
|
|
]
|
|
spec = ExecutionGraphSpec(
|
|
name="story_authoring",
|
|
version=2,
|
|
graph_type="STORY_AUTHORING",
|
|
entry="build_context",
|
|
nodes=nodes,
|
|
edges=edges,
|
|
terminal_nodes=["complete", "manual_revision", "reject"],
|
|
metadata={"description": "Bounded one-draft, one-review, one-patch story workflow."},
|
|
)
|
|
spec.validate()
|
|
return spec
|