test_exclude_tools_prevents_clearing() — langchain Function Reference
Architecture documentation for the test_exclude_tools_prevents_clearing() function in test_context_editing.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 4572b7af_9de2_d204_664e_0c4cea09602d["test_exclude_tools_prevents_clearing()"] 95bc2c91_0832_8fb7_f8e0_c4d613e022d3["test_context_editing.py"] 4572b7af_9de2_d204_664e_0c4cea09602d -->|defined in| 95bc2c91_0832_8fb7_f8e0_c4d613e022d3 d0fac9a0_048c_c4bc_10f5_307a81af0095["_make_state_and_request()"] 4572b7af_9de2_d204_664e_0c4cea09602d -->|calls| d0fac9a0_048c_c4bc_10f5_307a81af0095 style 4572b7af_9de2_d204_664e_0c4cea09602d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_context_editing.py lines 223–272
def test_exclude_tools_prevents_clearing() -> None:
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
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
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
Defined In
Source
Frequently Asked Questions
What does test_exclude_tools_prevents_clearing() do?
test_exclude_tools_prevents_clearing() 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() defined?
test_exclude_tools_prevents_clearing() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_context_editing.py at line 223.
What does test_exclude_tools_prevents_clearing() call?
test_exclude_tools_prevents_clearing() 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