langchain - ✅(Solved) Fix ChatOpenai based agent using reasoning and MultiServerMCPClient fails [3 pull requests, 6 comments, 5 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36321Fetched 2026-04-08 01:40:54
View on GitHub
Comments
6
Participants
5
Timeline
31
Reactions
0
Author
Timeline (top)
cross-referenced ×7commented ×6mentioned ×4subscribed ×4

If I create an agent using ChatOpenai and MultiServerMCPClient, and specify reasoning option, invoking the agent fails as soon as the LLM tries to use a tool.

I tried with different openai-compatible backends (vLLM and ollama).

If I use ChatOllama instead ot ChatOpenai, it works. If I remove the reasoning configuration, it works. If I use a tool that is not MultiServerMCPClient (a tool created in the file using langchain.tools.tool decorator), it works

The problem might be an incompatibility between MultiServerMCPClient and a ChatOpenai with configured reasoning.

Error Message

<path_to_project>.venv\Scripts\python.exe <path_to_project>\langchain_test.py Traceback (most recent call last): File "<path_to_project>\langchain_test.py", line 33, in <module> asyncio.run(main()) File "C:\Python312\Lib\asyncio\runners.py", line 195, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\asyncio\runners.py", line 118, in run return self._loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Python312\Lib\asyncio\base_events.py", line 691, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "<path_to_project>\langchain_test.py", line 27, in main result = await agent.ainvoke({"messages": [{"role": "user", "content": "What's the weather like in New York?"}]}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\langgraph\pregel\main.py", line 3462, in ainvoke async for chunk in self.astream( File "<path_to_project>.venv\Lib\site-packages\langgraph\pregel\main.py", line 3111, in astream async for _ in runner.atick( File "<path_to_project>.venv\Lib\site-packages\langgraph\pregel_runner.py", line 304, in atick await arun_with_retry( File "<path_to_project>.venv\Lib\site-packages\langgraph\pregel_retry.py", line 211, in arun_with_retry return await task.proc.ainvoke(task.input, config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\langgraph_internal_runnable.py", line 705, in ainvoke input = await asyncio.create_task( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\langgraph_internal_runnable.py", line 473, in ainvoke ret = await self.afunc(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\langchain\agents\factory.py", line 1349, in amodel_node model_response = await _execute_model_async(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\langchain\agents\factory.py", line 1321, in execute_model_async output = await model.ainvoke(messages) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\langchain_core\runnables\base.py", line 5708, in ainvoke return await self.bound.ainvoke( ^^^^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 477, in ainvoke llm_result = await self.agenerate_prompt( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1212, in agenerate_prompt return await self.agenerate( ^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1170, in agenerate raise exceptions[0] File "<path_to_project>.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1439, in _agenerate_with_cache result = await self._agenerate( ^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1752, in _agenerate _handle_openai_bad_request(e) File "<path_to_project>.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1733, in _agenerate await self.root_async_client.responses.with_raw_response.create( File "<path_to_project>.venv\Lib\site-packages\openai_legacy_response.py", line 384, in wrapped return cast(LegacyAPIResponse[R], await func(*args, **kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\openai\resources\responses\responses.py", line 2565, in create return await self._post( ^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\openai_base_client.py", line 1884, in post return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<path_to_project>.venv\Lib\site-packages\openai_base_client.py", line 1669, in request raise self._make_status_error_from_response(err.response) from None openai.BadRequestError: Error code: 400 - {'error': {'message': 'input[4]: json: cannot unmarshal array into Go struct field ResponsesFunctionCallOutput.output of type string', 'type': 'invalid_request_error', 'param': None, 'code': None}} During task with name 'model' and id '498551a6-76c1-3791-aa56-3650278b531f'

Root Cause

If I create an agent using ChatOpenai and MultiServerMCPClient, and specify reasoning option, invoking the agent fails as soon as the LLM tries to use a tool.

I tried with different openai-compatible backends (vLLM and ollama).

If I use ChatOllama instead ot ChatOpenai, it works. If I remove the reasoning configuration, it works. If I use a tool that is not MultiServerMCPClient (a tool created in the file using langchain.tools.tool decorator), it works

The problem might be an incompatibility between MultiServerMCPClient and a ChatOpenai with configured reasoning.

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Other Dependencies

httpx: 0.28.1 jsonpatch: 1.33 langgraph: 1.1.3 mcp: 1.26.0 ollama: 0.6.1 openai: 2.29.0 opentelemetry-api: 1.40.0 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 python-dotenv: 1.2.2 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 rich: 14.3.3 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 websockets: 16.0 xxhash: 3.6.0 zstandard: 0.25.0

PR fix notes

PR #36335: fix(openai): stringify responses function_call_output tool blocks

Description (problem / solution / changelog)

Fixes #36321

This fixes Responses API tool-output serialization for OpenAI-compatible backends by ensuring function tool outputs are always sent as strings, including MCP-style ToolMessage block content. It also adds a regression test to lock in this behavior.

Read the full contributing guidelines: https://docs.langchain.com/oss/python/contributing/overview

How did you verify your code works?

  • Added regression test in libs/partners/openai/tests/unit_tests/chat_models/test_base.py covering ToolMessage list-block serialization for function_call_output.
  • Ran focused tests:
    • OPENAI_API_KEY=test .venv/bin/python -m pytest -c /dev/null libs/partners/openai/tests/unit_tests/chat_models/test_base.py::test__construct_responses_api_input_tool_message_conversion -q
    • OPENAI_API_KEY=test .venv/bin/python -m pytest -c /dev/null libs/partners/openai/tests/unit_tests/chat_models/test_base.py::test__construct_responses_api_input_tool_message_content_blocks_are_stringified -q
    • OPENAI_API_KEY=test .venv/bin/python -m pytest -c /dev/null libs/partners/openai/tests/unit_tests/chat_models/test_base.py::test__construct_responses_api_input_multiple_message_types -q
  • Ran broader subset:
    • OPENAI_API_KEY=test .venv/bin/python -m pytest -c /dev/null --asyncio-mode=auto libs/partners/openai/tests/unit_tests/chat_models -q
    • Result: 233 passed, 1 xpassed.

Breaking changes

  • None.

AI assistance disclosure

  • This change was implemented with AI coding assistance; I manually reviewed, refined, and validated the final patch and tests.

Areas for careful review

  • libs/partners/openai/langchain_openai/chat_models/base.py around _ensure_valid_tool_message_content to confirm stringification is correct for all function_call_output paths.

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +3/-2)
  • libs/partners/openai/tests/unit_tests/chat_models/test_base.py (modified, +26/-0)

PR #36336: fix(openai): stringify Responses function_call_output tool blocks

Description (problem / solution / changelog)

Fixes #36321

Serialize Responses function tool outputs as strings when ToolMessage content is provided as blocks, and guard conversion so malformed blocks cannot raise KeyError during payload construction. Add regression coverage for both valid block serialization and malformed-block fallback behavior.

Read the full contributing guidelines: https://docs.langchain.com/oss/python/contributing/overview

How did you verify your code works?

  • OPENAI_API_KEY=test .venv/bin/python -m pytest -c /dev/null --asyncio-mode=auto libs/partners/openai/tests/unit_tests/chat_models -q
  • OPENAI_API_KEY=test .venv/bin/python -m pytest -c /dev/null libs/partners/openai/tests/unit_tests/chat_models/test_base.py::test__construct_responses_api_input_tool_message_conversion libs/partners/openai/tests/unit_tests/chat_models/test_base.py::test__construct_responses_api_input_tool_message_content_blocks_are_stringified libs/partners/openai/tests/unit_tests/chat_models/test_base.py::test__construct_responses_api_input_tool_message_malformed_blocks_stringified -q

Social handles (optional)

Twitter: @ LinkedIn: https://linkedin.com/in/

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +20/-13)
  • libs/partners/openai/tests/unit_tests/chat_models/test_base.py (modified, +44/-0)

PR #36343: fix(openai): ensure tool output is string for Responses API function_call_output

Description (problem / solution / changelog)

Description

When using ChatOpenAI with reasoning configuration and MCP tools, the tool output can be a list of content blocks. The OpenAI Responses API requires the 'output' field in 'function_call_output' to be a string, not a list.

This fix ensures that when the tool output is a list, it gets stringified before being passed to the Responses API.

Fixes #36321

Issue

The error message was:

This happened because:

  1. When using ChatOpenAI with reasoning configuration, the Responses API is used
  2. MCP tools return tool output as a list of content blocks
  3. The function returns this list as-is
  4. The Responses API expects the field in to be a string

Fix

Added a check in to stringify the tool output if it's a list before passing it to the .

Testing

Added a new test that verifies tool messages with list content are properly converted to function_call_output with string output.

All existing tests continue to pass.

Changed files

  • libs/partners/openai/langchain_openai/chat_models/base.py (modified, +4/-0)
  • libs/partners/openai/tests/unit_tests/chat_models/test_base.py (modified, +23/-0)

Code Example

import asyncio

from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_openai import ChatOpenAI


async def main():
    chat = ChatOpenAI(base_url="http://localhost:11434/v1",
                      api_key="blank",
                      model="qwen3.5:4b",
                      reasoning={"effort": "low"})

    tools = await MultiServerMCPClient({
        "weather": {
            "transport": "sse",
            "url": "http://localhost:48000/sse"
        }
    }).get_tools()

    agent = create_agent(chat, tools=tools)
    result = await agent.ainvoke({"messages": [{
        "role": "user",
        "content": "What's the weather like in New York?"
    }]})
    print(result)

if __name__ == "__main__":
    asyncio.run(main())

---

<path_to_project>\.venv\Scripts\python.exe <path_to_project>\langchain_test.py 
Traceback (most recent call last):
  File "<path_to_project>\langchain_test.py", line 33, in <module>
    asyncio.run(main())
  File "C:\Python312\Lib\asyncio\runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "<path_to_project>\langchain_test.py", line 27, in main
    result = await agent.ainvoke({"messages": [{"role": "user", "content": "What's the weather like in New York?"}]})
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\pregel\main.py", line 3462, in ainvoke
    async for chunk in self.astream(
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\pregel\main.py", line 3111, in astream
    async for _ in runner.atick(
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\pregel\_runner.py", line 304, in atick
    await arun_with_retry(
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\pregel\_retry.py", line 211, in arun_with_retry
    return await task.proc.ainvoke(task.input, config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\_internal\_runnable.py", line 705, in ainvoke
    input = await asyncio.create_task(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\_internal\_runnable.py", line 473, in ainvoke
    ret = await self.afunc(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain\agents\factory.py", line 1349, in amodel_node
    model_response = await _execute_model_async(request)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain\agents\factory.py", line 1321, in _execute_model_async
    output = await model_.ainvoke(messages)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain_core\runnables\base.py", line 5708, in ainvoke
    return await self.bound.ainvoke(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 477, in ainvoke
    llm_result = await self.agenerate_prompt(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1212, in agenerate_prompt
    return await self.agenerate(
           ^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1170, in agenerate
    raise exceptions[0]
  File "<path_to_project>\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1439, in _agenerate_with_cache
    result = await self._agenerate(
             ^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1752, in _agenerate
    _handle_openai_bad_request(e)
  File "<path_to_project>\.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1733, in _agenerate
    await self.root_async_client.responses.with_raw_response.create(
  File "<path_to_project>\.venv\Lib\site-packages\openai\_legacy_response.py", line 384, in wrapped
    return cast(LegacyAPIResponse[R], await func(*args, **kwargs))
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\openai\resources\responses\responses.py", line 2565, in create
    return await self._post(
           ^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\openai\_base_client.py", line 1884, in post
    return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\openai\_base_client.py", line 1669, in request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': 'input[4]: json: cannot unmarshal array into Go struct field ResponsesFunctionCallOutput.output of type string', 'type': 'invalid_request_error', 'param': None, 'code': None}}
During task with name 'model' and id '498551a6-76c1-3791-aa56-3650278b531f'
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

Reproduction Steps / Example Code (Python)

import asyncio

from langchain.agents import create_agent
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_openai import ChatOpenAI


async def main():
    chat = ChatOpenAI(base_url="http://localhost:11434/v1",
                      api_key="blank",
                      model="qwen3.5:4b",
                      reasoning={"effort": "low"})

    tools = await MultiServerMCPClient({
        "weather": {
            "transport": "sse",
            "url": "http://localhost:48000/sse"
        }
    }).get_tools()

    agent = create_agent(chat, tools=tools)
    result = await agent.ainvoke({"messages": [{
        "role": "user",
        "content": "What's the weather like in New York?"
    }]})
    print(result)

if __name__ == "__main__":
    asyncio.run(main())

Error Message and Stack Trace (if applicable)

<path_to_project>\.venv\Scripts\python.exe <path_to_project>\langchain_test.py 
Traceback (most recent call last):
  File "<path_to_project>\langchain_test.py", line 33, in <module>
    asyncio.run(main())
  File "C:\Python312\Lib\asyncio\runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\asyncio\base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "<path_to_project>\langchain_test.py", line 27, in main
    result = await agent.ainvoke({"messages": [{"role": "user", "content": "What's the weather like in New York?"}]})
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\pregel\main.py", line 3462, in ainvoke
    async for chunk in self.astream(
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\pregel\main.py", line 3111, in astream
    async for _ in runner.atick(
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\pregel\_runner.py", line 304, in atick
    await arun_with_retry(
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\pregel\_retry.py", line 211, in arun_with_retry
    return await task.proc.ainvoke(task.input, config)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\_internal\_runnable.py", line 705, in ainvoke
    input = await asyncio.create_task(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langgraph\_internal\_runnable.py", line 473, in ainvoke
    ret = await self.afunc(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain\agents\factory.py", line 1349, in amodel_node
    model_response = await _execute_model_async(request)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain\agents\factory.py", line 1321, in _execute_model_async
    output = await model_.ainvoke(messages)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain_core\runnables\base.py", line 5708, in ainvoke
    return await self.bound.ainvoke(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 477, in ainvoke
    llm_result = await self.agenerate_prompt(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1212, in agenerate_prompt
    return await self.agenerate(
           ^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1170, in agenerate
    raise exceptions[0]
  File "<path_to_project>\.venv\Lib\site-packages\langchain_core\language_models\chat_models.py", line 1439, in _agenerate_with_cache
    result = await self._agenerate(
             ^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1752, in _agenerate
    _handle_openai_bad_request(e)
  File "<path_to_project>\.venv\Lib\site-packages\langchain_openai\chat_models\base.py", line 1733, in _agenerate
    await self.root_async_client.responses.with_raw_response.create(
  File "<path_to_project>\.venv\Lib\site-packages\openai\_legacy_response.py", line 384, in wrapped
    return cast(LegacyAPIResponse[R], await func(*args, **kwargs))
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\openai\resources\responses\responses.py", line 2565, in create
    return await self._post(
           ^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\openai\_base_client.py", line 1884, in post
    return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<path_to_project>\.venv\Lib\site-packages\openai\_base_client.py", line 1669, in request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': 'input[4]: json: cannot unmarshal array into Go struct field ResponsesFunctionCallOutput.output of type string', 'type': 'invalid_request_error', 'param': None, 'code': None}}
During task with name 'model' and id '498551a6-76c1-3791-aa56-3650278b531f'

Description

If I create an agent using ChatOpenai and MultiServerMCPClient, and specify reasoning option, invoking the agent fails as soon as the LLM tries to use a tool.

I tried with different openai-compatible backends (vLLM and ollama).

If I use ChatOllama instead ot ChatOpenai, it works. If I remove the reasoning configuration, it works. If I use a tool that is not MultiServerMCPClient (a tool created in the file using langchain.tools.tool decorator), it works

The problem might be an incompatibility between MultiServerMCPClient and a ChatOpenai with configured reasoning.

System Info

System Information

OS: Windows OS Version: 10.0.26200 Python Version: 3.12.10 (tags/v3.12.10:0cc8128, Apr 8 2025, 12:21:36) [MSC v.1943 64 bit (AMD64)]

Package Information

langchain_core: 1.2.22 langchain: 1.2.13 langsmith: 0.7.22 langchain_agent: 0.1.1 langchain_mcp_adapters: 0.2.2 langchain_ollama: 1.0.1 langchain_openai: 1.1.12 langgraph_sdk: 0.3.12

Optional packages not installed

deepagents deepagents-cli

Other Dependencies

httpx: 0.28.1 jsonpatch: 1.33 langgraph: 1.1.3 mcp: 1.26.0 ollama: 0.6.1 openai: 2.29.0 opentelemetry-api: 1.40.0 orjson: 3.11.7 packaging: 26.0 pydantic: 2.12.5 python-dotenv: 1.2.2 pyyaml: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 rich: 14.3.3 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 websockets: 16.0 xxhash: 3.6.0 zstandard: 0.25.0

Note : The same problem occurs on ubuntu 24 / python 3.12.10

extent analysis

Fix Plan

The issue seems to be related to the compatibility between MultiServerMCPClient and ChatOpenai with configured reasoning. To fix this, we can try the following steps:

  • Update the langchain_openai package to the latest version.
  • Check the reasoning configuration in ChatOpenai and make sure it is compatible with MultiServerMCPClient.
  • Try removing the reasoning configuration or setting it to a default value.

Here is an example of how to update the reasoning configuration:

chat = ChatOpenAI(
    base_url="http://localhost:11434/v1",
    api_key="blank",
    model="qwen3.5:4b",
    reasoning={"effort": "default"}  # or remove this line to use default reasoning
)

Alternatively, you can try using a different Chat model that is compatible with MultiServerMCPClient, such as ChatOllama.

Verification

To verify that the fix worked, you can run the same code again and check if the agent invocation is successful. You can also add some debug logging to see if the reasoning configuration is being applied correctly.

Extra Tips

  • Make sure to check the documentation for langchain_openai and MultiServerMCPClient to see if there are any known issues or compatibility problems.
  • If you are still experiencing issues, try to isolate the problem by removing other components or configurations and see if the issue persists.
  • Consider opening an issue on the langchain GitHub repository if you are unable to resolve the issue on your own.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING