From 0dcbe6edb527d650a8f6976638c9fcb47d482fa7 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:40:25 -0400 Subject: [PATCH] Ensure system messages are always added --- src/controlflow/events/message_compiler.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/controlflow/events/message_compiler.py b/src/controlflow/events/message_compiler.py index 4dc94174..aff21195 100644 --- a/src/controlflow/events/message_compiler.py +++ b/src/controlflow/events/message_compiler.py @@ -113,14 +113,14 @@ def convert_system_messages( messages: list[BaseMessage], rules: LLMRules ) -> list[BaseMessage]: """ - Converts system messages to human messages if the LLM doesnt support system messages, either at all or in the first position. + Converts system messages to human messages if the LLM doesnt support system + messages, either at all or in the first position. """ - new_messages = [] for i, message in enumerate(messages): if isinstance(message, SystemMessage): - # if system messages are not supported OR if they must be first and this is not the first message - # THEN convert the message to a human message + # If system messages are not supported OR if they must be first and + # this is not the first message, THEN convert the message to a human message if not rules.allow_system_messages or ( i > 0 and rules.require_system_message_first ): @@ -129,6 +129,9 @@ def convert_system_messages( content=f"ORCHESTRATOR: {message.content}", name=message.name ) ) + else: + # If the system message is allowed, add it as-is + new_messages.append(message) else: new_messages.append(message) return new_messages