The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
feat(openai): support `configuration_update` (#40201)
ccurme1a3d81756fa2
diff --git a/libs/partners/openai/langchain_openai/chat_models/base.py b/libs/partners/openai/langchain_openai/chat_models/base.pyindex 15f6ecc693..819ce65cb4 100644--- a/libs/partners/openai/langchain_openai/chat_models/base.py+++ b/libs/partners/openai/langchain_openai/chat_models/base.py@@ -881,6 +881,27 @@ class BaseChatOpenAI(BaseChatModel):Currently supported values are `'minimal'`, `'low'`, `'medium'`, and`'high'`. Reducing reasoning effort can result in faster responses and fewertokens used on reasoning in a response.++ !!! note "Changing reasoning effort mid-conversation"++ Changing this value part-way through a conversation changes a request-level+ parameter, which invalidates the cached prompt prefix.++ Models that support it (currently GPT-6) can instead carry the new effort+ in a `configuration_update` item attached to the message that should start+ using it:++ ```python+ HumanMessage(+ [+ {"type": "configuration_update", "reasoning": {"effort": "high"}},+ {"type": "text", "text": "Analyze the failure modes."},+ ]+ )+ ```++ The new effort applies from that message onward, until another update+ overrides it."""reasoning: dict[str, Any] | None = None@@ -4945,6 +4966,7 @@ def _construct_responses_api_input("mcp_approval_response","tool_search_output","apply_patch_call_output",+ "configuration_update",)for block in msg["content"]:if block["type"] in ("text", "image_url", "file"):diff --git a/libs/partners/openai/tests/cassettes/test_configuration_update_block.yaml.gz b/libs/partners/openai/tests/cassettes/test_configuration_update_block.yaml.gznew file mode 100644index 0000000000..48d0fa2f2fBinary files /dev/null and b/libs/partners/openai/tests/cassettes/test_configuration_update_block.yaml.gz differdiff --git a/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py b/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.pyindex f5d3ae7205..a6bfb60e89 100644--- a/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py+++ b/libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py@@ -610,6 +610,43 @@ def test_reasoning(output_version: Literal["v0", "responses/v1", "v1"]) -> None:assert block_types == ["reasoning", "text"]+def test_configuration_update_block() -> None:+ """A `configuration_update` block changes reasoning effort mid-conversation.++ The model is left at `low`, so the higher effort can only come from the item.+ """+ llm = ChatOpenAI(+ model="gpt-6-astra", use_responses_api=True, reasoning_effort="low"+ )+ question = "How many distinct 5-card poker hands are a full house? Number only."++ first = llm.invoke("Say hi.")+ assert isinstance(first, AIMessage)++ history: list = ["Say hi.", first]+ baseline = llm.invoke([*history, HumanMessage(question)])+ raised = llm.invoke(+ [+ *history,+ HumanMessage(+ [+ {"type": "configuration_update", "reasoning": {"effort": "high"}},+ {"type": "text", "text": question},+ ]+ ),+ ]+ )++ assert isinstance(raised, AIMessage)+ assert raised.usage_metadata is not None+ assert baseline.usage_metadata is not None+ reasoning_tokens = raised.usage_metadata["output_token_details"]["reasoning"]+ assert (+ reasoning_tokens > baseline.usage_metadata["output_token_details"]["reasoning"]+ )++def test_stateful_api() -> None:llm = ChatOpenAI(model=MODEL_NAME, use_responses_api=True)response = llm.invoke("how are you, my name is Bobo")diff --git a/libs/partners/openai/tests/unit_tests/chat_models/test_base.py b/libs/partners/openai/tests/unit_tests/chat_models/test_base.pyindex 78cf75c712..a2462c91a8 100644--- a/libs/partners/openai/tests/unit_tests/chat_models/test_base.py+++ b/libs/partners/openai/tests/unit_tests/chat_models/test_base.py@@ -5236,3 +5236,83 @@ def test_langsmith_gateway_provider_base_url_uses_provider_key(assert llm.openai_api_base == "https://api.openai.com/v1"assert isinstance(llm.openai_api_key, SecretStr)assert llm.openai_api_key.get_secret_value() == "provider-key"+++def test_configuration_update_block_becomes_input_item() -> None:+ """A `configuration_update` block is hoisted out of the message content.++ The Responses API expects it as a top-level input item preceding the message+ it applies to, not as a content block nested inside one.+ """+ llm = ChatOpenAI(model="gpt-6-astra", use_responses_api=True)+ payload = llm._get_request_payload(+ [+ HumanMessage(+ [+ {"type": "configuration_update", "reasoning": {"effort": "high"}},+ {"type": "text", "text": "Hello"},+ ]+ )+ ]+ )++ assert payload["input"] == [+ {"type": "configuration_update", "reasoning": {"effort": "high"}},+ {+ "role": "user",+ "content": [{"type": "input_text", "text": "Hello"}],+ "type": "message",+ },+ ]+++def test_configuration_update_block_keeps_position_across_turns() -> None:+ """The item stays put as the conversation grows, so the prefix stays cacheable.++ Re-deriving the item per request would shift it forward each turn and truncate+ the cached prefix to whatever precedes it.+ """+ llm = ChatOpenAI(model="gpt-6-astra", use_responses_api=True)+ messages: list = [+ HumanMessage("First question"),+ AIMessage("First answer", response_metadata={"id": "resp_123"}),+ HumanMessage(+ [+ {"type": "configuration_update", "reasoning": {"effort": "high"}},+ {"type": "text", "text": "Second question"},+ ]+ ),+ ]+ first = llm._get_request_payload(messages)+ assert [item.get("role") or item["type"] for item in first["input"]] == [+ "user",+ "assistant",+ "configuration_update",+ "user",+ ]++ messages += [+ AIMessage("Second answer", response_metadata={"id": "resp_456"}),+ HumanMessage("Third question"),+ ]+ second = llm._get_request_payload(messages)+ assert second["input"][: len(first["input"])] == first["input"]+++def test_configuration_update_block_without_text() -> None:+ """An update with no accompanying text still yields the input item."""+ llm = ChatOpenAI(model="gpt-6-astra", use_responses_api=True)+ payload = llm._get_request_payload(+ [+ HumanMessage("Earlier question"),+ AIMessage("Earlier answer", response_metadata={"id": "resp_123"}),+ HumanMessage(+ [{"type": "configuration_update", "reasoning": {"effort": "low"}}]+ ),+ ]+ )++ assert payload["input"][-1] == {+ "type": "configuration_update",+ "reasoning": {"effort": "low"},+ }