Home / Function/ test_exclude_tools_prevents_clearing_async() — langchain Function Reference

test_exclude_tools_prevents_clearing_async() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_context_editing.py lines 420–470

async def test_exclude_tools_prevents_clearing_async() -> None:
    """Test async version of excluding tools from clearing."""
    search_call = "call-search"
    calc_call = "call-calc"

    _state, request = _make_state_and_request(
        [
            AIMessage(
                content="",
                tool_calls=[{"id": search_call, "name": "search", "args": {"query": "foo"}}],
            ),
            ToolMessage(content="search-results" * 20, tool_call_id=search_call),
            AIMessage(
                content="",
                tool_calls=[{"id": calc_call, "name": "calculator", "args": {"a": 1, "b": 2}}],
            ),
            ToolMessage(content="42", tool_call_id=calc_call),
        ]
    )

    middleware = ContextEditingMiddleware(
        edits=[
            ClearToolUsesEdit(
                trigger=50,
                clear_at_least=10,
                keep=0,
                exclude_tools=("search",),
                placeholder="[cleared]",
            )
        ],
    )

    modified_request = None

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

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

    assert modified_request is not None
    search_tool = modified_request.messages[1]
    calc_tool = modified_request.messages[3]

    assert isinstance(search_tool, ToolMessage)
    assert search_tool.content == "search-results" * 20

    assert isinstance(calc_tool, ToolMessage)
    assert calc_tool.content == "[cleared]"

Domain

Subdomains

Frequently Asked Questions

What does test_exclude_tools_prevents_clearing_async() do?
test_exclude_tools_prevents_clearing_async() 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_exclude_tools_prevents_clearing_async() defined?
test_exclude_tools_prevents_clearing_async() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_context_editing.py at line 420.
What does test_exclude_tools_prevents_clearing_async() call?
test_exclude_tools_prevents_clearing_async() 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