mirror of
https://github.com/hwchase17/langchain.git
synced 2026-04-24 04:36:46 +00:00
## 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 <eugene@langchain.dev> Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
This commit is contained in:
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user