Home / Function/ test_compaction() — langchain Function Reference

test_compaction() — langchain Function Reference

Architecture documentation for the test_compaction() function in test_chat_models.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  d0ec0463_29f0_7214_8503_9a4a5d5585bc["test_compaction()"]
  f27640dd_3870_5548_d153_f9504ae1021f["test_chat_models.py"]
  d0ec0463_29f0_7214_8503_9a4a5d5585bc -->|defined in| f27640dd_3870_5548_d153_f9504ae1021f
  style d0ec0463_29f0_7214_8503_9a4a5d5585bc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/partners/anthropic/tests/integration_tests/test_chat_models.py lines 2413–2463

def test_compaction() -> None:
    """Test the compation beta feature."""
    llm = ChatAnthropic(
        model="claude-opus-4-6",  # type: ignore[call-arg]
        betas=["compact-2026-01-12"],
        max_tokens=4096,
        context_management={
            "edits": [
                {
                    "type": "compact_20260112",
                    "trigger": {"type": "input_tokens", "value": 50000},
                    "pause_after_compaction": True,
                }
            ]
        },
    )

    input_message = {
        "role": "user",
        "content": f"Generate a one-sentence summary of this:\n\n{'a' * 100000}",
    }
    messages: list = [input_message]

    first_response = llm.invoke(messages)
    messages.append(first_response)

    second_message = {
        "role": "user",
        "content": f"Generate a one-sentence summary of this:\n\n{'b' * 100000}",
    }
    messages.append(second_message)

    second_response = llm.invoke(messages)
    messages.append(second_response)

    content_blocks = second_response.content_blocks
    compaction_block = next(
        (block for block in content_blocks if block["type"] == "non_standard"),
        None,
    )
    assert compaction_block
    assert compaction_block["value"].get("type") == "compaction"

    third_message = {
        "role": "user",
        "content": "What are we talking about?",
    }
    messages.append(third_message)
    third_response = llm.invoke(messages)
    content_blocks = third_response.content_blocks
    assert [block["type"] for block in content_blocks] == ["text"]

Domain

Subdomains

Frequently Asked Questions

What does test_compaction() do?
test_compaction() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/integration_tests/test_chat_models.py.
Where is test_compaction() defined?
test_compaction() is defined in libs/partners/anthropic/tests/integration_tests/test_chat_models.py at line 2413.

Analyze Your Own Codebase

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

Try Supermodel Free