Home / Function/ test_wrap_tool_call_monitoring_pattern() — langchain Function Reference

test_wrap_tool_call_monitoring_pattern() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  8cd36adc_b546_0ce4_9302_c915ca9774df["test_wrap_tool_call_monitoring_pattern()"]
  e783c6bd_e3d7_7d3b_e64d_d062c5c12013["test_wrap_tool_call.py"]
  8cd36adc_b546_0ce4_9302_c915ca9774df -->|defined in| e783c6bd_e3d7_7d3b_e64d_d062c5c12013
  style 8cd36adc_b546_0ce4_9302_c915ca9774df 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 818–867

def test_wrap_tool_call_monitoring_pattern() -> None:
    """Test monitoring pattern with wrap_tool_call decorator."""
    metrics = []

    @wrap_tool_call
    def monitor_execution(
        request: ToolCallRequest, handler: Callable[[ToolCallRequest], ToolMessage | Command[Any]]
    ) -> ToolMessage | Command[Any]:
        start_time = time.time()
        response = handler(request)
        execution_time = time.time() - start_time

        assert isinstance(request.tool, BaseTool)
        assert isinstance(response, ToolMessage)
        assert isinstance(response.content, str)
        metrics.append(
            {
                "tool": request.tool.name,
                "execution_time": execution_time,
                "success": not response.content.startswith("Error:"),
            }
        )

        return response

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

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

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

    # Metrics should be collected
    assert len(metrics) == 1
    assert metrics[0]["tool"] == "search"
    assert metrics[0]["success"] is True
    assert isinstance(metrics[0]["execution_time"], float)
    assert metrics[0]["execution_time"] >= 0

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free