41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
"""统一收尾能力不足、资源缺失和动作修正失败"""
|
|
|
|
from app.processor.base import BaseNode
|
|
from app.processor.state import QueryState
|
|
|
|
|
|
class FallbackNode(BaseNode):
|
|
name = "fallback_node"
|
|
|
|
def process(self, state: QueryState) -> QueryState:
|
|
updated_state: QueryState = state.copy()
|
|
reason = state.get("failure_reason")
|
|
if not reason:
|
|
if state.get("validation_errors"):
|
|
reason = f"动作校验未通过,已达到自动修正上限,共重试 {state.get('retry_count', 0)} 次"
|
|
else:
|
|
reason = "当前需求未能完成,缺少具体失败原因"
|
|
|
|
# 失败动作仅保留作诊断,validation_passed=False 表示不可交付执行
|
|
updated_state["status"] = "failed"
|
|
updated_state["failure_reason"] = reason
|
|
updated_state["validation_passed"] = False
|
|
updated_state["simulated_screen"] = None
|
|
return updated_state
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from app.schemas.action_validation import ActionValidationError
|
|
|
|
state = {
|
|
"request": {},
|
|
"retry_count": 2,
|
|
"actions": None,
|
|
"validation_errors": [
|
|
ActionValidationError(code="generation_error", message="动作生成失败")
|
|
],
|
|
}
|
|
node = FallbackNode()
|
|
final_state = node.process(state)
|
|
print(final_state)
|