Home / Function/ test_sync_only_middleware_works_on_sync_path() — langchain Function Reference

test_sync_only_middleware_works_on_sync_path() — langchain Function Reference

Architecture documentation for the test_sync_only_middleware_works_on_sync_path() function in test_sync_async_wrappers.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  d99b55fb_4f76_1c09_3af4_78356671f501["test_sync_only_middleware_works_on_sync_path()"]
  dcfb9efa_1e8c_d646_a0b4_9a9d7afddd2c["TestSyncAsyncMiddlewareComposition"]
  d99b55fb_4f76_1c09_3af4_78356671f501 -->|defined in| dcfb9efa_1e8c_d646_a0b4_9a9d7afddd2c
  b32ae1d3_dc67_5e65_9233_c87c7775379d["wrap_tool_call()"]
  d99b55fb_4f76_1c09_3af4_78356671f501 -->|calls| b32ae1d3_dc67_5e65_9233_c87c7775379d
  style d99b55fb_4f76_1c09_3af4_78356671f501 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_sync_async_wrappers.py lines 38–73

    def test_sync_only_middleware_works_on_sync_path(self) -> None:
        """Middleware with only sync wrap_tool_call works on sync path."""
        call_log = []

        class SyncOnlyMiddleware(AgentMiddleware):
            def wrap_tool_call(
                self,
                request: ToolCallRequest,
                handler: Callable[[ToolCallRequest], ToolMessage | Command[Any]],
            ) -> ToolMessage | Command[Any]:
                call_log.append("sync_called")
                return handler(request)

        model = FakeToolCallingModel(
            tool_calls=[
                [ToolCall(name="search", args={"query": "test"}, id="1")],
                [],
            ]
        )

        agent = create_agent(
            model=model,
            tools=[search],
            middleware=[SyncOnlyMiddleware()],
            checkpointer=InMemorySaver(),
        )

        result = agent.invoke(
            {"messages": [HumanMessage("Search")]},
            {"configurable": {"thread_id": "test"}},
        )

        assert "sync_called" in call_log
        tool_messages = [m for m in result["messages"] if isinstance(m, ToolMessage)]
        assert len(tool_messages) == 1
        assert "Results for: test" in tool_messages[0].content

Domain

Subdomains

Frequently Asked Questions

What does test_sync_only_middleware_works_on_sync_path() do?
test_sync_only_middleware_works_on_sync_path() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_sync_async_wrappers.py.
Where is test_sync_only_middleware_works_on_sync_path() defined?
test_sync_only_middleware_works_on_sync_path() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_sync_async_wrappers.py at line 38.
What does test_sync_only_middleware_works_on_sync_path() call?
test_sync_only_middleware_works_on_sync_path() calls 1 function(s): wrap_tool_call.

Analyze Your Own Codebase

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

Try Supermodel Free