Home / Function/ test_custom_field_via_state_schema() — langchain Function Reference

test_custom_field_via_state_schema() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  c63f428e_384f_b63a_d89a_009ef771bae3["test_custom_field_via_state_schema()"]
  39f408b3_5c60_c805_79c1_928b75d54186["TestCustomStateField"]
  c63f428e_384f_b63a_d89a_009ef771bae3 -->|defined in| 39f408b3_5c60_c805_79c1_928b75d54186
  style c63f428e_384f_b63a_d89a_009ef771bae3 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 148–173

    def test_custom_field_via_state_schema(self) -> None:
        """Middleware updates a custom state field via ExtendedModelResponse."""

        class MyState(AgentState):
            summary: str

        class SummaryMiddleware(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={"summary": "conversation summarized"}),
                )

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

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

        assert result["messages"][-1].content == "Hello"

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free