Home / Function/ test_create_agent_sync_invoke_with_mixed_middleware() — langchain Function Reference

test_create_agent_sync_invoke_with_mixed_middleware() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  961f73c9_e6c4_a00d_0f68_5b7b5f0a264b["test_create_agent_sync_invoke_with_mixed_middleware()"]
  8310d669_2524_e019_e333_8473b50a4990["test_framework.py"]
  961f73c9_e6c4_a00d_0f68_5b7b5f0a264b -->|defined in| 8310d669_2524_e019_e333_8473b50a4990
  f207db9d_3f7a_9c6f_d85c_5e48d79f2dee["abefore_model()"]
  961f73c9_e6c4_a00d_0f68_5b7b5f0a264b -->|calls| f207db9d_3f7a_9c6f_d85c_5e48d79f2dee
  style 961f73c9_e6c4_a00d_0f68_5b7b5f0a264b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_framework.py lines 503–543

def test_create_agent_sync_invoke_with_mixed_middleware() -> None:
    """Test that sync invoke works with mixed sync/async middleware when sync versions exist."""
    calls = []

    class MixedMiddleware(AgentMiddleware):
        def before_model(self, state: AgentState[Any], runtime: Runtime) -> None:
            calls.append("MixedMiddleware.before_model")

        async def abefore_model(self, state: AgentState[Any], runtime: Runtime) -> None:
            calls.append("MixedMiddleware.abefore_model")

        def wrap_model_call(
            self,
            request: ModelRequest,
            handler: Callable[[ModelRequest], ModelResponse],
        ) -> ModelCallResult:
            calls.append("MixedMiddleware.wrap_model_call")
            return handler(request)

        async def awrap_model_call(
            self,
            request: ModelRequest,
            handler: Callable[[ModelRequest], Awaitable[ModelResponse]],
        ) -> ModelCallResult:
            calls.append("MixedMiddleware.awrap_model_call")
            return await handler(request)

    agent = create_agent(
        model=FakeToolCallingModel(),
        tools=[],
        system_prompt="You are a helpful assistant.",
        middleware=[MixedMiddleware()],
    )

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

    # In sync mode, only sync methods should be called
    assert calls == [
        "MixedMiddleware.before_model",
        "MixedMiddleware.wrap_model_call",
    ]

Domain

Subdomains

Frequently Asked Questions

What does test_create_agent_sync_invoke_with_mixed_middleware() do?
test_create_agent_sync_invoke_with_mixed_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_create_agent_sync_invoke_with_mixed_middleware() defined?
test_create_agent_sync_invoke_with_mixed_middleware() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_framework.py at line 503.
What does test_create_agent_sync_invoke_with_mixed_middleware() call?
test_create_agent_sync_invoke_with_mixed_middleware() calls 1 function(s): abefore_model.

Analyze Your Own Codebase

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

Try Supermodel Free