Home / Function/ test_wrap_tool_call_response_modification() — langchain Function Reference

test_wrap_tool_call_response_modification() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  e6da8c02_2546_6cc1_2340_76f44995cbeb["test_wrap_tool_call_response_modification()"]
  e783c6bd_e3d7_7d3b_e64d_d062c5c12013["test_wrap_tool_call.py"]
  e6da8c02_2546_6cc1_2340_76f44995cbeb -->|defined in| e783c6bd_e3d7_7d3b_e64d_d062c5c12013
  style e6da8c02_2546_6cc1_2340_76f44995cbeb 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 330–369

def test_wrap_tool_call_response_modification() -> None:
    """Test modifying tool response with wrap_tool_call decorator."""

    @wrap_tool_call
    def modify_response(
        request: ToolCallRequest, handler: Callable[[ToolCallRequest], ToolMessage | Command[Any]]
    ) -> ToolMessage | Command[Any]:
        response = handler(request)

        # Modify the response
        if isinstance(response, ToolMessage):
            return ToolMessage(
                content=f"MODIFIED: {response.content}",
                tool_call_id=response.tool_call_id,
                name=response.name,
            )
        return response

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

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

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

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

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free