The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
fix(perplexity): include type="message" on Responses input items (#39774)
andrewmadson-pplx09a917e1a3fc
diff --git a/libs/partners/perplexity/langchain_perplexity/chat_models.py b/libs/partners/perplexity/langchain_perplexity/chat_models.pyindex 7ba7deb739..f56fc8ab19 100644--- a/libs/partners/perplexity/langchain_perplexity/chat_models.py+++ b/libs/partners/perplexity/langchain_perplexity/chat_models.py@@ -237,7 +237,9 @@ def _translate_responses_input(message_dicts: list[dict[str, Any]]) -> list[Any]# as `function_call` items.text = _content_to_text(message.get("content"))if text:- translated.append({"role": "assistant", "content": text})+ translated.append(+ {"type": "message", "role": "assistant", "content": text}+ )for tool_call in message["tool_calls"]:function = tool_call.get("function", {})call_id = tool_call.get("id")@@ -274,6 +276,8 @@ def _translate_responses_input(message_dicts: list[dict[str, Any]]) -> list[Any]"output": output,})+ elif role in {"assistant", "system", "user", "developer"}:+ translated.append({**message, "type": "message"})else:translated.append(message)return translateddiff --git a/libs/partners/perplexity/tests/unit_tests/test_chat_models.py b/libs/partners/perplexity/tests/unit_tests/test_chat_models.pyindex ba697d5c89..3ff86eb1c0 100644--- a/libs/partners/perplexity/tests/unit_tests/test_chat_models.py+++ b/libs/partners/perplexity/tests/unit_tests/test_chat_models.py@@ -493,7 +493,7 @@ def test_translate_responses_input_tool_roundtrip() -> None:{"role": "tool", "content": "18C cloudy", "tool_call_id": "call_1"},]translated = _translate_responses_input(message_dicts)- assert translated[0] == {"role": "user", "content": "hi"}+ assert translated[0] == {"type": "message", "role": "user", "content": "hi"}# Empty/None assistant content is dropped; only the function_call item remains.assert translated[1] == {"type": "function_call",@@ -525,11 +525,58 @@ def test_translate_responses_input_keeps_assistant_text_with_tool_calls() -> Non}])- assert translated[0] == {"role": "assistant", "content": "Let me check."}+ assert translated[0] == {+ "type": "message",+ "role": "assistant",+ "content": "Let me check.",+ }assert translated[1]["type"] == "function_call"assert translated[1]["call_id"] == "call_1"+def test_to_responses_payload_marks_message_items_with_type() -> None:+ """Message items use the SDK's `message` union variant."""+ llm = ChatPerplexity(model="openai/gpt-5", api_key="test")+ payload = llm._to_responses_payload(+ [+ {"role": "system", "content": "Be concise."},+ {"role": "user", "content": "What is the weather?"},+ {"role": "assistant", "content": "It is sunny."},+ {+ "role": "assistant",+ "content": "Let me check.",+ "tool_calls": [+ {+ "id": "call_1",+ "type": "function",+ "function": {"name": "get_weather", "arguments": "{}"},+ }+ ],+ },+ {"role": "tool", "content": "18C cloudy", "tool_call_id": "call_1"},+ ],+ {},+ )++ assert payload["input"] == [+ {"type": "message", "role": "system", "content": "Be concise."},+ {"type": "message", "role": "user", "content": "What is the weather?"},+ {"type": "message", "role": "assistant", "content": "It is sunny."},+ {"type": "message", "role": "assistant", "content": "Let me check."},+ {+ "type": "function_call",+ "call_id": "call_1",+ "name": "get_weather",+ "arguments": "{}",+ },+ {+ "type": "function_call_output",+ "call_id": "call_1",+ "output": "18C cloudy",+ },+ ]++def test_to_responses_payload_flattens_tools_and_translates_messages() -> None:"""End-to-end: `_to_responses_payload` flattens tools and translates tool turns."""llm = ChatPerplexity(model="openai/gpt-5", api_key="test", use_responses_api=True)diff --git a/libs/partners/perplexity/tests/unit_tests/test_chat_models_responses.py b/libs/partners/perplexity/tests/unit_tests/test_chat_models_responses.pyindex 0317c1a6c6..3faa3e26b4 100644--- a/libs/partners/perplexity/tests/unit_tests/test_chat_models_responses.py+++ b/libs/partners/perplexity/tests/unit_tests/test_chat_models_responses.py@@ -600,7 +600,7 @@ def test_to_responses_payload_renames_and_drops_keys() -> None:},)- assert payload["input"] == [{"role": "user", "content": "hi"}]+ assert payload["input"] == [{"type": "message", "role": "user", "content": "hi"}]assert payload["model"] == "sonar-pro"assert payload["max_output_tokens"] == 128assert "max_tokens" not in payload