refactor(workflow): simplify edge configuration
This commit is contained in:
@@ -785,22 +785,9 @@ class WorkflowBrain(BaseBrain):
|
||||
triggering_user_message: dict[str, Any] | None = None,
|
||||
) -> NodeConfig:
|
||||
await self._begin_edge_transition(edge)
|
||||
context_messages = list(leading_messages or [])
|
||||
speech = self._engine.edge_transition_speech(edge)
|
||||
if speech:
|
||||
content = self._store.render(speech).strip()
|
||||
if content:
|
||||
await self._queue_visible_speech(
|
||||
content,
|
||||
source="workflow-edge-transition",
|
||||
node_id=str(edge.get("target") or "") or None,
|
||||
)
|
||||
context_message = fixed_speech_context_message(content)
|
||||
if context_message is not None:
|
||||
context_messages.append(context_message)
|
||||
return await self._resolve_path(
|
||||
str(edge.get("target") or ""),
|
||||
leading_messages=context_messages,
|
||||
leading_messages=list(leading_messages or []),
|
||||
triggering_user_text=triggering_user_text,
|
||||
triggering_user_message=triggering_user_message,
|
||||
)
|
||||
@@ -863,19 +850,6 @@ class WorkflowBrain(BaseBrain):
|
||||
if not edge:
|
||||
return self._passive_node_config(node_id, context_messages)
|
||||
await self._begin_edge_transition(edge)
|
||||
speech = self._engine.edge_transition_speech(edge)
|
||||
if speech:
|
||||
content = self._store.render(speech).strip()
|
||||
if content:
|
||||
target_id = str(edge.get("target") or "")
|
||||
await self._queue_visible_speech(
|
||||
content,
|
||||
source="workflow-edge-transition",
|
||||
node_id=target_id or None,
|
||||
)
|
||||
context_message = fixed_speech_context_message(content)
|
||||
if context_message is not None:
|
||||
context_messages.append(context_message)
|
||||
node_id = str(edge.get("target") or "")
|
||||
raise RuntimeError("工作流连续自动跳转超过安全上限")
|
||||
|
||||
|
||||
@@ -138,17 +138,17 @@ def node_types_response() -> dict[str, Any]:
|
||||
|
||||
def _edge_data_v3(edge: dict) -> dict:
|
||||
data = deepcopy(edge.get("data") or {})
|
||||
data.pop("transitionSpeech", None)
|
||||
data.pop("transition_speech", None)
|
||||
if data.get("mode") in EDGE_MODES:
|
||||
data.setdefault("priority", 10)
|
||||
return data
|
||||
condition = str(data.pop("condition", "") or "").strip()
|
||||
transition = data.pop("transition_speech", data.get("transitionSpeech", ""))
|
||||
data.update(
|
||||
{
|
||||
"mode": "llm" if condition else "always",
|
||||
"priority": 10,
|
||||
"condition": condition,
|
||||
"transitionSpeech": transition,
|
||||
}
|
||||
)
|
||||
return data
|
||||
@@ -234,6 +234,8 @@ def normalize_graph(graph: dict[str, Any] | None) -> dict[str, Any]:
|
||||
_normalize_settings(settings)
|
||||
source.setdefault("nodes", [])
|
||||
source.setdefault("edges", [])
|
||||
for edge in source["edges"]:
|
||||
edge["data"] = _edge_data_v3(edge)
|
||||
for node in source["nodes"]:
|
||||
data = node.setdefault("data", {})
|
||||
if node.get("type") == "start":
|
||||
@@ -327,7 +329,7 @@ def normalize_graph(graph: dict[str, Any] | None) -> dict[str, Any]:
|
||||
"id": f"e-{start_id}-{synthetic_id}",
|
||||
"source": start_id,
|
||||
"target": synthetic_id,
|
||||
"data": {"mode": "always", "priority": 0, "transitionSpeech": ""},
|
||||
"data": {"mode": "always", "priority": 0},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -113,14 +113,6 @@ class WorkflowEngine:
|
||||
return f"当满足以下条件时转到「{target}」:{condition}"
|
||||
return f"当当前阶段任务完成时转到「{target}」。"
|
||||
|
||||
def edge_transition_speech(self, edge: dict | None) -> str:
|
||||
if not edge:
|
||||
return ""
|
||||
data = edge.get("data") or {}
|
||||
return str(
|
||||
data.get("transitionSpeech") or data.get("transition_speech") or ""
|
||||
)
|
||||
|
||||
def global_prompt(self) -> str:
|
||||
return str(self.settings.get("globalPrompt") or "").strip()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user