Home / Class/ TestBackwardsCompatibility Class — langchain Architecture

TestBackwardsCompatibility Class — langchain Architecture

Architecture documentation for the TestBackwardsCompatibility class in test_wrap_model_call_state_update.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  2bf07a68_4a56_38b0_435c_b9917d8b0fd3["TestBackwardsCompatibility"]
  949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e["AgentMiddleware"]
  2bf07a68_4a56_38b0_435c_b9917d8b0fd3 -->|extends| 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e
  08361e76_a995_1e57_f200_e292474e2f00["test_wrap_model_call_state_update.py"]
  2bf07a68_4a56_38b0_435c_b9917d8b0fd3 -->|defined in| 08361e76_a995_1e57_f200_e292474e2f00
  36204887_ef1c_7118_b2dc_38c1c6574b66["test_model_response_return_unchanged()"]
  2bf07a68_4a56_38b0_435c_b9917d8b0fd3 -->|method| 36204887_ef1c_7118_b2dc_38c1c6574b66
  b4fa90a3_123c_c3a9_1c8c_a21800dc32e8["test_ai_message_return_unchanged()"]
  2bf07a68_4a56_38b0_435c_b9917d8b0fd3 -->|method| b4fa90a3_123c_c3a9_1c8c_a21800dc32e8
  a901da46_5501_86ef_20c3_8c6c542eecec["test_no_middleware_unchanged()"]
  2bf07a68_4a56_38b0_435c_b9917d8b0fd3 -->|method| a901da46_5501_86ef_20c3_8c6c542eecec

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py lines 198–247

class TestBackwardsCompatibility:
    """Test that existing ModelResponse and AIMessage returns still work."""

    def test_model_response_return_unchanged(self) -> None:
        """Existing middleware returning ModelResponse works identically."""

        class PassthroughMiddleware(AgentMiddleware):
            def wrap_model_call(
                self,
                request: ModelRequest,
                handler: Callable[[ModelRequest], ModelResponse],
            ) -> ModelResponse:
                return handler(request)

        model = GenericFakeChatModel(messages=iter([AIMessage(content="Hello")]))
        agent = create_agent(model=model, middleware=[PassthroughMiddleware()])

        result = agent.invoke({"messages": [HumanMessage("Hi")]})

        assert len(result["messages"]) == 2
        assert result["messages"][1].content == "Hello"

    def test_ai_message_return_unchanged(self) -> None:
        """Existing middleware returning AIMessage works identically."""

        class ShortCircuitMiddleware(AgentMiddleware):
            def wrap_model_call(
                self,
                request: ModelRequest,
                handler: Callable[[ModelRequest], ModelResponse],
            ) -> AIMessage:
                return AIMessage(content="Short-circuited")

        model = GenericFakeChatModel(messages=iter([AIMessage(content="Should not appear")]))
        agent = create_agent(model=model, middleware=[ShortCircuitMiddleware()])

        result = agent.invoke({"messages": [HumanMessage("Hi")]})

        assert len(result["messages"]) == 2
        assert result["messages"][1].content == "Short-circuited"

    def test_no_middleware_unchanged(self) -> None:
        """Agent without middleware works identically."""
        model = GenericFakeChatModel(messages=iter([AIMessage(content="Hello")]))
        agent = create_agent(model=model)

        result = agent.invoke({"messages": [HumanMessage("Hi")]})

        assert len(result["messages"]) == 2
        assert result["messages"][1].content == "Hello"

Extends

Frequently Asked Questions

What is the TestBackwardsCompatibility class?
TestBackwardsCompatibility is a class in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py.
Where is TestBackwardsCompatibility defined?
TestBackwardsCompatibility is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py at line 198.
What does TestBackwardsCompatibility extend?
TestBackwardsCompatibility extends AgentMiddleware.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free