test_wrap_tool_call_inner_short_circuits() — langchain Function Reference
Architecture documentation for the test_wrap_tool_call_inner_short_circuits() function in test_wrap_tool_call.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 59522fa7_fcd4_81d9_6e89_c99b974ee722["test_wrap_tool_call_inner_short_circuits()"] e783c6bd_e3d7_7d3b_e64d_d062c5c12013["test_wrap_tool_call.py"] 59522fa7_fcd4_81d9_6e89_c99b974ee722 -->|defined in| e783c6bd_e3d7_7d3b_e64d_d062c5c12013 style 59522fa7_fcd4_81d9_6e89_c99b974ee722 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_tool_call.py lines 618–675
def test_wrap_tool_call_inner_short_circuits() -> None:
"""Test composition when inner middleware short-circuits."""
call_log = []
@wrap_tool_call(name="OuterWrapper")
def outer(
request: ToolCallRequest, handler: Callable[[ToolCallRequest], ToolMessage | Command[Any]]
) -> ToolMessage | Command[Any]:
call_log.append("outer_before")
response = handler(request)
call_log.append("outer_after")
# Wrap inner's response
if isinstance(response, ToolMessage):
return ToolMessage(
content=f"outer_wrapped: {response.content}",
tool_call_id=response.tool_call_id,
name=response.name,
)
return response
@wrap_tool_call(name="InnerShortCircuit")
def inner_short_circuit(
request: ToolCallRequest, handler: Callable[[ToolCallRequest], ToolMessage | Command[Any]]
) -> ToolMessage | Command[Any]:
call_log.append("inner_short_circuit")
# Don't call handler, return custom response
return ToolMessage(
content="inner_result",
tool_call_id=request.tool_call["id"],
name=request.tool_call["name"],
)
model = FakeToolCallingModel(
tool_calls=[
[ToolCall(name="search", args={"query": "test"}, id="1")],
[],
]
)
agent = create_agent(
model=model,
tools=[search],
middleware=[outer, inner_short_circuit],
checkpointer=InMemorySaver(),
)
result = agent.invoke(
{"messages": [HumanMessage("Search")]},
{"configurable": {"thread_id": "test"}},
)
# Verify order: outer_before -> inner short circuits -> outer_after
assert call_log == ["outer_before", "inner_short_circuit", "outer_after"]
tool_messages = [m for m in result["messages"] if isinstance(m, ToolMessage)]
assert len(tool_messages) == 1
assert "outer_wrapped: inner_result" in tool_messages[0].content
Domain
Subdomains
Source
Frequently Asked Questions
What does test_wrap_tool_call_inner_short_circuits() do?
test_wrap_tool_call_inner_short_circuits() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_tool_call.py.
Where is test_wrap_tool_call_inner_short_circuits() defined?
test_wrap_tool_call_inner_short_circuits() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_tool_call.py at line 618.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free