diff --git a/api/core/app/apps/workflow/app_generator.py b/api/core/app/apps/workflow/app_generator.py index f4aec3479b..022beef00c 100644 --- a/api/core/app/apps/workflow/app_generator.py +++ b/api/core/app/apps/workflow/app_generator.py @@ -48,6 +48,7 @@ class WorkflowAppGenerator(BaseAppGenerator): streaming: Literal[True], call_depth: int, workflow_thread_pool_id: Optional[str], + conversation_id: Optional[str], ) -> Generator[Mapping | str, None, None]: ... @overload @@ -62,6 +63,7 @@ class WorkflowAppGenerator(BaseAppGenerator): streaming: Literal[False], call_depth: int, workflow_thread_pool_id: Optional[str], + conversation_id: Optional[str], ) -> Mapping[str, Any]: ... @overload @@ -76,6 +78,7 @@ class WorkflowAppGenerator(BaseAppGenerator): streaming: bool, call_depth: int, workflow_thread_pool_id: Optional[str], + conversation_id: Optional[str], ) -> Union[Mapping[str, Any], Generator[Mapping | str, None, None]]: ... def generate( @@ -89,6 +92,7 @@ class WorkflowAppGenerator(BaseAppGenerator): streaming: bool = True, call_depth: int = 0, workflow_thread_pool_id: Optional[str] = None, + conversation_id: Optional[str] = None, ) -> Union[Mapping[str, Any], Generator[Mapping | str, None, None]]: files: Sequence[Mapping[str, Any]] = args.get("files") or [] @@ -133,6 +137,7 @@ class WorkflowAppGenerator(BaseAppGenerator): call_depth=call_depth, trace_manager=trace_manager, workflow_execution_id=workflow_run_id, + conversation_id=conversation_id, ) contexts.plugin_tool_providers.set({}) @@ -280,6 +285,7 @@ class WorkflowAppGenerator(BaseAppGenerator): node_id=node_id, inputs=args["inputs"] ), workflow_execution_id=str(uuid.uuid4()), + conversation_id=None, ) contexts.plugin_tool_providers.set({}) contexts.plugin_tool_providers_lock.set(threading.Lock()) @@ -356,6 +362,7 @@ class WorkflowAppGenerator(BaseAppGenerator): extras={"auto_generate_conversation_name": False}, single_loop_run=WorkflowAppGenerateEntity.SingleLoopRunEntity(node_id=node_id, inputs=args["inputs"]), workflow_execution_id=str(uuid.uuid4()), + conversation_id=None, ) contexts.plugin_tool_providers.set({}) contexts.plugin_tool_providers_lock.set(threading.Lock()) diff --git a/api/core/app/apps/workflow/app_runner.py b/api/core/app/apps/workflow/app_runner.py index b59e34e222..f3676305a8 100644 --- a/api/core/app/apps/workflow/app_runner.py +++ b/api/core/app/apps/workflow/app_runner.py @@ -96,6 +96,7 @@ class WorkflowAppRunner(WorkflowBasedAppRunner): SystemVariableKey.APP_ID: app_config.app_id, SystemVariableKey.WORKFLOW_ID: app_config.workflow_id, SystemVariableKey.WORKFLOW_EXECUTION_ID: self.application_generate_entity.workflow_execution_id, + SystemVariableKey.CONVERSATION_ID: self.application_generate_entity.conversation_id, } variable_pool = VariablePool( diff --git a/api/core/app/entities/app_invoke_entities.py b/api/core/app/entities/app_invoke_entities.py index c0d99693b0..f16b55a91b 100644 --- a/api/core/app/entities/app_invoke_entities.py +++ b/api/core/app/entities/app_invoke_entities.py @@ -205,6 +205,7 @@ class WorkflowAppGenerateEntity(AppGenerateEntity): # app config app_config: WorkflowUIBasedAppConfig workflow_execution_id: str + conversation_id: Optional[str] class SingleIterationRunEntity(BaseModel): """ diff --git a/api/core/plugin/backwards_invocation/app.py b/api/core/plugin/backwards_invocation/app.py index 4e43561a15..5eca5197b8 100644 --- a/api/core/plugin/backwards_invocation/app.py +++ b/api/core/plugin/backwards_invocation/app.py @@ -165,6 +165,7 @@ class PluginAppBackwardsInvocation(BaseBackwardsInvocation): streaming=stream, call_depth=1, workflow_thread_pool_id=None, + conversation_id=None, ) @classmethod diff --git a/api/core/tools/workflow_as_tool/tool.py b/api/core/tools/workflow_as_tool/tool.py index 57c93d1d45..57b9af146f 100644 --- a/api/core/tools/workflow_as_tool/tool.py +++ b/api/core/tools/workflow_as_tool/tool.py @@ -95,6 +95,7 @@ class WorkflowTool(Tool): streaming=False, call_depth=self.workflow_call_depth + 1, workflow_thread_pool_id=self.thread_pool_id, + conversation_id=conversation_id, ) assert isinstance(result, dict) data = result.get("data", {}) diff --git a/api/services/app_generate_service.py b/api/services/app_generate_service.py index 245c123a04..aa3bbaf15c 100644 --- a/api/services/app_generate_service.py +++ b/api/services/app_generate_service.py @@ -113,6 +113,7 @@ class AppGenerateService: streaming=streaming, call_depth=0, workflow_thread_pool_id=None, + conversation_id=None, ), ), request_id, diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index 428c204dd3..3f6122e830 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -200,11 +200,11 @@ const formatItem = ( variable: 'sys.dialogue_count', type: VarType.number, }) - res.vars.push({ - variable: 'sys.conversation_id', - type: VarType.string, - }) } + res.vars.push({ + variable: 'sys.conversation_id', + type: VarType.string, + }) res.vars.push({ variable: 'sys.user_id', type: VarType.string,