The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
feat(core,anthropic,openai): declare mid-conversation support in model profiles (#41180)
Richard Scarrottb060a7466482
diff --git a/libs/core/langchain_core/language_models/model_profile.py b/libs/core/langchain_core/language_models/model_profile.pyindex bbfdc87a59..a724fd1a78 100644--- a/libs/core/langchain_core/language_models/model_profile.py+++ b/libs/core/langchain_core/language_models/model_profile.py@@ -135,6 +135,26 @@ class ModelProfile(TypedDict, total=False):Only meaningful when `tool_calling` is `True`."""+ # --- Mid-conversation changes ---+ mid_conversation_system_messages: bool+ """Whether a `SystemMessage` after the first turn is sent where it sits.++ Absent or `False` means the chat model may move it into the leading system+ prompt instead.+ """++ mid_conversation_tools: bool+ """Whether tools can be added mid-conversation.++ The tool is added through a message rather than the request's tool list, so+ the prompt prefix before it stays unchanged. Implies+ `mid_conversation_system_messages`.++ The message format is provider-specific. Every provider that sets this+ accepts a tool's full definition; some also accept a reference to a tool+ already in the request, or can remove a tool.+ """+# --- Structured output ---structured_output: bool"""Whether the model supports native [structured output](https://docs.langchain.com/oss/python/langchain/models#structured-outputs)."""diff --git a/libs/partners/anthropic/langchain_anthropic/chat_models.py b/libs/partners/anthropic/langchain_anthropic/chat_models.pyindex 01d8369bc0..dd264f8e1c 100644--- a/libs/partners/anthropic/langchain_anthropic/chat_models.py+++ b/libs/partners/anthropic/langchain_anthropic/chat_models.py@@ -625,10 +625,10 @@ def _format_system_content(warnings.warn(f"Tool-change block {block_type!r} was dropped: it is only ""valid on a `SystemMessage` sent in place, and this one was "- "hoisted into the top-level `system` field. Use a model that "- "supports mid-conversation system messages and place the "- "message after a human or tool message, either last or before "- f"an AI message (model: {model!r}).",+ "hoisted into the top-level `system` field. Use a model whose "+ "profile sets `mid_conversation_system_messages` and place "+ "the message after a human or tool message, either last or "+ f"before an AI message (model: {model!r}).",UserWarning,stacklevel=stacklevel,)@@ -648,8 +648,9 @@ def _warn_system_message_hoisted(model: str | None) -> None:warnings.warn("A non-leading `SystemMessage` was moved to the top-level `system` field ""and now applies to the entire conversation. To send it in place, use a "- "supported model and place it after a human or tool message, either last "- f"or before an AI message (model: {model!r}).",+ "model whose profile sets `mid_conversation_system_messages` and place "+ "it after a human or tool message, either last or before an AI message "+ f"(model: {model!r}).",UserWarning,stacklevel=3,)@@ -716,8 +717,16 @@ def _format_messages(messages: Sequence[BaseMessage],*,model: str | None,+ mid_conversation_system_messages: bool = False,) -> tuple[str | list[dict] | None, list[dict]]:- """Format messages for Anthropic's API."""+ """Format messages for Anthropic's API.++ Args:+ messages: Messages to format.+ model: The model the request targets, used only in warning text.+ mid_conversation_system_messages: Whether a non-leading system message+ may be sent in place. When `False`, it is hoisted into `system`.+ """system: str | list[dict] | None = Noneformatted_messages: list[dict] = []toolsets: dict[str, str] = {}@@ -736,7 +745,7 @@ def _format_messages(preserve_tool_changes=True,)continue- if _supports_mid_conversation_system_messages(model) and (+ if mid_conversation_system_messages and (pending_systemor _previous_turn_allows_system(formatted_messages[-1] if formatted_messages else None@@ -1143,21 +1152,6 @@ def _reasoning_effort_levels(profile: object) -> tuple[str, ...]:return tuple(levels)-def _supports_mid_conversation_system_messages(model: object) -> bool:- """Return whether the model supports mid-conversation system messages."""- if not isinstance(model, str):- return False- return model.startswith(- (- "claude-fable-5",- "claude-mythos-5",- "claude-opus-4-8",- "claude-opus-5",- "claude-sonnet-5-5",- )- )--def _supports_forced_tool_choice(model: str) -> bool:"""Return whether the model accepts `tool_choice` types `any` and `tool`."""return not model.startswith(@@ -1901,7 +1895,13 @@ class ChatAnthropic(BaseChatModel):})- system, formatted_messages = _format_messages(messages, model=self.model)+ system, formatted_messages = _format_messages(+ messages,+ model=self.model,+ mid_conversation_system_messages=bool(+ (self.profile or {}).get("mid_conversation_system_messages")+ ),+ )if isinstance(system, list) and not system:# Every block was narrowed away (or the message was empty to begin# with). An empty block array carries no instructions, so drop the@@ -3095,7 +3095,11 @@ class ChatAnthropic(BaseChatModel):```""" # noqa: D214formatted_system, formatted_messages = _format_messages(- messages, model=self.model+ messages,+ model=self.model,+ mid_conversation_system_messages=bool(+ (self.profile or {}).get("mid_conversation_system_messages")+ ),)if formatted_system is not None:kwargs["system"] = formatted_systemdiff --git a/libs/partners/anthropic/langchain_anthropic/data/_profiles.py b/libs/partners/anthropic/langchain_anthropic/data/_profiles.pyindex 3ce0c7ebd2..51a744b4ef 100644--- a/libs/partners/anthropic/langchain_anthropic/data/_profiles.py+++ b/libs/partners/anthropic/langchain_anthropic/data/_profiles.py@@ -49,6 +49,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "high",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"claude-fable-5-1": {"name": "Claude Fable 5.1",@@ -83,6 +85,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "high",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"claude-haiku-4-5": {"name": "Claude Haiku 4.5 (latest)",@@ -136,6 +140,54 @@ _PROFILES: dict[str, dict[str, Any]] = {"image_tool_message": True,"tool_call_streaming": True,},+ "claude-haiku-5-5": {+ "name": "Claude Haiku 5.5",+ "release_date": "2026-10-07",+ "last_updated": "2026-10-07",+ "open_weights": False,+ "max_input_tokens": 1000000,+ "max_output_tokens": 128000,+ "text_inputs": True,+ "image_inputs": True,+ "audio_inputs": False,+ "pdf_inputs": True,+ "video_inputs": False,+ "text_outputs": True,+ "image_outputs": False,+ "audio_outputs": False,+ "video_outputs": False,+ "reasoning_output": True,+ "tool_calling": True,+ "structured_output": False,+ "attachment": True,+ "temperature": False,+ "image_url_inputs": True,+ "pdf_tool_message": True,+ "image_tool_message": True,+ "tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,+ },+ "claude-mythos-5": {+ "image_url_inputs": True,+ "pdf_inputs": True,+ "pdf_tool_message": True,+ "image_tool_message": True,+ "structured_output": False,+ "tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,+ },+ "claude-mythos-5-1": {+ "image_url_inputs": True,+ "pdf_inputs": True,+ "pdf_tool_message": True,+ "image_tool_message": True,+ "structured_output": False,+ "tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,+ },"claude-opus-4-5": {"name": "Claude Opus 4.5 (latest)","release_date": "2025-11-24",@@ -300,6 +352,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "high",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"claude-opus-5": {"name": "Claude Opus 5",@@ -334,6 +388,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "high",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"claude-opus-5-5": {"name": "Claude Opus 5.5",@@ -368,6 +424,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "medium",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"claude-sonnet-4-5": {"name": "Claude Sonnet 4.5 (latest)",@@ -487,6 +545,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "high",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": False,},"claude-sonnet-5-5": {"name": "Claude Sonnet 5.5",@@ -522,5 +582,7 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "high",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},}diff --git a/libs/partners/anthropic/langchain_anthropic/data/profile_augmentations.toml b/libs/partners/anthropic/langchain_anthropic/data/profile_augmentations.tomlindex ba4367f1e2..e3ff55caad 100644--- a/libs/partners/anthropic/langchain_anthropic/data/profile_augmentations.toml+++ b/libs/partners/anthropic/langchain_anthropic/data/profile_augmentations.toml@@ -42,34 +42,61 @@ reasoning_effort_default = "high"structured_output = truereasoning_effort_levels = ["low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "high"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."claude-opus-5"]structured_output = truereasoning_effort_levels = ["low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "high"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."claude-opus-5-5"]structured_output = truereasoning_effort_levels = ["low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "medium"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."claude-sonnet-5-5"]structured_output = truetool_choice = falsereasoning_effort_levels = ["low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "high"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."claude-sonnet-5"]structured_output = truereasoning_effort_levels = ["low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "high"+mid_conversation_system_messages = true+mid_conversation_tools = false++[overrides."claude-haiku-5-5"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."claude-fable-5"]structured_output = truereasoning_effort_levels = ["low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "high"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."claude-fable-5-1"]structured_output = truereasoning_effort_levels = ["low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "high"+mid_conversation_system_messages = true+mid_conversation_tools = true++# Not in models.dev (Project Glasswing only), so these entries are the whole profile.+[overrides."claude-mythos-5"]+mid_conversation_system_messages = true+mid_conversation_tools = true++[overrides."claude-mythos-5-1"]+mid_conversation_system_messages = true+mid_conversation_tools = truediff --git a/libs/partners/anthropic/tests/unit_tests/test_chat_models.py b/libs/partners/anthropic/tests/unit_tests/test_chat_models.pyindex f83b66a845..ca8571cb71 100644--- a/libs/partners/anthropic/tests/unit_tests/test_chat_models.py+++ b/libs/partners/anthropic/tests/unit_tests/test_chat_models.py@@ -1721,7 +1721,9 @@ def test__format_messages_with_multiple_system() -> None:},]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert expected_messages == actual_messages@@ -1795,7 +1797,9 @@ def test__format_messages_leading_system_string_content_unchanged() -> None:HumanMessage("Review foo()"),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system == "You are a code reviewer."assert actual_messages == [{"role": "user", "content": "Review foo()"}]@@ -1811,7 +1815,9 @@ def test__format_messages_trailing_system_sent_in_place() -> None:SystemMessage("Every suggestion must include type annotations."),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system == "You are a code reviewer."assert actual_messages == [@@ -1832,7 +1838,9 @@ def test__format_messages_non_leading_system_only_run_sent_in_place() -> None:SystemMessage("Be concise."),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert actual_messages == [@@ -1849,7 +1857,9 @@ def test__format_messages_system_between_user_and_ai_sent_in_place() -> None:AIMessage("Looks fine."),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert actual_messages == [@@ -1872,7 +1882,9 @@ def test__format_messages_system_after_tool_message_sent_in_place() -> None:SystemMessage("Be concise."),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert [message["role"] for message in actual_messages] == [@@ -1909,7 +1921,9 @@ def test__format_messages_system_after_server_tool_result_sent_in_place(SystemMessage("Be concise."),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert [message["role"] for message in actual_messages] == [@@ -1933,7 +1947,9 @@ def test__format_messages_system_after_client_tool_result_hoisted() -> None:]with pytest.warns(UserWarning, match=_HOIST_WARNING):actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system == "Be concise."assert [message["role"] for message in actual_messages] == ["user", "assistant"]@@ -1948,7 +1964,9 @@ def test__format_messages_system_after_plain_ai_turn_hoisted() -> None:]with pytest.warns(UserWarning, match=_HOIST_WARNING):actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system == "Be concise."assert actual_messages == [@@ -1966,7 +1984,9 @@ def test__format_messages_system_followed_by_user_turn_hoisted() -> None:]with pytest.warns(UserWarning, match=_HOIST_WARNING):actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system == "Be concise."assert actual_messages == [@@ -1984,7 +2004,9 @@ def test__format_messages_leading_run_hoisted_and_later_run_in_place() -> None:SystemMessage("Every suggestion must include type annotations."),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system == [{"type": "text", "text": "You are a code reviewer."},@@ -2009,7 +2031,9 @@ def test__format_messages_several_non_contiguous_system_runs_in_place() -> None:SystemMessage("Include type annotations."),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert actual_messages == [@@ -2032,7 +2056,9 @@ def test__format_messages_keeps_both_runs_when_turn_between_is_dropped() -> NoneHumanMessage("Review bar()"),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert actual_messages == [@@ -2056,11 +2082,15 @@ def test__format_messages_two_held_back_runs_before_a_user_turn_raise() -> None:with pytest.raises(ValueError, match=r"Received multiple non-consecutive system messages\."):- _format_messages(messages, model=MID_CONVERSATION_SYSTEM_MODEL)+ _format_messages(+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,+ )-def test__format_messages_non_leading_system_hoisted_on_unsupported_model() -> None:- """Test unsupported models hoist non-leading system messages."""+def test__format_messages_non_leading_system_hoisted_by_default() -> None:+ """Without the capability, it is hoisted, and the warning omits its text."""messages = [HumanMessage("Review foo()"),SystemMessage("Be concise."),@@ -2074,57 +2104,54 @@ def test__format_messages_non_leading_system_hoisted_on_unsupported_model() -> Nassert actual_messages == [{"role": "user", "content": "Review foo()"}]-def test__format_messages_non_leading_system_hoisted_on_sonnet_5() -> None:- """Sonnet 5 is a current model that does not support the feature."""- messages = [- HumanMessage("Review foo()"),- SystemMessage("Be concise."),- ]- with pytest.warns(UserWarning, match=_HOIST_WARNING):- actual_system, actual_messages = _format_messages(- messages, model="claude-sonnet-5"- )- assert actual_system == "Be concise."- assert actual_messages == [{"role": "user", "content": "Review foo()"}]+def test_non_leading_system_in_place_when_profile_declares_it() -> None:+ """The profile decides, so a Bedrock model ID sends it in place too."""+ model = ChatAnthropic(+ model="global.anthropic.claude-opus-5-5",+ profile={"mid_conversation_system_messages": True},+ )+ payload = model._get_request_payload(+ [HumanMessage("Review foo()"), SystemMessage("Be concise.")]+ )+ assert "system" not in payload+ assert payload["messages"][-1] == {"role": "system", "content": "Be concise."}-def test__format_messages_non_leading_system_hoisted_on_platform_model_id() -> None:- """Test platform-prefixed model identifiers do not match."""- messages = [- HumanMessage("Review foo()"),- SystemMessage("Be concise."),- ][email protected]("profile", [{}, {"mid_conversation_system_messages": False}])+def test_non_leading_system_hoisted_when_profile_does_not_declare_it(+ profile: dict,+) -> None:+ """Absent or `False` both hoist, even for a model that supports it."""+ model = ChatAnthropic(model="claude-opus-5-5", profile=profile)with pytest.warns(UserWarning, match=_HOIST_WARNING):- actual_system, _ = _format_messages(- messages, model="us.anthropic.claude-opus-5-v1:0"+ payload = model._get_request_payload(+ [HumanMessage("Review foo()"), SystemMessage("Be concise.")])- assert actual_system == "Be concise."+ assert payload["system"] == "Be concise."+ assert payload["messages"] == [{"role": "user", "content": "Review foo()"}]@pytest.mark.parametrize(- "model",- ["claude-opus-5-1", "claude-fable-5-1", "claude-mythos-5-2", "claude-opus-4-8"],+ ("model", "system_messages", "tools"),+ [+ ("claude-opus-5-5", True, True),+ ("claude-haiku-5-5", True, True),+ # Sonnet 5 accepts a mid-conversation system message but rejects tools in it.+ ("claude-sonnet-5", True, False),+ # Mythos isn't in models.dev, so its profile comes from augmentations alone.+ ("claude-mythos-5", True, True),+ ("claude-mythos-5-1", True, True),+ ("claude-mythos-preview", None, None),+ ("claude-opus-4-5", None, None),+ ],)-def test__format_messages_supported_model_prefixes_match_forward(model: str) -> None:- """A later point release of a supported family needs no edit here."""- messages = [- HumanMessage("Review foo()"),- SystemMessage("Be concise."),- ]- _, actual_messages = _format_messages(messages, model=model)- assert actual_messages[-1] == {"role": "system", "content": "Be concise."}--[email protected]("model", ["claude-opus-4-5", "claude-mythos-preview"])-def test__format_messages_unsupported_model_prefixes_hoist(model: str) -> None:- """Prefixes that must not match: pre-4-8 Opus, and unversioned Mythos."""- messages = [- HumanMessage("Review foo()"),- SystemMessage("Be concise."),- ]- with pytest.warns(UserWarning, match=_HOIST_WARNING):- actual_system, _ = _format_messages(messages, model=model)- assert actual_system == "Be concise."+def test_profile_declares_mid_conversation_capabilities(+ model: str, *, system_messages: bool | None, tools: bool | None+) -> None:+ """Profiles carry the capabilities live probes show each model accepts."""+ profile = ChatAnthropic(model=model).profile or {}+ assert profile.get("mid_conversation_system_messages") is system_messages+ assert profile.get("mid_conversation_tools") is toolsdef test__format_messages_second_unplaceable_system_run_raises() -> None:@@ -2138,7 +2165,11 @@ def test__format_messages_second_unplaceable_system_run_raises() -> None:with pytest.raises(ValueError, match=r"Received multiple non-consecutive system messages\."):- _format_messages(messages, model=MID_CONVERSATION_SYSTEM_MODEL)+ _format_messages(+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,+ )def test__format_messages_system_cache_control_preserved_in_both_paths() -> None:@@ -2150,7 +2181,9 @@ def test__format_messages_system_cache_control_preserved_in_both_paths() -> None}in_place_messages = [HumanMessage("Review foo()"), SystemMessage([block])]actual_system, actual_messages = _format_messages(- in_place_messages, model=MID_CONVERSATION_SYSTEM_MODEL+ in_place_messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert actual_messages[-1] == {"role": "system", "content": [block]}@@ -2167,7 +2200,9 @@ def test__format_messages_system_v1_content_blocks_drop_id_in_place() -> None:SystemMessage(content_blocks=[create_text_block("Be concise.")]),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert actual_messages[-1] == {@@ -2185,6 +2220,7 @@ def test__format_messages_final_assistant_turn_trimmed_past_system() -> None:_, actual_messages = _format_messages([human, AIMessage("thought "), system],model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_messages[-1]["content"] == "thought"@@ -2192,6 +2228,7 @@ def test__format_messages_final_assistant_turn_trimmed_past_system() -> None:_, actual_messages = _format_messages([human, AIMessage([{"type": "text", "text": "thought "}]), system],model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_messages[-1]["content"][0]["text"] == "thought" # type: ignore[index]@@ -2202,6 +2239,7 @@ def test__format_messages_empty_final_assistant_turn_kept_past_system() -> None:_, actual_messages = _format_messages([HumanMessage("Review foo()"), AIMessage(""), SystemMessage("Be concise.")],model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_messages == [{"role": "user", "content": "Review foo()"},@@ -2218,7 +2256,9 @@ def test__format_messages_system_position_judged_against_wire_sequence() -> NoneAIMessage("Looks fine."),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert actual_messages == [@@ -2238,7 +2278,9 @@ def test__format_messages_system_hoisted_when_next_ai_turn_is_dropped() -> None:]with pytest.warns(UserWarning, match=_HOIST_WARNING):actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system == "Be concise."assert actual_messages == [@@ -2272,6 +2314,7 @@ def test__format_messages_system_citations_preserved_in_place() -> None:_, actual_messages = _format_messages([HumanMessage("Review foo()"), SystemMessage([block])],model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_messages[-1] == {"role": "system",@@ -2308,7 +2351,9 @@ def test__format_messages_system_tool_change_block_sent_in_place(AIMessage("Looks fine."),]actual_system, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system is Noneassert actual_messages[1] == {"role": "system", "content": [block]}@@ -2329,8 +2374,14 @@ def test__format_messages_system_tool_change_block_spellings_match(SystemMessage([{"type": "non_standard", "value": block}]),AIMessage("Looks fine."),]- assert _format_messages(bare, model=MID_CONVERSATION_SYSTEM_MODEL) == (- _format_messages(wrapped, model=MID_CONVERSATION_SYSTEM_MODEL)+ assert _format_messages(+ bare, model=MID_CONVERSATION_SYSTEM_MODEL, mid_conversation_system_messages=True+ ) == (+ _format_messages(+ wrapped,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,+ ))@@ -2355,9 +2406,11 @@ def test__format_messages_tool_change_block_survives_content_blocks(assert _format_messages([conversation[0], bare, conversation[1]],model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,) == _format_messages([conversation[0], wrapped, conversation[1]],model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)@@ -2368,7 +2421,11 @@ def test__format_messages_system_tool_change_block_beside_text() -> None:SystemMessage([{"type": "text", "text": "Be concise."}, _TOOL_REMOVAL_BLOCK]),AIMessage("Looks fine."),]- _, actual_messages = _format_messages(messages, model=MID_CONVERSATION_SYSTEM_MODEL)+ _, actual_messages = _format_messages(+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,+ )assert actual_messages[1] == {"role": "system","content": [{"type": "text", "text": "Be concise."}, _TOOL_REMOVAL_BLOCK],@@ -2389,7 +2446,9 @@ def test__format_messages_system_unrecognized_block_dropped_with_warning() -> No]with pytest.warns(UserWarning, match=_UNRECOGNIZED_SYSTEM_BLOCK_WARNING):_, actual_messages = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_messages[1] == {"role": "system",@@ -2410,7 +2469,9 @@ def test__format_messages_leading_system_unrecognized_block_dropped() -> None:]with pytest.warns(UserWarning, match=_UNRECOGNIZED_SYSTEM_BLOCK_WARNING):actual_system, _ = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system == [{"type": "text", "text": "Be concise."}]@@ -2428,6 +2489,7 @@ def test__format_messages_leading_system_tool_change_block_forwarded(actual_system, actual_messages = _format_messages([SystemMessage(content), HumanMessage("Review foo()")],model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_system == [block]assert actual_messages == [{"role": "user", "content": "Review foo()"}]@@ -2462,7 +2524,9 @@ def test__format_messages_system_tool_change_block_stripped_on_illegal_position(]with pytest.warns(UserWarning, match=_TOOL_CHANGE_UNSUPPORTED_WARNING) as record:actual_system, _ = _format_messages(- messages, model=MID_CONVERSATION_SYSTEM_MODEL+ messages,+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)messages_warned = [str(warning.message) for warning in record]assert any(_TOOL_CHANGE_UNSUPPORTED_WARNING in m for m in messages_warned)@@ -2497,6 +2561,7 @@ def test__format_messages_does_not_mutate_input_content() -> None:AIMessage("Looks fine."),],model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert content == before@@ -2508,7 +2573,9 @@ def test__format_messages_human_native_image_block_preserved() -> None:"source": {"type": "base64", "media_type": "image/png", "data": "aGk="},}_, actual_messages = _format_messages(- [HumanMessage([block])], model=MID_CONVERSATION_SYSTEM_MODEL+ [HumanMessage([block])],+ model=MID_CONVERSATION_SYSTEM_MODEL,+ mid_conversation_system_messages=True,)assert actual_messages == [{"role": "user", "content": [block]}]@@ -3113,6 +3180,21 @@ def test_get_num_tokens_from_messages_forwards_block_system_prompt() -> None:assert call_args["system"] == [{"type": "text", "text": "You are a scientist"}]+def test_get_num_tokens_from_messages_keeps_mid_conversation_system_in_place() -> None:+ """Counting reads the profile like a request does, so the turn stays in place."""+ llm = ChatAnthropic(+ model=MODEL_NAME, profile={"mid_conversation_system_messages": True}+ )+ messages = [HumanMessage("Review foo()"), SystemMessage("Be concise.")]++ with patch.object(anthropic, "Client") as _client:+ llm.get_num_tokens_from_messages(messages)++ call_args = _client.return_value.messages.count_tokens.call_args.kwargs+ assert "system" not in call_args+ assert call_args["messages"][-1] == {"role": "system", "content": "Be concise."}++def test_usage_metadata_standardization() -> None:class UsageModel(BaseModel):input_tokens: int = 10diff --git a/libs/partners/anthropic/tests/unit_tests/test_sonnet55.py b/libs/partners/anthropic/tests/unit_tests/test_sonnet55.pyindex 9ad8a745ad..0937ac11c6 100644--- a/libs/partners/anthropic/tests/unit_tests/test_sonnet55.py+++ b/libs/partners/anthropic/tests/unit_tests/test_sonnet55.py@@ -20,7 +20,6 @@ from langchain_core.messages import (from langchain_core.runnables import RunnableBinding, RunnableSequencefrom langchain_anthropic import ChatAnthropic-from langchain_anthropic.chat_models import _format_messagesMODEL = "claude-sonnet-5-5"TOOL = {"name": "answer", "input_schema": {"type": "object", "properties": {}}}@@ -139,7 +138,7 @@ def test_profile_and_defaults() -> None:def test_mid_conversation_system() -> None:- system, messages = _format_messages(+ payload = model()._get_request_payload([SystemMessage("initial"),HumanMessage("hello"),@@ -147,10 +146,14 @@ def test_mid_conversation_system() -> None:AIMessage("answer"),HumanMessage("next"),],- model=MODEL,)- assert system == "initial"- assert [m["role"] for m in messages] == ["user", "system", "assistant", "user"]+ assert payload["system"] == "initial"+ assert [m["role"] for m in payload["messages"]] == [+ "user",+ "system",+ "assistant",+ "user",+ ]@pytest.mark.parametrize("standard", [False, True])@@ -334,11 +337,10 @@ def test_mid_conversation_tool_change() -> None:"type": "tool_addition","tool": {"type": "tool_reference", "name": "answer"},}- _, messages = _format_messages(+ payload = model()._get_request_payload([HumanMessage("hello"), SystemMessage([block]), AIMessage("answer")],- model=MODEL,)- assert messages[1] == {"role": "system", "content": [block]}+ assert payload["messages"][1] == {"role": "system", "content": [block]}def test_default_thinking_stream_preserves_signature() -> None:diff --git a/libs/partners/openai/langchain_openai/chat_models/azure.py b/libs/partners/openai/langchain_openai/chat_models/azure.pyindex f429ff25a4..2371bf297d 100644--- a/libs/partners/openai/langchain_openai/chat_models/azure.py+++ b/libs/partners/openai/langchain_openai/chat_models/azure.py@@ -759,13 +759,16 @@ class AzureChatOpenAI(BaseChatOpenAI):return selfdef _resolve_model_profile(self) -> ModelProfile | None:- if (self.model_name is not None) and (- profile := _get_default_model_profile(self.model_name) or None- ):- return profile- if self.deployment_name is not None:- return _get_default_model_profile(self.deployment_name) or None- return None+ profile: ModelProfile | None = None+ if self.model_name is not None:+ profile = _get_default_model_profile(self.model_name) or None+ if profile is None and self.deployment_name is not None:+ profile = _get_default_model_profile(self.deployment_name) or None+ if profile is not None:+ # The data describes OpenAI's API; `additional_tools` is unverified+ # on Azure's, so make no claim either way.+ profile.pop("mid_conversation_tools", None)+ return profile@propertydef _identifying_params(self) -> dict[str, Any]:diff --git a/libs/partners/openai/langchain_openai/chat_models/base.py b/libs/partners/openai/langchain_openai/chat_models/base.pyindex cca86677ee..739d74da87 100644--- a/libs/partners/openai/langchain_openai/chat_models/base.py+++ b/libs/partners/openai/langchain_openai/chat_models/base.py@@ -1545,7 +1545,16 @@ class BaseChatOpenAI(BaseChatModel):return selfdef _resolve_model_profile(self) -> ModelProfile | None:- return _get_default_model_profile(self.model_name) or None+ profile = _get_default_model_profile(self.model_name) or None+ if (+ profile is not None+ and profile.get("mid_conversation_tools")+ and not self._use_responses_api({})+ ):+ # Only the Responses API carries an `additional_tools` input item.+ # Routing that depends on the request can't be claimed up front.+ profile["mid_conversation_tools"] = False+ return profile@propertydef _default_params(self) -> dict[str, Any]:diff --git a/libs/partners/openai/langchain_openai/chat_models/codex.py b/libs/partners/openai/langchain_openai/chat_models/codex.pyindex 842d48fd31..bec390f0c6 100644--- a/libs/partners/openai/langchain_openai/chat_models/codex.py+++ b/libs/partners/openai/langchain_openai/chat_models/codex.py@@ -37,7 +37,7 @@ if TYPE_CHECKING:from collections.abc import AsyncIteratorfrom langchain_core.callbacks import AsyncCallbackManagerForLLMRun- from langchain_core.language_models import LanguageModelInput+ from langchain_core.language_models import LanguageModelInput, ModelProfilefrom langchain_core.outputs import ChatGenerationChunk, ChatResult@@ -527,6 +527,15 @@ class _ChatOpenAICodex(ChatOpenAI):params["ls_provider"] = "openai-codex"return params+ def _resolve_model_profile(self) -> ModelProfile | None:+ profile = super()._resolve_model_profile()+ if profile is not None:+ # System content is lifted into the string `instructions` field, so+ # it can neither stay in place nor carry a tool definition.+ profile["mid_conversation_system_messages"] = False+ profile["mid_conversation_tools"] = False+ return profile+@propertydef _llm_type(self) -> str:return "openai-codex-chat"diff --git a/libs/partners/openai/langchain_openai/data/_profiles.py b/libs/partners/openai/langchain_openai/data/_profiles.pyindex c14effd36d..1a353ca7f9 100644--- a/libs/partners/openai/langchain_openai/data/_profiles.py+++ b/libs/partners/openai/langchain_openai/data/_profiles.py@@ -152,6 +152,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"image_tool_message": True,"tool_choice": True,"tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-4.1-mini": {"name": "GPT-4.1 mini",@@ -179,6 +181,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"image_tool_message": True,"tool_choice": True,"tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-4.1-nano": {"name": "GPT-4.1 nano",@@ -207,6 +211,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"image_tool_message": True,"tool_choice": True,"tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-4o": {"name": "GPT-4o",@@ -376,6 +382,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"medium","high",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5-chat-latest": {"image_url_inputs": True,@@ -392,6 +400,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5-codex": {"image_url_inputs": True,@@ -408,6 +418,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5-mini": {"name": "GPT-5 Mini",@@ -441,6 +453,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"medium","high",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5-nano": {"name": "GPT-5 Nano",@@ -474,6 +488,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"medium","high",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5-pro": {"name": "GPT-5 Pro",@@ -508,6 +524,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.1": {"name": "GPT-5.1",@@ -541,6 +559,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"medium","high",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.1-chat-latest": {"image_url_inputs": True,@@ -557,6 +577,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.1-codex": {"image_url_inputs": True,@@ -573,6 +595,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.1-codex-max": {"image_url_inputs": True,@@ -589,6 +613,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.1-codex-mini": {"image_url_inputs": True,@@ -605,6 +631,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.2": {"name": "GPT-5.2",@@ -639,6 +667,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.2-chat-latest": {"name": "GPT-5.2 Chat",@@ -674,6 +704,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.2-codex": {"image_url_inputs": True,@@ -689,6 +721,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.2-pro": {"name": "GPT-5.2 Pro",@@ -723,6 +757,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.3-chat-latest": {"name": "GPT-5.3 Chat (latest)",@@ -751,6 +787,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"image_tool_message": True,"tool_choice": True,"tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.3-codex": {"name": "GPT-5.3 Codex",@@ -785,6 +823,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.3-codex-spark": {"name": "GPT-5.3 Codex Spark",@@ -819,6 +859,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.4": {"name": "GPT-5.4",@@ -853,6 +895,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.4-mini": {"name": "GPT-5.4 mini",@@ -887,6 +931,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.4-nano": {"name": "GPT-5.4 nano",@@ -921,6 +967,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.4-pro": {"name": "GPT-5.4 Pro",@@ -955,6 +1003,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"high","xhigh",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.5": {"name": "GPT-5.5",@@ -990,6 +1040,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"xhigh",],"reasoning_effort_default": "medium",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.5-pro": {"name": "GPT-5.5 Pro",@@ -1025,6 +1077,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"xhigh",],"reasoning_effort_default": "medium",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.6": {"name": "GPT-5.6",@@ -1061,6 +1115,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "medium",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.6-luna": {"name": "GPT-5.6 Luna",@@ -1097,6 +1153,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "medium",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.6-sol": {"name": "GPT-5.6 Sol",@@ -1133,6 +1191,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "medium",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-5.6-terra": {"name": "GPT-5.6 Terra",@@ -1169,6 +1229,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "medium",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-6-astra": {"name": "GPT-6 Astra",@@ -1203,6 +1265,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"xhigh","max",],+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-6-luna": {"name": "GPT-6 Luna",@@ -1239,6 +1303,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "medium",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-6-sol": {"name": "GPT-6 Sol",@@ -1275,6 +1341,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"max",],"reasoning_effort_default": "medium",+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-6.1-sol": {"name": "GPT-6.1 Sol",@@ -1302,6 +1370,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"image_tool_message": True,"tool_choice": True,"tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"gpt-daybreak-blue-latest": {"name": "Daybreak Blue",@@ -1571,6 +1641,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"image_tool_message": True,"tool_choice": True,"tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"o3-mini": {"name": "o3-mini",@@ -1599,6 +1671,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"image_tool_message": True,"tool_choice": True,"tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"o3-pro": {"name": "o3-pro",@@ -1626,6 +1700,8 @@ _PROFILES: dict[str, dict[str, Any]] = {"image_tool_message": True,"tool_choice": True,"tool_call_streaming": True,+ "mid_conversation_system_messages": True,+ "mid_conversation_tools": True,},"o4-mini": {"name": "o4-mini",diff --git a/libs/partners/openai/langchain_openai/data/profile_augmentations.toml b/libs/partners/openai/langchain_openai/data/profile_augmentations.tomlindex 3b8a885c8e..cbec17cb5f 100644--- a/libs/partners/openai/langchain_openai/data/profile_augmentations.toml+++ b/libs/partners/openai/langchain_openai/data/profile_augmentations.toml@@ -17,111 +17,203 @@ image_tool_message = false[overrides."gpt-5.1-codex"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.2-pro"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.1-codex-mini"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.2-chat-latest"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.1"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5-nano"]max_input_tokens = 272000reasoning_effort_levels = ["minimal", "low", "medium", "high"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5-codex"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5-mini"]max_input_tokens = 272000reasoning_effort_levels = ["minimal", "low", "medium", "high"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.1-codex-max"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5-chat-latest"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5"]max_input_tokens = 272000reasoning_effort_levels = ["minimal", "low", "medium", "high"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5-pro"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.2"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.1-chat-latest"]max_input_tokens = 272000reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.2-codex"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.3-codex"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.3-codex-spark"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.4"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.4-mini"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.4-nano"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.4-pro"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.5"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]reasoning_effort_default = "medium"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.5-pro"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh"]reasoning_effort_default = "medium"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.6"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "medium"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.6-luna"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "medium"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.6-sol"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "medium"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-5.6-terra"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "medium"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-6-astra"]reasoning_effort_levels = ["low", "medium", "high", "xhigh", "max"]+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-6-sol"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "medium"+mid_conversation_system_messages = true+mid_conversation_tools = true[overrides."gpt-6-luna"]reasoning_effort_levels = ["none", "low", "medium", "high", "xhigh", "max"]reasoning_effort_default = "medium"+mid_conversation_system_messages = true+mid_conversation_tools = true++[overrides."gpt-4.1"]+mid_conversation_system_messages = true+mid_conversation_tools = true++[overrides."gpt-4.1-mini"]+mid_conversation_system_messages = true+mid_conversation_tools = true++[overrides."gpt-4.1-nano"]+mid_conversation_system_messages = true+mid_conversation_tools = true++[overrides."gpt-5.3-chat-latest"]+mid_conversation_system_messages = true+mid_conversation_tools = true++[overrides."gpt-6.1-sol"]+mid_conversation_system_messages = true+mid_conversation_tools = true++[overrides."o3"]+mid_conversation_system_messages = true+mid_conversation_tools = true++[overrides."o3-mini"]+mid_conversation_system_messages = true+mid_conversation_tools = true++[overrides."o3-pro"]+mid_conversation_system_messages = true+mid_conversation_tools = truediff --git a/libs/partners/openai/tests/unit_tests/chat_models/test_azure.py b/libs/partners/openai/tests/unit_tests/chat_models/test_azure.pyindex fda9778ad2..c6cb2e49b3 100644--- a/libs/partners/openai/tests/unit_tests/chat_models/test_azure.py+++ b/libs/partners/openai/tests/unit_tests/chat_models/test_azure.py@@ -203,6 +203,20 @@ def test_profile_resolves_from_model_name() -> None:assert llm.profile["max_input_tokens"] == AZURE_PROFILE_TEST_MAX_INPUT_TOKENS+def test_profile_does_not_claim_mid_conversation_tools() -> None:+ """OpenAI's data doesn't cover Azure's Responses API, so no claim is made."""+ llm = AzureChatOpenAI(+ model=AZURE_PROFILE_TEST_MODEL,+ azure_endpoint="my-base-url",+ api_key=SecretStr("test"),+ api_version="2023-05-15",+ use_responses_api=True,+ )++ assert llm.profile+ assert "mid_conversation_tools" not in llm.profile++def test_profile_resolves_from_model_name_with_custom_deployment_alias() -> None:llm = AzureChatOpenAI(model=AZURE_PROFILE_TEST_MODEL,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 3a00101b4c..882b5ce9bc 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@@ -221,6 +221,28 @@ def test_gpt_6_astra_reasoning_effort_levels() -> None:assert "reasoning_effort_default" not in model.profile+ ("kwargs", "expected"),+ [+ ({"use_responses_api": True}, True),+ # Routes every request to the Responses API.+ ({"reasoning": {"effort": "low"}}, True),+ ({"use_responses_api": False}, False),+ # Routing is decided per request, so it can't be claimed up front.+ ({}, False),+ ],+)+def test_profile_mid_conversation_tools_follow_responses_api(+ kwargs: dict[str, Any], expected: bool+) -> None:+ """Only the Responses API carries an `additional_tools` input item."""+ model = ChatOpenAI(model="gpt-5.6", **kwargs)++ assert model.profile+ assert model.profile["mid_conversation_tools"] is expected+ assert model.profile["mid_conversation_system_messages"] is True++def test_function_message_dict_to_function_message() -> None:content = json.dumps({"result": "Example #1"})name = "test_function"diff --git a/libs/partners/openai/tests/unit_tests/chat_models/test_codex.py b/libs/partners/openai/tests/unit_tests/chat_models/test_codex.pyindex cb5fac4415..a0a17c7256 100644--- a/libs/partners/openai/tests/unit_tests/chat_models/test_codex.py+++ b/libs/partners/openai/tests/unit_tests/chat_models/test_codex.py@@ -669,6 +669,15 @@ def test_ls_params_uses_codex_provider_tag() -> None:assert params["ls_provider"] == "openai-codex"+def test_profile_declares_no_mid_conversation_capabilities() -> None:+ """The Codex API takes system text only, as a string `instructions`."""+ model = _build_model(model="gpt-5.6")++ assert model.profile+ assert model.profile["mid_conversation_system_messages"] is False+ assert model.profile["mid_conversation_tools"] is False++def test_is_not_serializable_due_to_live_token_provider() -> None:assert _ChatOpenAICodex.is_lc_serializable() is False