The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
fix(core): Support of 'reasoning' type in 'convert_to_openai_messages' (#33050)
Mohammad Mohtashim33a6def76295
diff --git a/libs/core/langchain_core/messages/utils.py b/libs/core/langchain_core/messages/utils.pyindex ea72ae06ba..d479d41e8b 100644--- a/libs/core/langchain_core/messages/utils.py+++ b/libs/core/langchain_core/messages/utils.py@@ -1385,7 +1385,7 @@ def convert_to_openai_messages(},})- elif block.get("type") == "thinking":+ elif block.get("type") in ["thinking", "reasoning"]:content.append(block)else:err = (diff --git a/libs/core/tests/unit_tests/messages/test_utils.py b/libs/core/tests/unit_tests/messages/test_utils.pyindex bedd518589..5d324401de 100644--- a/libs/core/tests/unit_tests/messages/test_utils.py+++ b/libs/core/tests/unit_tests/messages/test_utils.py@@ -1484,3 +1484,64 @@ def test_get_buffer_string_with_empty_content() -> None:expected = "Human: \nAI: \nSystem: "actual = get_buffer_string(messages)assert actual == expected+++def test_convert_to_openai_messages_reasoning_content() -> None:+ """Test convert_to_openai_messages with reasoning content blocks."""+ # Test reasoning block with empty summary+ msg = AIMessage(content=[{"type": "reasoning", "summary": []}])+ result = convert_to_openai_messages(msg, text_format="block")+ expected = {"role": "assistant", "content": [{"type": "reasoning", "summary": []}]}+ assert result == expected++ # Test reasoning block with summary content+ msg_with_summary = AIMessage(+ content=[+ {+ "type": "reasoning",+ "summary": [+ {"type": "text", "text": "First thought"},+ {"type": "text", "text": "Second thought"},+ ],+ }+ ]+ )+ result_with_summary = convert_to_openai_messages(+ msg_with_summary, text_format="block"+ )+ expected_with_summary = {+ "role": "assistant",+ "content": [+ {+ "type": "reasoning",+ "summary": [+ {"type": "text", "text": "First thought"},+ {"type": "text", "text": "Second thought"},+ ],+ }+ ],+ }+ assert result_with_summary == expected_with_summary++ # Test mixed content with reasoning and text+ mixed_msg = AIMessage(+ content=[+ {"type": "text", "text": "Regular response"},+ {+ "type": "reasoning",+ "summary": [{"type": "text", "text": "My reasoning process"}],+ },+ ]+ )+ mixed_result = convert_to_openai_messages(mixed_msg, text_format="block")+ expected_mixed = {+ "role": "assistant",+ "content": [+ {"type": "text", "text": "Regular response"},+ {+ "type": "reasoning",+ "summary": [{"type": "text", "text": "My reasoning process"}],+ },+ ],+ }+ assert mixed_result == expected_mixed