CapabilityWire
// event · sdk

Anthropic Python SDK v1.7.0 adds compact_before_next_turn() to tool runner

sdk
vendor: anthropicpublished: 24d agoconfidence: 0.85id: 47e0d51f-1688-4f99-900a-11901c9a7beb

Anthropic's Python SDK v1.7.0 adds a compact_before_next_turn() hook to the tool runner, letting agents compact conversation state before the next model turn. The release also introduces a `group` field with display_name on rate limits (deprecating group_type), Bedrock eventstream error handling, and improved parsing of X|Y union types in responses.

capability delta

An agent can now call compact_before_next_turn() in the Anthropic tool runner to compact conversation/tool state between turns, keeping long tool-using loops within context windows.

curator note

Key agent-relevant change is compact_before_next_turn() in the tool runner — directly targets long agent loops. Rate-limit group field also useful for orchestration.

// install
pip install anthropic==1.7.0
pypi · anthropic @ 1.7.0
// example
python
from anthropic import Anthropic
from anthropic.lib.tools import beta_tool_runner

client = Anthropic()

runner = beta_tool_runner(
    client=client,
    model="claude-sonnet-4-5",
    max_tokens=4096,
    messages=[{"role": "user", "content": "Investigate the repo and summarize."}],
    tools=[...],
)

async for event in runner:
    # Ask the runner to compact accumulated tool output before the next model turn
    if runner.input_tokens > 150_000:
        runner.compact_before_next_turn()
// links
anthropicpythontool-usecontext-compactionrate-limitsbedrock
source: github_release · https://github.com/anthropics/anthropic-sdk-python/releases/tag/v1.7.0