From 844773a73590ae8741ff5bfaf1c641c619edc044 Mon Sep 17 00:00:00 2001 From: Soulter <37870767+Soulter@users.noreply.github.com> Date: Sat, 17 Jan 2026 17:57:11 +0800 Subject: [PATCH] feat: skip saving head system messages in history (#4538) * feat: skip saving the first system message in history * fix: rename variable for clarity in system message handling * fix: update logic to skip all system messages until the first non-system message --- .../process_stage/method/agent_sub_stages/internal.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py b/astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py index 43d88c5ad..6d43a78ec 100644 --- a/astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py +++ b/astrbot/core/pipeline/process_stage/method/agent_sub_stages/internal.py @@ -414,10 +414,11 @@ class InternalAgentSubStage(Stage): # using agent context messages to save to history message_to_save = [] + skipped_initial_system = False for message in all_messages: - if message.role == "system": - # we do not save system messages to history - continue + if message.role == "system" and not skipped_initial_system: + continue # skip all system messages until the first non-system message + skipped_initial_system = True if message.role in ["assistant", "user"] and getattr( message, "_no_save", None ):