Home / Function/ test_inner_command_propagated_through_composition() — langchain Function Reference

test_inner_command_propagated_through_composition() — langchain Function Reference

Architecture documentation for the test_inner_command_propagated_through_composition() function in test_wrap_model_call_state_update.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c243db8c_72a9_edbd_93c9_c31516998280["test_inner_command_propagated_through_composition()"]
  269d8393_43ba_e665_6d86_95d75ce0c396["TestComposition"]
  c243db8c_72a9_edbd_93c9_c31516998280 -->|defined in| 269d8393_43ba_e665_6d86_95d75ce0c396
  style c243db8c_72a9_edbd_93c9_c31516998280 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py lines 374–425

    def test_inner_command_propagated_through_composition(self) -> None:
        """Inner middleware's ExtendedModelResponse command is propagated.

        When inner middleware returns ExtendedModelResponse, its command is
        captured before normalizing to ModelResponse at the composition boundary
        and collected into the final result.
        """

        class OuterMiddleware(AgentMiddleware):
            def wrap_model_call(
                self,
                request: ModelRequest,
                handler: Callable[[ModelRequest], ModelResponse],
            ) -> ModelResponse:
                # Outer sees a ModelResponse from handler (inner's ExtendedModelResponse
                # was normalized at the composition boundary)
                response = handler(request)
                assert isinstance(response, ModelResponse)
                return response

        class InnerMiddleware(AgentMiddleware):
            def wrap_model_call(
                self,
                request: ModelRequest,
                handler: Callable[[ModelRequest], ModelResponse],
            ) -> ExtendedModelResponse:
                response = handler(request)
                return ExtendedModelResponse(
                    model_response=response,
                    command=Command(
                        update={
                            "messages": [
                                HumanMessage(content="Inner msg", id="inner"),
                            ]
                        }
                    ),
                )

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

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

        # Model messages + inner command messages (additive)
        messages = result["messages"]
        assert len(messages) == 3
        assert messages[0].content == "Hi"
        assert messages[1].content == "Hello"
        assert messages[2].content == "Inner msg"

Domain

Subdomains

Frequently Asked Questions

What does test_inner_command_propagated_through_composition() do?
test_inner_command_propagated_through_composition() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py.
Where is test_inner_command_propagated_through_composition() defined?
test_inner_command_propagated_through_composition() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py at line 374.

Analyze Your Own Codebase

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

Try Supermodel Free