test_compaction_control() — anthropic-sdk-python Function Reference
Architecture documentation for the test_compaction_control() function in test_runners.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD dd0a9b14_98b5_81ba_de20_c96c8204e36f["test_compaction_control()"] 6847e1ae_03a4_3e19_19ff_ea808e74d94c["TestSyncRunTools"] dd0a9b14_98b5_81ba_de20_c96c8204e36f -->|defined in| 6847e1ae_03a4_3e19_19ff_ea808e74d94c style dd0a9b14_98b5_81ba_de20_c96c8204e36f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/lib/tools/test_runners.py lines 405–511
def test_compaction_control(
self, client: Anthropic, respx_mock: MockRouter, caplog: pytest.LogCaptureFixture
) -> None:
@beta_tool
def submit_analysis(summary: str) -> str: # noqa: ARG001
"""Call this LAST with your final analysis."""
return "Analysis submitted"
def tool_runner(client: Anthropic) -> BetaToolRunner[None]:
runner = client.beta.messages.tool_runner(
model="claude-sonnet-4-5",
max_tokens=4000,
tools=[submit_analysis],
messages=[
{
"role": "user",
"content": (
"Write a detailed 500 word essay about dogs, cats, and birds. "
"Call the tool submit_analysis with the information about all three animals. "
"Note that you should call it only once at the end of your essay."
),
}
],
betas=["structured-outputs-2025-12-15"],
compaction_control={"enabled": True, "context_token_threshold": 500},
max_iterations=1,
)
next(runner)
runner.until_done()
return runner
with caplog.at_level(logging.INFO, logger="anthropic.lib.tools._beta_runner"):
runner = make_snapshot_request(
tool_runner,
content_snapshot=external("uuid:ab7b2edd-9c2d-4f53-9c04-92bb659b9caa.json"),
path="/v1/messages",
mock_client=client,
respx_mock=respx_mock,
)
messages = list(runner._params["messages"])
assert len(messages) == 1
assert messages[0]["role"] == "user"
content = list(messages[0]["content"])[0]
assert isinstance(content, dict)
assert content["type"] == "text"
assert content["text"] == snapshot("""\
<summary>
## 1. Task Overview
The user requests a 500-word essay about dogs, cats, and birds, followed by a single call to the `submit_analysis` tool at the end containing information about all three animals. \n\
**Key constraints:**
- Essay must be detailed and approximately 500 words
- Must cover all three animals: dogs, cats, and birds
- Tool `submit_analysis` must be called exactly once, at the end
- Tool call should contain information about all three animals
## 2. Current State
**Completed:** Nothing has been completed yet.
**Status:** The task has been acknowledged but no essay has been written and no tool has been called.
**Artifacts produced:** None yet.
## 3. Important Discoveries
**Technical requirements:**
- Need to understand the parameters/schema for `submit_analysis` tool (not yet verified)
- Must structure the tool call to include data about all three animal types in a single invocation
**Approach to take:**
- Write a comprehensive 500-word essay discussing dogs, cats, and birds
- Essay should cover characteristics, behaviors, and comparisons between the three
- Extract/organize key information about each animal for the tool call
- Call `submit_analysis` once with consolidated data about all three animals
## 4. Next Steps
1. **Write the 500-word essay** covering:
- Dogs: characteristics, behavior, relationship with humans
- Cats: characteristics, behavior, relationship with humans
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_compaction_control() do?
test_compaction_control() is a function in the anthropic-sdk-python codebase, defined in tests/lib/tools/test_runners.py.
Where is test_compaction_control() defined?
test_compaction_control() is defined in tests/lib/tools/test_runners.py at line 405.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free