From 348df9d4ced25de0f6c36fb0fb38e1b31743d28b Mon Sep 17 00:00:00 2001 From: Paul Kompfner Date: Thu, 19 Mar 2026 13:34:41 -0400 Subject: [PATCH] fix: remove redundant instructions override in run_inference The override would re-add `instructions` after the adapter had intentionally converted it to a developer message for empty contexts. Added a regression test. --- src/pipecat/services/openai/responses/llm.py | 4 --- tests/test_run_inference.py | 33 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/pipecat/services/openai/responses/llm.py b/src/pipecat/services/openai/responses/llm.py index f62c6e758..4f0c81dc7 100644 --- a/src/pipecat/services/openai/responses/llm.py +++ b/src/pipecat/services/openai/responses/llm.py @@ -385,10 +385,6 @@ class OpenAIResponsesLLMService(LLMService): # Override for non-streaming params["stream"] = False - # Override instructions if caller provided one explicitly - if system_instruction is not None: - params["instructions"] = system_instruction - if max_tokens is not None: params["max_output_tokens"] = max_tokens diff --git a/tests/test_run_inference.py b/tests/test_run_inference.py index f67c725ae..cef13fb27 100644 --- a/tests/test_run_inference.py +++ b/tests/test_run_inference.py @@ -902,3 +902,36 @@ async def test_openai_responses_run_inference_max_tokens_override(): assert result == "Summary" call_kwargs = service._client.responses.create.call_args.kwargs assert call_kwargs["max_output_tokens"] == 200 + + +@pytest.mark.asyncio +async def test_openai_responses_run_inference_system_instruction_param_with_empty_context(): + """Test that system_instruction param becomes a developer message when context is empty. + + The Responses API rejects requests with instructions but no input items. + When run_inference is called with an explicit system_instruction and an + empty context, the instruction must become a developer message — not be + sent as the instructions parameter. + """ + with patch.object(OpenAIResponsesLLMService, "_create_client"): + service = OpenAIResponsesLLMService( + settings=OpenAIResponsesLLMService.Settings(model="gpt-4.1"), + ) + service._client = AsyncMock() + + context = LLMContext(messages=[]) + + mock_response = MagicMock() + mock_response.output_text = "Response" + service._client.responses.create = AsyncMock(return_value=mock_response) + + result = await service.run_inference( + context, system_instruction="Summarize the conversation" + ) + + assert result == "Response" + call_kwargs = service._client.responses.create.call_args.kwargs + assert call_kwargs["input"] == [ + {"role": "developer", "content": "Summarize the conversation"} + ] + assert "instructions" not in call_kwargs