Move turn completion instructions to system_instruction
Turn completion instructions were being injected as a system message in the LLM context, which caused warning spam when system_instruction was also set, did not persist across full context updates, and broke LLMs that do not support consecutive system messages. Instead, compose the turn completion instructions into the LLM service system_instruction field. This is managed via _base_system_instruction which stores the original value for restoration when turn completion is disabled.
This commit is contained in:
@@ -50,7 +50,6 @@ from pipecat.turns.user_mute import (
|
||||
MuteUntilFirstBotCompleteUserMuteStrategy,
|
||||
)
|
||||
from pipecat.turns.user_stop import SpeechTimeoutUserTurnStopStrategy
|
||||
from pipecat.turns.user_turn_completion_mixin import UserTurnCompletionConfig
|
||||
from pipecat.turns.user_turn_strategies import UserTurnStrategies
|
||||
|
||||
USER_TURN_STOP_TIMEOUT = 0.2
|
||||
@@ -156,7 +155,7 @@ class TestLLMUserAggregator(unittest.IsolatedAsyncioTestCase):
|
||||
)
|
||||
assert context.messages[0]["content"] == "Hi there!"
|
||||
|
||||
async def test_llm_messages_update_reinjects_turn_completion_instructions(self):
|
||||
async def test_llm_messages_update_does_not_inject_turn_completion_into_context(self):
|
||||
context = LLMContext()
|
||||
params = LLMUserAggregatorParams(filter_incomplete_user_turns=True)
|
||||
pipeline = Pipeline([LLMUserAggregator(context, params=params)])
|
||||
@@ -170,13 +169,11 @@ class TestLLMUserAggregator(unittest.IsolatedAsyncioTestCase):
|
||||
pipeline,
|
||||
frames_to_send=frames_to_send,
|
||||
)
|
||||
config = UserTurnCompletionConfig()
|
||||
# The context should contain the new messages plus the re-injected instructions
|
||||
assert len(context.messages) == 3
|
||||
# Turn completion instructions are now set via system_instruction on the
|
||||
# LLM service, not injected into context messages.
|
||||
assert len(context.messages) == 2
|
||||
assert context.messages[0]["content"] == "You are a helpful assistant."
|
||||
assert context.messages[1]["content"] == "Hello!"
|
||||
assert context.messages[2]["role"] == "system"
|
||||
assert context.messages[2]["content"] == config.completion_instructions
|
||||
|
||||
async def test_default_user_turn_strategies(self):
|
||||
context = LLMContext()
|
||||
|
||||
Reference in New Issue
Block a user