diff --git a/api/core/helper/encrypter.py b/api/core/helper/encrypter.py index 13f1024eec..a4e1d7c601 100644 --- a/api/core/helper/encrypter.py +++ b/api/core/helper/encrypter.py @@ -88,7 +88,7 @@ def encrypt_secret_keys( if secret_variables is None: secret_variables = set() - if isinstance(obj, dict): + if isinstance(obj, Mapping): # recurse into dict return {key: encrypt_secret_keys(value, secret_variables, key) for key, value in obj.items()} diff --git a/api/core/workflow/nodes/agent/agent_node.py b/api/core/workflow/nodes/agent/agent_node.py index 3ad26ea0ba..04f50ee0f6 100644 --- a/api/core/workflow/nodes/agent/agent_node.py +++ b/api/core/workflow/nodes/agent/agent_node.py @@ -141,14 +141,18 @@ class AgentNode(Node): # get conversation id conversation_id = self.graph_runtime_state.variable_pool.get(["sys", SystemVariableKey.CONVERSATION_ID]) - env_vars = self.graph_runtime_state.variable_pool.variable_dictionary.get("env", {}) - - # get secret variables used - secret_variables = { - var.name - for var in env_vars.values() # iterate over the values directly - if isinstance(var, SecretVariable) - } + # to store secret variables used in the Agent block. + secret_variables = set() + # get secret variables used. + for section_vars in self.graph_runtime_state.variable_pool.variable_dictionary.values(): + # Iterate over all the sections. e.g. sys, env etc. + if isinstance(section_vars, dict): + # Iterate over each variable in the section + for variable in section_vars.values(): + # Check if the variable is a SecretVariable + if isinstance(variable, SecretVariable): + # Add the variable name to the set + secret_variables.add(variable.name) try: message_stream = strategy.invoke(