fix(bedrock): don't send stopSequences to OpenAI GPT-6/GPT-5.6/gpt-oss (#7731)

OpenAI models on Bedrock reject inferenceConfig.stopSequences with a 400,
and crewAI adds the "\nObservation:" stop word to every agent call, so
Agent.kickoff() and Crew.kickoff() failed on GPT-6 Sol/Luna, GPT-5.6 and
gpt-oss.

supports_stop_words() now returns False for "openai." model ids and
_get_inference_config() only sends stopSequences when it returns True,
mirroring the Azure provider. Stop words are still applied client-side
by _apply_stop_words, and executors fall back to use_stop_words=False.

Co-authored-by: Claude <[email protected]>
This commit is contained in:
Lucas Kim
2026-10-09 13:16:55 +00:00
committed by GitHub
co-authored by Claude
parent ce149db311
commit 107fab8c85
2 changed files with 45 additions and 3 deletions
@@ -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_sequences
if self.is_claude_model and self.top_k is not None:
@@ -2130,8 +2130,13 @@ class BedrockCompletion(BaseLLM):
return self.supports_tools
def 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."""
@@ -945,6 +945,43 @@ def test_bedrock_stop_sequences_sent_to_api():
assert call_kwargs["inferenceConfig"]["stopSequences"] == ["\nObservation:", "\nThought:"]
@pytest.mark.parametrize(
"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