Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
fix(bedrock): don't send stopSequences to OpenAI GPT-6/GPT-5.6/gpt-oss (#7731)
Lucas Kim107fab8c8508
diff --git a/lib/crewai/src/crewai/llms/providers/bedrock/completion.py b/lib/crewai/src/crewai/llms/providers/bedrock/completion.pyindex cf0d552ae..3cfa3fd47 100644--- a/lib/crewai/src/crewai/llms/providers/bedrock/completion.py+++ b/lib/crewai/src/crewai/llms/providers/bedrock/completion.py@@ -2056,7 +2056,7 @@ class BedrockCompletion(BaseLLM):config["temperature"] = float(self.temperature)if self.top_p is not None:config["topP"] = float(self.top_p)- if self.stop_sequences:+ if self.stop_sequences and self.supports_stop_words():config["stopSequences"] = self.stop_sequencesif self.is_claude_model and self.top_k is not None:@@ -2130,8 +2130,13 @@ class BedrockCompletion(BaseLLM):return self.supports_toolsdef supports_stop_words(self) -> bool:- """Check if the model supports stop words."""- return True+ """Check if the model supports stop words.++ OpenAI models on Bedrock (gpt-oss, GPT-5.x, GPT-6) reject+ ``stopSequences``. Stop words are still applied to their output+ client-side by ``_apply_stop_words``.+ """+ return "openai." not in self.model.lower()def get_context_window_size(self) -> int:"""Get the context window size for the model."""diff --git a/lib/crewai/tests/llms/bedrock/test_bedrock.py b/lib/crewai/tests/llms/bedrock/test_bedrock.pyindex 6d9b67cdf..f82abaaa6 100644--- a/lib/crewai/tests/llms/bedrock/test_bedrock.py+++ b/lib/crewai/tests/llms/bedrock/test_bedrock.py@@ -945,6 +945,43 @@ def test_bedrock_stop_sequences_sent_to_api():assert call_kwargs["inferenceConfig"]["stopSequences"] == ["\nObservation:", "\nThought:"]+ "model",+ [+ "bedrock/us.openai.gpt-6-sol",+ "bedrock/global.openai.gpt-6-luna",+ "bedrock/openai.gpt-oss-120b-1:0",+ ],+)+def test_bedrock_openai_models_do_not_send_stop_sequences(model):+ """Test that OpenAI models on Bedrock get stop words client-side, not as stopSequences."""+ llm = LLM(model=model)+ llm.stop = ["\nObservation:"]++ with patch.object(llm._client, 'converse') as mock_converse:+ mock_converse.return_value = {+ 'output': {+ 'message': {+ 'role': 'assistant',+ 'content': [{'text': 'Thought: done\nObservation: extra'}]+ }+ },+ 'usage': {+ 'inputTokens': 10,+ 'outputTokens': 5,+ 'totalTokens': 15+ }+ }++ result = llm.call("Say hello in one word")++ assert "stopSequences" not in mock_converse.call_args[1]["inferenceConfig"]+ assert result == "Thought: done"++ # Agent executors read this to fall back to client-side stop handling.+ assert llm.supports_stop_words() is False++# Agent Kickoff Structured Output Tests