test_context_management() — langchain Function Reference
Architecture documentation for the test_context_management() function in test_chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9857cff8_6c23_436c_8b3b_346ed45d1a6a["test_context_management()"] f27640dd_3870_5548_d153_f9504ae1021f["test_chat_models.py"] 9857cff8_6c23_436c_8b3b_346ed45d1a6a -->|defined in| f27640dd_3870_5548_d153_f9504ae1021f style 9857cff8_6c23_436c_8b3b_346ed45d1a6a fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/tests/integration_tests/test_chat_models.py lines 2046–2075
def test_context_management() -> None:
# TODO: update example to trigger action
llm = ChatAnthropic(
model="claude-sonnet-4-5-20250929", # type: ignore[call-arg]
betas=["context-management-2025-06-27"],
context_management={
"edits": [
{
"type": "clear_tool_uses_20250919",
"trigger": {"type": "input_tokens", "value": 10},
"clear_at_least": {"type": "input_tokens", "value": 5},
}
]
},
max_tokens=1024, # type: ignore[call-arg]
)
llm_with_tools = llm.bind_tools(
[{"type": "web_search_20250305", "name": "web_search"}]
)
input_message = {"role": "user", "content": "Search for recent developments in AI"}
response = llm_with_tools.invoke([input_message])
assert response.response_metadata.get("context_management")
# Test streaming
full: BaseMessageChunk | None = None
for chunk in llm_with_tools.stream([input_message]):
assert isinstance(chunk, AIMessageChunk)
full = chunk if full is None else full + chunk
assert isinstance(full, AIMessageChunk)
assert full.response_metadata.get("context_management")
Domain
Subdomains
Source
Frequently Asked Questions
What does test_context_management() do?
test_context_management() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/integration_tests/test_chat_models.py.
Where is test_context_management() defined?
test_context_management() is defined in libs/partners/anthropic/tests/integration_tests/test_chat_models.py at line 2046.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free