From ca00f5aed915f49995dfe495f8018f03f48b3ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ChoYongHo=20=7C=20=EC=A1=B0=EC=9A=A9=ED=98=B8?= <117273428+bart0401@users.noreply.github.com> Date: Tue, 14 Oct 2025 05:02:30 +0900 Subject: [PATCH] fix(langchain_v1): export ModelResponse from agents.middleware (#33453) (#33454) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Fixes #33453 `ModelResponse` was defined in `types.py` and included in its `__all__` list, but was not exported from the middleware package's `__init__.py`. This caused `ImportError` when attempting to import it directly from `langchain.agents.middleware`, despite being documented as a public export. ## Changes - Added `ModelResponse` to the import statement in `langchain/agents/middleware/__init__.py` - Added `ModelResponse` to the `__all__` list in `langchain/agents/middleware/__init__.py` - Added comprehensive unit tests in `test_imports.py` to verify the import works correctly ## Issue The original issue reported that the following import failed: ```python from langchain.agents.middleware import ModelResponse # ImportError: cannot import name 'ModelResponse' from 'langchain.agents.middleware' The workaround was to import from the submodule: from langchain.agents.middleware.types import ModelResponse # Workaround Solution After this fix, ModelResponse can be imported directly as documented: from langchain.agents.middleware import ModelResponse # Now works! Testing - ✅ Added 3 unit tests in tests/unit_tests/agents/middleware/test_imports.py - ✅ All tests pass locally: make format, make lint, make test - ✅ Verified ModelResponse is properly exported and importable - ✅ Verified ModelResponse appears in __all__ list Dependencies None. This is a simple export fix with no new dependencies. --------- Co-authored-by: Eugene Yurtsev Co-authored-by: Eugene Yurtsev --- libs/langchain_v1/langchain/agents/middleware/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/langchain_v1/langchain/agents/middleware/__init__.py b/libs/langchain_v1/langchain/agents/middleware/__init__.py index 8a8e22e44e..1b0c50bb8d 100644 --- a/libs/langchain_v1/langchain/agents/middleware/__init__.py +++ b/libs/langchain_v1/langchain/agents/middleware/__init__.py @@ -20,6 +20,7 @@ from .types import ( AgentMiddleware, AgentState, ModelRequest, + ModelResponse, after_agent, after_model, before_agent, @@ -41,6 +42,7 @@ __all__ = [ "ModelCallLimitMiddleware", "ModelFallbackMiddleware", "ModelRequest", + "ModelResponse", "PIIDetectionError", "PIIMiddleware", "PlanningMiddleware",