Skip to content

Commit e60affc

Browse files
authored
chore(client): deprecate client-side compaction helpers
* deprecate: mark client-side compaction helpers as deprecated Server-side compaction via `edits=[{"type": "compact_20260112"}]` is now the recommended approach. Adds DeprecationWarning when compaction_control is enabled and @deprecated docstrings. * chore: remove auto_compaction example The example demonstrated client-side compaction which is now deprecated in favor of server-side compaction. * chore: align deprecation message wording Use "in a future version" and "in the params passed to tool_runner()" to match TypeScript SDK phrasing.
1 parent 8496c50 commit e60affc

File tree

5 files changed

+45
-96
lines changed

5 files changed

+45
-96
lines changed

examples/auto_compaction.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/anthropic/lib/tools/_beta_compaction_control.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929

3030

3131
class CompactionControl(TypedDict, total=False):
32+
"""Client-side compaction control configuration.
33+
34+
.. deprecated::
35+
Use server-side compaction instead by passing
36+
``edits=[{"type": "compact_20260112"}]`` in the params passed to ``tool_runner()``.
37+
See https://platform.claude.com/docs/en/build-with-claude/compaction
38+
"""
3239
context_token_threshold: int
3340
"""The context token threshold at which to trigger compaction.
3441

src/anthropic/lib/tools/_beta_runner.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ def __init__(
146146
)
147147
self._client = client
148148

149+
if compaction_control is not None and compaction_control.get("enabled"):
150+
warnings.warn(
151+
"The 'compaction_control' parameter is deprecated and will be removed in a future version. "
152+
"Use server-side compaction instead by passing `edits=[{'type': 'compact_20260112'}]` in your "
153+
"the params passed to `tool_runner()`. See https://platform.claude.com/docs/en/build-with-claude/compaction",
154+
DeprecationWarning,
155+
stacklevel=3,
156+
)
157+
149158
self._iterator = self.__run__()
150159
self._last_message: (
151160
Callable[[], ParsedBetaMessage[ResponseFormatT]] | ParsedBetaMessage[ResponseFormatT] | None
@@ -416,6 +425,15 @@ def __init__(
416425
)
417426
self._client = client
418427

428+
if compaction_control is not None and compaction_control.get("enabled"):
429+
warnings.warn(
430+
"The 'compaction_control' parameter is deprecated and will be removed in a future version. "
431+
"Use server-side compaction instead by passing `edits=[{'type': 'compact_20260112'}]` in your "
432+
"the params passed to `tool_runner()`. See https://platform.claude.com/docs/en/build-with-claude/compaction",
433+
DeprecationWarning,
434+
stacklevel=3,
435+
)
436+
419437
self._iterator = self.__run__()
420438
self._last_message: (
421439
Callable[[], Coroutine[None, None, ParsedBetaMessage[ResponseFormatT]]]

tests/lib/tools/test_runners.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -473,24 +473,25 @@ def submit_analysis(summary: str) -> str: # noqa: ARG001
473473
"""Call this LAST with your final analysis."""
474474
return "Analysis submitted"
475475

476-
runner = snapshot_client.beta.messages.tool_runner(
477-
model="claude-sonnet-4-5",
478-
max_tokens=4000,
479-
tools=[submit_analysis],
480-
messages=[
481-
{
482-
"role": "user",
483-
"content": (
484-
"Write a detailed 500 word essay about dogs, cats, and birds. "
485-
"Call the tool submit_analysis with the information about all three animals. "
486-
"Note that you should call it only once at the end of your essay."
487-
),
488-
}
489-
],
490-
betas=["structured-outputs-2025-12-15"],
491-
compaction_control={"enabled": True, "context_token_threshold": 500},
492-
max_iterations=1,
493-
)
476+
with pytest.warns(DeprecationWarning, match="compaction_control.*deprecated"):
477+
runner = snapshot_client.beta.messages.tool_runner(
478+
model="claude-sonnet-4-5",
479+
max_tokens=4000,
480+
tools=[submit_analysis],
481+
messages=[
482+
{
483+
"role": "user",
484+
"content": (
485+
"Write a detailed 500 word essay about dogs, cats, and birds. "
486+
"Call the tool submit_analysis with the information about all three animals. "
487+
"Note that you should call it only once at the end of your essay."
488+
),
489+
}
490+
],
491+
betas=["structured-outputs-2025-12-15"],
492+
compaction_control={"enabled": True, "context_token_threshold": 500},
493+
max_iterations=1,
494+
)
494495

495496
with caplog.at_level(logging.INFO, logger="anthropic.lib.tools._beta_runner"):
496497
next(runner)

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)