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
This commit is contained in:
Soulter
2026-01-17 17:57:11 +08:00
committed by GitHub
parent 1a7e8456ab
commit 844773a735
@@ -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
):