From a05b3fbd335fdd89527d9dbcbf79f356fa604bd7 Mon Sep 17 00:00:00 2001 From: vegu-ai-tools <152010387+vegu-ai-tools@users.noreply.github.com> Date: Fri, 1 May 2026 13:52:17 +0300 Subject: [PATCH] fix: correct volatile context placement in RAG query generation template --- CHANGELOG.yaml | 1 + ...alyze-text-and-generate-rag-queries.jinja2 | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.yaml b/CHANGELOG.yaml index c59a2115..60552616 100644 --- a/CHANGELOG.yaml +++ b/CHANGELOG.yaml @@ -49,6 +49,7 @@ - "Game Loop Actor Iter: Fixed a bug where the `game_loop_actor_iter` event was only firing for player turns, so agents that listen for actor iteration (like passive narration) silently skipped AI turns." - "OpenRouter: Fixed redundant provider/model list fetches when multiple OpenRouter clients are configured. Concurrent `status()` calls all saw the fetched-flag as still false and each kicked off its own HTTP request; the fetches are now serialized with an asyncio lock and double-checked locking so only one request runs." - "Character Prompts: Fixed duplicated character description in prompts. When the LLM-generated character sheet contained a `description` attribute (common — the extractor often emits one), it was rendered alongside the standalone description field, repeating the same text twice. Templates that render both now filter `description` out of the sheet (case-insensitive). Affects the dialogue, narrator, director (voice assignment), and creator (dialogue examples, dialogue instructions, character goals, contextual generate) prompt paths." + - "RAG Query Generation: Fixed the analyze-text-and-generate-rag-queries template (used by the long-term memory retrieval flow) ignoring the volatile context placement setting. Dynamic instructions and the passed-in RAG context were always pinned at the top of the prompt, defeating prompt caching even when it was enabled on the client/agent. Volatile pieces are now split out and positioned via volatile_context_placement, matching the rest of the prompt set." improvements: - "System Prompt Override Indicators: The system prompt override list now shows a pencil icon next to entries that have an active override, making it easy to see which prompts have been customized." - "Search Strictness: The distance_mod embedding preset value is now a float (was int) with a range of 0.1–2.0, allowing both tighter and looser similarity matching. A 'Search Strictness' slider is now available in the Context Database UI, letting users tune search sensitivity on the fly. Changes persist to the active embedding preset immediately." diff --git a/src/talemate/prompts/templates/world_state/analyze-text-and-generate-rag-queries.jinja2 b/src/talemate/prompts/templates/world_state/analyze-text-and-generate-rag-queries.jinja2 index 9405cccd..60e9a7b3 100644 --- a/src/talemate/prompts/templates/world_state/analyze-text-and-generate-rag-queries.jinja2 +++ b/src/talemate/prompts/templates/world_state/analyze-text-and-generate-rag-queries.jinja2 @@ -10,20 +10,34 @@ Override example: {% set rendered_context -%} <|SECTION:CONTEXT|> {% include "extra-context-static.jinja2" %} -{% include "extra-context-dynamic.jinja2" %} -{% if extra_context %}{% for context in extra_context %}{{ context }} ---- -{% endfor %}{% endif %} <|CLOSE_SECTION|> {% if include_character_context %}{% include "character-context.jinja2" %}{% endif %} {% endset %} {# END RENDERED CONTEXT #} +{# VOLATILE CONTEXT #} +{% set volatile_inner -%} +{% include "extra-context-dynamic.jinja2" %} +{% if extra_context %}{% for context in extra_context %}{{ context }} +--- +{% endfor %}{% endif %} +{%- endset %} +{% set volatile_context_text -%} +{% if volatile_inner.strip() %}<|SECTION:DYNAMIC CONTEXT|> +{{ volatile_inner }} +<|CLOSE_SECTION|> +{% endif %} +{%- endset %} +{# END VOLATILE CONTEXT #} + {# RENDER PROMPT #} +{% set volatile_placement = volatile_context_placement() %} {{ rendered_context }} +{% if volatile_placement != "after_history" %}{{ volatile_context_text }}{% endif %} <|SECTION:SCENE|> {{ text }} <|CLOSE_SECTION|> +{% if volatile_placement == "after_history" %}{{ volatile_context_text }}{% endif %} <|SECTION:TASK|> You are assisting with an ongoing story. You have access to a vector database containing factual information about the characters, locations, events, and lore of this narrative world. Your task is to generate up to {{ num_queries }} specific, targeted queries to gather additional context for the current scene or conversation.