From 991010005056f18451cc0397eaef5de84caecf6f Mon Sep 17 00:00:00 2001 From: vegu-ai-tools <152010387+vegu-ai-tools@users.noreply.github.com> Date: Wed, 13 May 2026 22:29:46 +0300 Subject: [PATCH] Update CHANGELOG and refactor ConversationAgent to prevent unnecessary stop-sequence injection --- CHANGELOG.yaml | 1 + src/talemate/agents/conversation/__init__.py | 6 +----- tests/test_conversation_agent.py | 21 +++++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index 588d4dec..f0e8fed7 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -5,6 +5,7 @@ - "Pydantic Migration: Internal data models across the codebase converted to pydantic for stricter validation. No user-visible behavior changes." fixes: - "Game Loop Event: Fixed an internal scene-loop event being constructed with the wrong scene reference, surfaced by the pydantic migration." + - "Conversation Agent: Stopped injecting `#` into the LLM stop-sequence list on every conversation turn. The conversation agent's prompt-parameter hook now only wipes character-name stop sequences when the `inject_character_names_into_stop` setting is disabled, and is a no-op otherwise." 0.37.0: features: - "System Prompt Template Variable: Added {{ system_prompt }} template variable for system prompt overrides. Use it to include the default system prompt within a custom override, at both the app and client level." diff --git a/src/talemate/agents/conversation/__init__.py b/src/talemate/agents/conversation/__init__.py index 5c62e6f7..5c7199f8 100644 --- a/src/talemate/agents/conversation/__init__.py +++ b/src/talemate/agents/conversation/__init__.py @@ -539,9 +539,5 @@ class ConversationAgent(MemoryRAGMixin, Agent): def inject_prompt_paramters( self, prompt_param: dict, kind: str, agent_function_name: str ): - if ( - prompt_param.get("extra_stopping_strings") is None - or not self.inject_character_names_into_stop - ): + if not self.inject_character_names_into_stop: prompt_param["extra_stopping_strings"] = [] - prompt_param["extra_stopping_strings"] += ["#"] diff --git a/tests/test_conversation_agent.py b/tests/test_conversation_agent.py index 4a851b50..68dc25ee 100644 --- a/tests/test_conversation_agent.py +++ b/tests/test_conversation_agent.py @@ -297,13 +297,15 @@ class TestAllowRepetitionBreakAndInject: conversation.allow_repetition_break("conversation", "build_prompt") is False ) - def test_inject_prompt_parameters_appends_hash(self, conversation_scene): + def test_inject_prompt_parameters_noop_with_inject_enabled_and_empty( + self, conversation_scene + ): _, conversation, _ = conversation_scene params = {} conversation.inject_prompt_paramters(params, "conversation", "converse") - # When inject_character_names_into_stop is True (default), the - # function still wraps with extra_stopping_strings = [], then adds "#". - assert params.get("extra_stopping_strings", []) == ["#"] + # When inject_character_names_into_stop is True (default) and no + # stopping strings are present, the function leaves params untouched. + assert "extra_stopping_strings" not in params def test_inject_prompt_parameters_resets_when_inject_disabled( self, conversation_scene @@ -314,22 +316,23 @@ class TestAllowRepetitionBreakAndInject: ].value = False params = {"extra_stopping_strings": ["EXISTING"]} conversation.inject_prompt_paramters(params, "conversation", "converse") - # The function resets to [] when inject_character_names_into_stop is - # False, and then appends "#". - assert params["extra_stopping_strings"] == ["#"] + # When inject_character_names_into_stop is False, any stopping + # strings already populated (e.g. character names added by the + # client) are wiped. + assert params["extra_stopping_strings"] == [] def test_inject_prompt_parameters_preserves_existing_with_inject_enabled( self, conversation_scene ): _, conversation, _ = conversation_scene # When inject_character_names_into_stop is True AND extra_stopping_strings - # is already a list, it is preserved (existing list + "#"). + # is already populated, it is left untouched. conversation.actions["generation_override"].config[ "inject_character_names_into_stop" ].value = True params = {"extra_stopping_strings": ["EXISTING"]} conversation.inject_prompt_paramters(params, "conversation", "converse") - assert params["extra_stopping_strings"] == ["EXISTING", "#"] + assert params["extra_stopping_strings"] == ["EXISTING"] # ---------------------------------------------------------------------------