Home / Function/ test_clear_tool_outputs_and_inputs() — langchain Function Reference

test_clear_tool_outputs_and_inputs() — langchain Function Reference

Architecture documentation for the test_clear_tool_outputs_and_inputs() function in test_context_editing.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  12c7930c_71c2_d5fb_8ec3_6df6687e1ae9["test_clear_tool_outputs_and_inputs()"]
  95bc2c91_0832_8fb7_f8e0_c4d613e022d3["test_context_editing.py"]
  12c7930c_71c2_d5fb_8ec3_6df6687e1ae9 -->|defined in| 95bc2c91_0832_8fb7_f8e0_c4d613e022d3
  d0fac9a0_048c_c4bc_10f5_307a81af0095["_make_state_and_request()"]
  12c7930c_71c2_d5fb_8ec3_6df6687e1ae9 -->|calls| d0fac9a0_048c_c4bc_10f5_307a81af0095
  style 12c7930c_71c2_d5fb_8ec3_6df6687e1ae9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_context_editing.py lines 117–166

def test_clear_tool_outputs_and_inputs() -> None:
    tool_call_id = "call-2"
    ai_message = AIMessage(
        content=[
            {"type": "tool_call", "id": tool_call_id, "name": "search", "args": {"query": "foo"}}
        ],
        tool_calls=[{"id": tool_call_id, "name": "search", "args": {"query": "foo"}}],
    )
    tool_message = ToolMessage(content="x" * 200, tool_call_id=tool_call_id)

    _state, request = _make_state_and_request([ai_message, tool_message])

    edit = ClearToolUsesEdit(
        trigger=50,
        clear_at_least=10,
        clear_tool_inputs=True,
        keep=0,
        placeholder="[cleared output]",
    )
    middleware = ContextEditingMiddleware(edits=[edit])

    modified_request = None

    def mock_handler(req: ModelRequest) -> ModelResponse:
        nonlocal modified_request
        modified_request = req
        return ModelResponse(result=[AIMessage(content="mock response")])

    # Call wrap_model_call which creates a new request with edits
    middleware.wrap_model_call(request, mock_handler)

    assert modified_request is not None
    cleared_ai = modified_request.messages[0]
    cleared_tool = modified_request.messages[1]

    assert isinstance(cleared_tool, ToolMessage)
    assert cleared_tool.content == "[cleared output]"
    assert cleared_tool.response_metadata["context_editing"]["cleared"] is True

    assert isinstance(cleared_ai, AIMessage)
    assert cleared_ai.tool_calls[0]["args"] == {}
    context_meta = cleared_ai.response_metadata.get("context_editing")
    assert context_meta is not None
    assert context_meta["cleared_tool_inputs"] == [tool_call_id]

    # Original request should be unchanged
    request_ai_message = request.messages[0]
    assert isinstance(request_ai_message, AIMessage)
    assert request_ai_message.tool_calls[0]["args"] == {"query": "foo"}
    assert request.messages[1].content == "x" * 200

Domain

Subdomains

Frequently Asked Questions

What does test_clear_tool_outputs_and_inputs() do?
test_clear_tool_outputs_and_inputs() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_context_editing.py.
Where is test_clear_tool_outputs_and_inputs() defined?
test_clear_tool_outputs_and_inputs() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_context_editing.py at line 117.
What does test_clear_tool_outputs_and_inputs() call?
test_clear_tool_outputs_and_inputs() calls 1 function(s): _make_state_and_request.

Analyze Your Own Codebase

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

Try Supermodel Free