fix: honor strict workflow agent entry mode
This commit is contained in:
@@ -562,16 +562,24 @@ class WorkflowBrain(BaseBrain):
|
||||
return
|
||||
|
||||
await self._emit_node_active(node_id)
|
||||
data = self._engine.data(node_id)
|
||||
entry_mode = str(data.get("entryMode") or "wait_user")
|
||||
should_run = entry_mode == "generate" or bool(triggering_user_text)
|
||||
if should_run:
|
||||
if self._agent_runs_on_entry(node_id):
|
||||
self._state.enter(node_id, WorkflowStatus.RUNNING_AGENT)
|
||||
await self._require_runtime().queue_frame(LLMRunFrame())
|
||||
return
|
||||
|
||||
# The turn that selected this node belongs to the previous stage.
|
||||
# A strict wait must not leave it pending until the next user message.
|
||||
if triggering_user_text:
|
||||
self._state.consume_user_turn()
|
||||
self._state.enter(node_id, WorkflowStatus.WAITING_USER)
|
||||
|
||||
def _agent_runs_on_entry(self, node_id: str) -> bool:
|
||||
"""Only explicit generate mode may start a reply on node entry."""
|
||||
entry_mode = str(
|
||||
self._engine.data(node_id).get("entryMode") or "wait_user"
|
||||
)
|
||||
return entry_mode == "generate"
|
||||
|
||||
async def _activate_node_config(
|
||||
self,
|
||||
node_config: NodeConfig,
|
||||
@@ -708,10 +716,7 @@ class WorkflowBrain(BaseBrain):
|
||||
return configured
|
||||
if node_type != "agent":
|
||||
return node_config
|
||||
entry_mode = str(
|
||||
self._engine.data(node_id).get("entryMode") or "wait_user"
|
||||
)
|
||||
should_run = entry_mode == "generate" or bool(triggering_user_text)
|
||||
should_run = self._agent_runs_on_entry(node_id)
|
||||
configured = dict(node_config)
|
||||
configured["respond_immediately"] = should_run
|
||||
configured["pre_actions"] = [
|
||||
@@ -719,6 +724,8 @@ class WorkflowBrain(BaseBrain):
|
||||
"type": ConfiguredFlowManager.ENTRY_ACTION_TYPE,
|
||||
"node_id": node_id,
|
||||
"should_run": should_run,
|
||||
"consume_triggering_turn": bool(triggering_user_text)
|
||||
and not should_run,
|
||||
"handler": self._activate_from_flow_transition,
|
||||
}
|
||||
]
|
||||
@@ -735,6 +742,8 @@ class WorkflowBrain(BaseBrain):
|
||||
if action.get("should_run"):
|
||||
self._state.enter(node_id, WorkflowStatus.RUNNING_AGENT)
|
||||
else:
|
||||
if action.get("consume_triggering_turn"):
|
||||
self._state.consume_user_turn()
|
||||
self._state.enter(node_id, WorkflowStatus.WAITING_USER)
|
||||
|
||||
def _knowledge_function(self, node_id: str) -> FlowsFunctionSchema | None:
|
||||
|
||||
Reference in New Issue
Block a user