feat: 接通 Planner → Action → Validator
This commit is contained in:
@@ -18,6 +18,7 @@ class PlannerNode(BaseNode):
|
||||
updated_state: QueryState = state.copy()
|
||||
requirement = state["requirement"]
|
||||
scope = state["change_scope"]
|
||||
|
||||
if (
|
||||
requirement.needs_clarification
|
||||
or requirement.intent
|
||||
@@ -33,6 +34,7 @@ class PlannerNode(BaseNode):
|
||||
resources = state.get("component_resources")
|
||||
if resources is not None and resources.status != "resolved":
|
||||
raise ValueError("组件目录尚未就绪,不能继续规划")
|
||||
|
||||
result = await get_llm(ScreenPlan).ainvoke(
|
||||
[
|
||||
SystemMessage(content=PLANNER_SYSTEM_PROMPT),
|
||||
@@ -42,7 +44,7 @@ class PlannerNode(BaseNode):
|
||||
"input_context": context.model_dump(mode="json"),
|
||||
"requirement": requirement.model_dump(mode="json"),
|
||||
"change_scope": scope.model_dump(mode="json"),
|
||||
"component_resources": resources.model_dump(mode="json")
|
||||
"component_resources": resources.to_planner_context()
|
||||
if resources is not None
|
||||
else None,
|
||||
},
|
||||
@@ -51,7 +53,9 @@ class PlannerNode(BaseNode):
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
plan = ScreenPlan.model_validate(result.model_dump())
|
||||
|
||||
if resources is not None:
|
||||
supported_types = {component.type for component in resources.components}
|
||||
for component in plan.components:
|
||||
@@ -65,6 +69,7 @@ class PlannerNode(BaseNode):
|
||||
raise ValueError(
|
||||
f"规划使用了目录中不存在的组件类型: {component.component_type}"
|
||||
)
|
||||
|
||||
existing_ids = {node.id for node in context.screen.nodes}
|
||||
planned_ids = {
|
||||
component.target_id
|
||||
@@ -73,9 +78,11 @@ class PlannerNode(BaseNode):
|
||||
}
|
||||
if unknown := planned_ids - existing_ids:
|
||||
raise ValueError(f"规划引用了不存在的组件: {sorted(unknown)}")
|
||||
|
||||
required_ids = {
|
||||
target for change in requirement.changes for target in change.target_ids
|
||||
}
|
||||
|
||||
if missing := required_ids - planned_ids:
|
||||
raise ValueError(f"规划遗漏了需求中的组件: {sorted(missing)}")
|
||||
if scope.scope == "local":
|
||||
@@ -86,6 +93,7 @@ class PlannerNode(BaseNode):
|
||||
}
|
||||
if outside := changed_ids - set(scope.target_ids):
|
||||
raise ValueError(f"局部规划修改了范围外的组件: {sorted(outside)}")
|
||||
|
||||
# 原始约束和假设不能在规划阶段被无声丢弃
|
||||
plan.constraints = list(
|
||||
dict.fromkeys([*requirement.constraints, *plan.constraints])
|
||||
@@ -94,6 +102,7 @@ class PlannerNode(BaseNode):
|
||||
dict.fromkeys([*requirement.assumptions, *plan.assumptions])
|
||||
)
|
||||
updated_state["screen_plan"] = plan
|
||||
|
||||
return updated_state
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user