fix: minor change in upsert logic for prompt default (#9729)

minor compaction upsert change
This commit is contained in:
amysguan
2026-03-02 11:11:48 -08:00
committed by Caren Thomas
parent c28ba77354
commit 8e60b73eee
3 changed files with 16 additions and 4 deletions

View File

@@ -2419,7 +2419,11 @@ async def summarize_messages(
# If mode changed from agent's original settings and prompt not explicitly set in request, then use the default prompt for the new mode # If mode changed from agent's original settings and prompt not explicitly set in request, then use the default prompt for the new mode
# Ex: previously was sliding_window, now is all, so we need to use the default prompt for all mode # Ex: previously was sliding_window, now is all, so we need to use the default prompt for all mode
if "mode" in changed_fields and agent.compaction_settings.mode != request.compaction_settings.mode: if (
"mode" in changed_fields
and "prompt" not in changed_fields
and agent.compaction_settings.mode != request.compaction_settings.mode
):
from letta.services.summarizer.summarizer_config import get_default_prompt_for_mode from letta.services.summarizer.summarizer_config import get_default_prompt_for_mode
compaction_settings.prompt = get_default_prompt_for_mode(compaction_settings.mode) compaction_settings.prompt = get_default_prompt_for_mode(compaction_settings.mode)

View File

@@ -712,7 +712,11 @@ async def compact_conversation(
# If mode changed from agent's original settings and prompt not explicitly set in request, then use the default prompt for the new mode # If mode changed from agent's original settings and prompt not explicitly set in request, then use the default prompt for the new mode
# Ex: previously was sliding_window, now is all, so we need to use the default prompt for all mode # Ex: previously was sliding_window, now is all, so we need to use the default prompt for all mode
if "mode" in changed_fields and agent.compaction_settings.mode != request.compaction_settings.mode: if (
"mode" in changed_fields
and "prompt" not in changed_fields
and agent.compaction_settings.mode != request.compaction_settings.mode
):
from letta.services.summarizer.summarizer_config import get_default_prompt_for_mode from letta.services.summarizer.summarizer_config import get_default_prompt_for_mode
compaction_settings.prompt = get_default_prompt_for_mode(compaction_settings.mode) compaction_settings.prompt = get_default_prompt_for_mode(compaction_settings.mode)

View File

@@ -791,14 +791,18 @@ class AgentManager:
# Upsert compaction_settings: merge incoming partial update with existing settings # Upsert compaction_settings: merge incoming partial update with existing settings
if agent_update.compaction_settings is not None: if agent_update.compaction_settings is not None:
# If mode changed, update the prompt to the default for the new mode # If mode changed, update the prompt to the default for the new mode
if agent.compaction_settings is not None and agent_update.compaction_settings.mode != agent.compaction_settings.mode: changed_fields = agent_update.compaction_settings.model_fields_set
if (
agent.compaction_settings is not None
and "mode" in changed_fields
and agent_update.compaction_settings.mode != agent.compaction_settings.mode
):
from letta.services.summarizer.summarizer_config import get_default_prompt_for_mode from letta.services.summarizer.summarizer_config import get_default_prompt_for_mode
agent_update.compaction_settings.prompt = get_default_prompt_for_mode(agent_update.compaction_settings.mode) agent_update.compaction_settings.prompt = get_default_prompt_for_mode(agent_update.compaction_settings.mode)
# Fill in unchanged fields from existing settings # Fill in unchanged fields from existing settings
if agent.compaction_settings is not None: if agent.compaction_settings is not None:
changed_fields = agent_update.compaction_settings.model_fields_set
for field in agent.compaction_settings.model_fields: for field in agent.compaction_settings.model_fields:
if field not in changed_fields: if field not in changed_fields:
setattr(agent_update.compaction_settings, field, getattr(agent.compaction_settings, field)) setattr(agent_update.compaction_settings, field, getattr(agent.compaction_settings, field))