Skip to content

Commit

Permalink
Ensure system messages are always added
Browse files Browse the repository at this point in the history
  • Loading branch information
jlowin committed Oct 9, 2024
1 parent 0c2ddc0 commit 0dcbe6e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/controlflow/events/message_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand All @@ -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
Expand Down

0 comments on commit 0dcbe6e

Please sign in to comment.