fix(workflow): prevent fixed speech continuation
This commit is contained in:
@@ -42,6 +42,7 @@ from services.action_runtime import (
|
||||
ActionStatus,
|
||||
)
|
||||
from services.action_stage import ActionStageRunner, ActionStageSpec, StageAction
|
||||
from services.fixed_speech import fixed_speech_context_message
|
||||
from services.knowledge import search as search_knowledge
|
||||
from services.message_policy import (
|
||||
MESSAGE_COMPLETION_POLICIES,
|
||||
@@ -794,9 +795,9 @@ class WorkflowBrain(BaseBrain):
|
||||
source="workflow-edge-transition",
|
||||
node_id=str(edge.get("target") or "") or None,
|
||||
)
|
||||
context_messages.append(
|
||||
{"role": "assistant", "content": content}
|
||||
)
|
||||
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,
|
||||
@@ -828,10 +829,11 @@ class WorkflowBrain(BaseBrain):
|
||||
if triggering_user_message
|
||||
else {"role": "user", "content": triggering_user_text}
|
||||
)
|
||||
agent_messages = [
|
||||
current_user_message,
|
||||
*context_messages,
|
||||
]
|
||||
# Fixed speech is represented by system facts. Put those
|
||||
# facts before the triggering user turn so RESET contexts
|
||||
# still end with the real user input rather than a control
|
||||
# message.
|
||||
agent_messages = [*context_messages, current_user_message]
|
||||
return self._agent_config(node_id, agent_messages)
|
||||
if node_type == "end":
|
||||
await self._enter_end(node_id)
|
||||
@@ -871,9 +873,9 @@ class WorkflowBrain(BaseBrain):
|
||||
source="workflow-edge-transition",
|
||||
node_id=target_id or None,
|
||||
)
|
||||
context_messages.append(
|
||||
{"role": "assistant", "content": content}
|
||||
)
|
||||
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("工作流连续自动跳转超过安全上限")
|
||||
|
||||
@@ -974,9 +976,9 @@ class WorkflowBrain(BaseBrain):
|
||||
dict(message) for message in continuation.context_messages
|
||||
]
|
||||
if result.speech:
|
||||
context_messages.append(
|
||||
{"role": "assistant", "content": result.speech}
|
||||
)
|
||||
context_message = fixed_speech_context_message(result.speech)
|
||||
if context_message is not None:
|
||||
context_messages.append(context_message)
|
||||
|
||||
if not self._engine.has_outgoing(continuation.node_id):
|
||||
self._state.enter(
|
||||
|
||||
Reference in New Issue
Block a user