Home / Function/ test_public_private_state_for_custom_middleware() — langchain Function Reference

test_public_private_state_for_custom_middleware() — langchain Function Reference

Architecture documentation for the test_public_private_state_for_custom_middleware() function in test_framework.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  4e23476c_44ad_48d5_4d38_9fbd2aa1413d["test_public_private_state_for_custom_middleware()"]
  8310d669_2524_e019_e333_8473b50a4990["test_framework.py"]
  4e23476c_44ad_48d5_4d38_9fbd2aa1413d -->|defined in| 8310d669_2524_e019_e333_8473b50a4990
  style 4e23476c_44ad_48d5_4d38_9fbd2aa1413d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_framework.py lines 353–382

def test_public_private_state_for_custom_middleware() -> None:
    """Test public and private state for custom middleware."""

    class CustomState(AgentState[Any]):
        omit_input: Annotated[str, OmitFromInput]
        omit_output: Annotated[str, OmitFromOutput]
        private_state: Annotated[str, PrivateStateAttr]

    class CustomMiddleware(AgentMiddleware[CustomState]):
        state_schema: type[CustomState] = CustomState

        @override
        def before_model(self, state: AgentState[Any], runtime: Runtime) -> dict[str, Any]:
            assert "omit_input" not in state
            assert "omit_output" in state
            assert "private_state" not in state
            return {"omit_input": "test", "omit_output": "test", "private_state": "test"}

    agent = create_agent(model=FakeToolCallingModel(), middleware=[CustomMiddleware()])
    result = agent.invoke(
        {
            "messages": [HumanMessage("Hello")],
            "omit_input": "test in",
            "private_state": "test in",
            "omit_output": "test in",
        }
    )
    assert "omit_input" in result
    assert "omit_output" not in result
    assert "private_state" not in result

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free