test_both_sync_and_async_middleware_uses_appropriate_path_async() — langchain Function Reference
Architecture documentation for the test_both_sync_and_async_middleware_uses_appropriate_path_async() function in test_sync_async_wrappers.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD a6069e66_8411_4c0e_4083_61d06a21d070["test_both_sync_and_async_middleware_uses_appropriate_path_async()"] dcfb9efa_1e8c_d646_a0b4_9a9d7afddd2c["TestSyncAsyncMiddlewareComposition"] a6069e66_8411_4c0e_4083_61d06a21d070 -->|defined in| dcfb9efa_1e8c_d646_a0b4_9a9d7afddd2c b32ae1d3_dc67_5e65_9233_c87c7775379d["wrap_tool_call()"] a6069e66_8411_4c0e_4083_61d06a21d070 -->|calls| b32ae1d3_dc67_5e65_9233_c87c7775379d 83212f91_58cd_0efb_7c70_b1044be4f13c["awrap_tool_call()"] a6069e66_8411_4c0e_4083_61d06a21d070 -->|calls| 83212f91_58cd_0efb_7c70_b1044be4f13c style a6069e66_8411_4c0e_4083_61d06a21d070 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 219–263
async def test_both_sync_and_async_middleware_uses_appropriate_path_async(
self,
) -> None:
"""Middleware with both sync and async uses correct implementation per path (async)."""
call_log = []
class BothSyncAsyncMiddleware(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)
async def awrap_tool_call(
self,
request: ToolCallRequest,
handler: Callable[[ToolCallRequest], Awaitable[ToolMessage | Command[Any]]],
) -> ToolMessage | Command[Any]:
call_log.append("async_called")
return await handler(request)
model = FakeToolCallingModel(
tool_calls=[
[ToolCall(name="search", args={"query": "test"}, id="1")],
[],
]
)
agent = create_agent(
model=model,
tools=[search],
middleware=[BothSyncAsyncMiddleware()],
checkpointer=InMemorySaver(),
)
# Async path
call_log.clear()
await agent.ainvoke(
{"messages": [HumanMessage("Search")]},
{"configurable": {"thread_id": "test2"}},
)
assert "async_called" in call_log
assert "sync_called" not in call_log
Domain
Subdomains
Source
Frequently Asked Questions
What does test_both_sync_and_async_middleware_uses_appropriate_path_async() do?
test_both_sync_and_async_middleware_uses_appropriate_path_async() 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_both_sync_and_async_middleware_uses_appropriate_path_async() defined?
test_both_sync_and_async_middleware_uses_appropriate_path_async() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_sync_async_wrappers.py at line 219.
What does test_both_sync_and_async_middleware_uses_appropriate_path_async() call?
test_both_sync_and_async_middleware_uses_appropriate_path_async() calls 2 function(s): awrap_tool_call, wrap_tool_call.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free