Home / Function/ test_non_reducer_key_conflict_raises() — langchain Function Reference

test_non_reducer_key_conflict_raises() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  4b3a2bdd_eba2_dc85_cdd0_6e1c60df119f["test_non_reducer_key_conflict_raises()"]
  269d8393_43ba_e665_6d86_95d75ce0c396["TestComposition"]
  4b3a2bdd_eba2_dc85_cdd0_6e1c60df119f -->|defined in| 269d8393_43ba_e665_6d86_95d75ce0c396
  style 4b3a2bdd_eba2_dc85_cdd0_6e1c60df119f 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 427–484

    def test_non_reducer_key_conflict_raises(self) -> None:
        """Multiple Commands setting the same non-reducer key raises.

        LastValue channels (like custom_key) can only receive one value per
        step. Inner and outer both setting the same key is an error.
        """

        class MyState(AgentState):
            custom_key: str

        class OuterMiddleware(AgentMiddleware):
            state_schema = MyState  # type: ignore[assignment]

            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="Outer msg", id="outer")],
                            "custom_key": "outer_value",
                        }
                    ),
                )

        class InnerMiddleware(AgentMiddleware):
            state_schema = MyState  # type: ignore[assignment]

            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")],
                            "custom_key": "inner_value",
                        }
                    ),
                )

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

        # Two Commands both setting custom_key (a LastValue channel)
        # in the same step raises InvalidUpdateError
        with pytest.raises(InvalidUpdateError):
            agent.invoke({"messages": [HumanMessage("Hi")]})

Domain

Subdomains

Frequently Asked Questions

What does test_non_reducer_key_conflict_raises() do?
test_non_reducer_key_conflict_raises() 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_non_reducer_key_conflict_raises() defined?
test_non_reducer_key_conflict_raises() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py at line 427.

Analyze Your Own Codebase

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

Try Supermodel Free