From 90502ee96211ae9333ccc3c5cb656d3e25fa6993 Mon Sep 17 00:00:00 2001 From: vegu-ai-tools <152010387+vegu-ai-tools@users.noreply.github.com> Date: Sat, 28 Mar 2026 12:52:33 +0200 Subject: [PATCH] Update CHANGELOG and remove unnecessary unified_api_key fields from agent action configs. Implemented a function to strip these static references before saving configurations. --- CHANGELOG.yaml | 3 ++- src/talemate/agents/base.py | 1 + src/talemate/config/state.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index 5ec008cf..8edac4a5 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -15,4 +15,5 @@ - Fixed "No episodes available" placeholder being selectable in the episode list. - Fixed response extraction failing when only a closing anchor tag was present in the LLM response (e.g., `` without ``). - "Director actions: Removed redundant fix_instructions LLM call from direct_scene actor path. The FOCAL callback metadata already prevents verbatim dialogue in director instructions." - - "Encryption: Fixed API keys in agent action configs (e.g., OpenAI-compatible TTS, visual backends) being stored in plaintext. The encryption walker now handles the nested AgentActionConfig structure where the key is wrapped in a {value: ...} dict." \ No newline at end of file + - "Encryption: Fixed API keys in agent action configs (e.g., OpenAI-compatible TTS, visual backends) being stored in plaintext. The encryption walker now handles the nested AgentActionConfig structure where the key is wrapped in a {value: ...} dict." + - "Agent Config: Stopped persisting unified_api_key fields to config.yaml. These are static reference pointers (e.g., 'openai.api_key') defined in code and never change, so saving them was unnecessary." \ No newline at end of file diff --git a/src/talemate/agents/base.py b/src/talemate/agents/base.py index 80296cb1..2616b543 100644 --- a/src/talemate/agents/base.py +++ b/src/talemate/agents/base.py @@ -628,6 +628,7 @@ class Agent(ABC): value=config_obj.value ) for config_key, config_obj in action.config.items() + if config_obj.type != "unified_api_key" }, ) for action_key, action in self.actions.items() diff --git a/src/talemate/config/state.py b/src/talemate/config/state.py index 31fd4b2f..46731def 100644 --- a/src/talemate/config/state.py +++ b/src/talemate/config/state.py @@ -57,6 +57,33 @@ async def update_config(other_config: Config | dict): await config.set_dirty() +def _strip_unified_api_key_configs(config: dict): + """ + Remove unified_api_key entries from agent action configs before saving. + + These are static reference pointers (e.g., 'openai.api_key') defined in + agent code — they never change and should not be persisted. + """ + from talemate.instance import AGENTS + + for agent_name, agent_data in config.get("agents", {}).items(): + agent = AGENTS.get(agent_name) + if not agent or not getattr(agent, "actions", None): + continue + + actions = agent_data.get("actions", {}) + for action_key, action_data in actions.items(): + runtime_action = agent.actions.get(action_key) + if not runtime_action or not runtime_action.config: + continue + + saved_config = action_data.get("config", {}) + for config_key in list(saved_config.keys()): + runtime_cfg = runtime_action.config.get(config_key) + if runtime_cfg and runtime_cfg.type == "unified_api_key": + del saved_config[config_key] + + def save_config(): """ Save the config file to the given path. @@ -107,6 +134,8 @@ def save_config(): ) client["preset_group"] = "" + _strip_unified_api_key_configs(config) + encrypt_sensitive_values(config) with open(CONFIG_FILE, "w") as file: