Home / Function/ test_counting_middleware() — langchain Function Reference

test_counting_middleware() — langchain Function Reference

Architecture documentation for the test_counting_middleware() function in test_wrap_model_call.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  defe0002_dad0_1c02_cd18_9658f8e0dd1a["test_counting_middleware()"]
  9e73d5df_d4b0_2065_d8b9_d39fc190f3f0["TestBasicWrapModelCall"]
  defe0002_dad0_1c02_cd18_9658f8e0dd1a -->|defined in| 9e73d5df_d4b0_2065_d8b9_d39fc190f3f0
  style defe0002_dad0_1c02_cd18_9658f8e0dd1a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call.py lines 81–103

    def test_counting_middleware(self) -> None:
        """Test middleware that counts model calls."""

        class CountingMiddleware(AgentMiddleware):
            def __init__(self) -> None:
                super().__init__()
                self.call_count = 0

            def wrap_model_call(
                self,
                request: ModelRequest,
                handler: Callable[[ModelRequest], ModelResponse],
            ) -> ModelCallResult:
                self.call_count += 1
                return handler(request)

        counter = CountingMiddleware()
        model = GenericFakeChatModel(messages=iter([AIMessage(content="Reply")]))
        agent = create_agent(model=model, middleware=[counter])

        agent.invoke({"messages": [HumanMessage("Test")]})

        assert counter.call_count == 1

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free