Home / Function/ test_wrap_tool_call_short_circuit() — langchain Function Reference

test_wrap_tool_call_short_circuit() — langchain Function Reference

Architecture documentation for the test_wrap_tool_call_short_circuit() function in test_wrap_tool_call.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  2b7b62ca_3cea_e11b_8acb_04e3a7db11d2["test_wrap_tool_call_short_circuit()"]
  e783c6bd_e3d7_7d3b_e64d_d062c5c12013["test_wrap_tool_call.py"]
  2b7b62ca_3cea_e11b_8acb_04e3a7db11d2 -->|defined in| e783c6bd_e3d7_7d3b_e64d_d062c5c12013
  style 2b7b62ca_3cea_e11b_8acb_04e3a7db11d2 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 288–327

def test_wrap_tool_call_short_circuit() -> None:
    """Test short-circuiting tool execution with wrap_tool_call decorator."""
    handler_called = []

    @wrap_tool_call
    def short_circuit(
        request: ToolCallRequest, handler: Callable[[ToolCallRequest], ToolMessage | Command[Any]]
    ) -> ToolMessage | Command[Any]:
        # Don't call handler, return custom response directly
        handler_called.append(False)
        return ToolMessage(
            content="short_circuit_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=[short_circuit],
        checkpointer=InMemorySaver(),
    )

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

    # Handler was not called
    assert len(handler_called) == 1
    tool_messages = [m for m in result["messages"] if isinstance(m, ToolMessage)]
    assert len(tool_messages) == 1
    assert "short_circuit_result" in tool_messages[0].content

Domain

Subdomains

Frequently Asked Questions

What does test_wrap_tool_call_short_circuit() do?
test_wrap_tool_call_short_circuit() 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_short_circuit() defined?
test_wrap_tool_call_short_circuit() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_tool_call.py at line 288.

Analyze Your Own Codebase

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

Try Supermodel Free