From 4a01cd78b254c7955306d4f31151d4050ba4a840 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 5 Oct 2026 11:29:14 -0400 Subject: [PATCH] fix(anthropic): allow variable compaction stop reasons Assert that compaction request metadata is captured without requiring a specific provider stop reason, and refresh the latest cassette. Fixes #864 --- ...s_create_captures_compaction_metadata.yaml | 41 +++++++------------ .../integrations/anthropic/test_anthropic.py | 3 +- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/py/src/braintrust/integrations/anthropic/cassettes/latest/test_anthropic_beta_messages_create_captures_compaction_metadata.yaml b/py/src/braintrust/integrations/anthropic/cassettes/latest/test_anthropic_beta_messages_create_captures_compaction_metadata.yaml index 387abfd33..34cdae4de 100644 --- a/py/src/braintrust/integrations/anthropic/cassettes/latest/test_anthropic_beta_messages_create_captures_compaction_metadata.yaml +++ b/py/src/braintrust/integrations/anthropic/cassettes/latest/test_anthropic_beta_messages_create_captures_compaction_metadata.yaml @@ -20,7 +20,7 @@ interactions: host: - api.anthropic.com user-agent: - - Anthropic/Python 1.8.0 + - Anthropic/Python 1.11.0 x-stainless-arch: - arm64 x-stainless-async: @@ -30,7 +30,7 @@ interactions: x-stainless-os: - MacOS x-stainless-package-version: - - 1.8.0 + - 1.11.0 x-stainless-read-timeout: - '600' x-stainless-retry-count: @@ -45,20 +45,7 @@ interactions: uri: https://api.anthropic.com/v1/messages?beta=true response: body: - string: "{\"model\":\"claude-opus-5\",\"id\":\"msg_011CfWMC5nMK7TUz5Ykq2uAo\",\"type\":\"message\",\"role\":\"assistant\",\"content\":[{\"type\":\"compaction\",\"content\":\"**Context - of conversation so far:**\\n\\nThe user provided a single short task: \\\"Summarize - this sentence: compaction captures request metadata.\\\" No other content, - files, tools, or prior work exist in this conversation \u2014 this is the - entire exchange to date.\\n\\n**Task status:** The summarization request is - trivial and essentially self-contained. A suitable response would be a condensed - restatement such as: \\\"Compaction records/preserves metadata about requests.\\\" - (Alternative phrasings: \\\"Request metadata is captured during compaction,\\\" - or simply \\\"Compaction logs request metadata.\\\")\\n\\n**Notes for continuing:**\\n- - No additional constraints (length, format, tone) were specified by the user.\\n- - No ambiguity has been raised or clarified regarding the technical meaning - of \\\"compaction\\\" (e.g., database/log compaction vs. conversation-history - compaction); if the user follows up, it may be worth asking or noting that - the sentence's domain is unspecified.\\n- Nothing else is pending.\",\"signature\":\"CAISywgKHggSGALyARdjb21wYWN0aW9uX3NpZ25hdHVyZV92MRIM6ArCjWZx0nueB9sNGgzDlWrWgJRPBV1lqroiMBFOfRiy8pFJSFQc+f3AelXVGK7oojeS2mtt/XP1/G8khL4TrMyvKCUohex4aBJUNSraB8KCbvKx2nMItFuciCqfCFt+i/ZbTKfqR4pIVpSOvuu0K4XKFl2HAazXI1VTUZEr7bnPy/+gfIE1FTzKguflaOiHoheLzgTUwqTvMvjsZ66fiWzFQgpeQDWvbQMyVS6ctwCQVu/cjvlcad8JOauqA9mmiuwWqh2a2qCbuOZb1rVLz/GFDLRRJuWFkZaLDLCT3ow1MBqbMyFr06lQPyIE80+sOOoiAdh8eLZSWAgwkYtHEn1sFNBbJTcfqbz78XLXbUUzRQc4XRmqLmNLcl9Dg3s8GaKk9QRfqwBcT1Quw5tLpNAxGdQFpN8ljS9sYh9agJuPwWA16qhfAlPBtx51JirX8SYtb+to31Xlv0MmSwF7nRloamtFqiX40PQuhHv1IMJZqcE09vfCarB9cvDmvVtg+ujXWwloaqBJw3uylEG4HSvQ8N41Z1H1eGW3KnrUsTeRriVYmrmkmCEvS8r0DVJunPrBLuWqQbXrC+PT9mX1wzkdRZAJJDubVIQ1nWwi8M4yVbE7iajBdbuINZqwUaNoK0dqlnQSkJ6TC3XCrHsceSYzIGswwiy3IKrUIuZ5XjzNLAv3Iu9vL2LSsvzB5LtO4gxT6DD3ZKd5FsfJa/8dJC6XtEl5N5BGRSZwoCpd80oMjTIFrc+9CgfpO7Q8boFuA5Is2/NyacutlNgqcv2wV+7tFLHtSYIs4KSKWSCQRCp6J3RUTPaV3FbkrJjmNOkGWLxB8fyP7aNTZA3XA5Aur0j2P3JuFWISXQH3xwdgVTMSBpIne56LyTRoD2tNULKbb+K3v8udC3KVvFr6qEn4rO7vaO4S8WHKXXtWm95qb4sjhpnFH19lJdsModymiaoZD4NxGzW4Fzp8ms3M+oXaQYuNKu4qjGob+CpGgR6qOADNc6Kj/ZfUno10771XVmRpkxmav9HC4GfJ0kS8H4ydX5t34m4cYJTveGvrroLn33ODwW+KGf5Ghd+3QZP1DbzJmispLLfZ5s74QCqV3GYtq7JF0Jd2pWWVjVpisE18xGnDDKJ4e8Es4pJ39wuvMTL2j0akmf5JJn3se4EwEtF2rUaqS3UaKXtu7Dx7jAMPY6yrvwZVE+oWf2CRhb53uelDhYJ1W1ByRBhdLvdF/u4bun9BMzThCYIS8/Qtazkz2LsH2oseigMjSSyiN9s7RzY100mGBPtrJfEgi6jdTCqhicTS8+BOrweBpC2hUQWzyCKHrIeJSwVrEIoU3m7LPNDad+TXbb2e7LllKrepUsz3L5u7IGYjL9gHjSF7fyK2+uSCeFC3fmt+q7ANBwDt9dqzDL3cXr1ePuXaGAs=\"}],\"container\":null,\"stop_reason\":\"compaction\",\"stop_sequence\":null,\"stop_details\":null,\"usage\":{\"input_tokens\":0,\"cache_creation_input_tokens\":0,\"cache_read_input_tokens\":0,\"cache_creation\":{\"ephemeral_5m_input_tokens\":0,\"ephemeral_1h_input_tokens\":0},\"iterations\":[{\"input_tokens\":82,\"output_tokens\":471,\"cache_read_input_tokens\":0,\"cache_creation_input_tokens\":0,\"cache_creation\":{\"ephemeral_5m_input_tokens\":0,\"ephemeral_1h_input_tokens\":0},\"type\":\"compaction\"}],\"output_tokens\":0,\"service_tier\":\"standard\",\"inference_geo\":\"global\"},\"diagnostics\":null}" + string: '{"model":"claude-opus-5","id":"msg_011CfjKiacbvcs4ZJrcU3NXE","type":"message","role":"assistant","content":[],"container":null,"stop_reason":"max_tokens","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":0,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"iterations":[{"input_tokens":82,"output_tokens":512,"cache_read_input_tokens":0,"cache_creation_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":0},"type":"compaction"}],"output_tokens":0,"service_tier":"standard","inference_geo":"global"},"diagnostics":null}' headers: anthropic-organization-id: - 27796668-7351-40ac-acc4-024aee8995a5 @@ -67,49 +54,49 @@ interactions: anthropic-ratelimit-input-tokens-remaining: - '10000000' anthropic-ratelimit-input-tokens-reset: - - '2026-09-28T18:57:32Z' + - '2026-10-05T15:25:56Z' anthropic-ratelimit-output-tokens-limit: - '2000000' anthropic-ratelimit-output-tokens-remaining: - - '2000000' + - '1999000' anthropic-ratelimit-output-tokens-reset: - - '2026-09-28T18:57:32Z' + - '2026-10-05T15:25:56Z' anthropic-ratelimit-requests-limit: - '20000' anthropic-ratelimit-requests-remaining: - '19999' anthropic-ratelimit-requests-reset: - - '2026-09-28T18:57:26Z' + - '2026-10-05T15:25:49Z' anthropic-ratelimit-tokens-limit: - '12000000' anthropic-ratelimit-tokens-remaining: - - '12000000' + - '11999000' anthropic-ratelimit-tokens-reset: - - '2026-09-28T18:57:32Z' + - '2026-10-05T15:25:56Z' anthropic-workspace-id: - wrkspc_018bFG1FgNVWqx5pthtdGTzS cf-cache-status: - DYNAMIC cf-ray: - - a424f94849aba217-YYZ + - a45d70efbbd9961e-YYZ connection: - keep-alive content-length: - - '3181' + - '663' content-security-policy: - default-src 'none'; frame-ancestors 'none' content-type: - application/json date: - - Mon, 28 Sep 2026 18:57:32 GMT + - Mon, 05 Oct 2026 15:25:56 GMT request-id: - - req_011CfWMC5WUtQwZpSxAKXHpn + - req_011CfjKiaMy6FZm3khHEnUmV server: - cloudflare strict-transport-security: - max-age=31536000; includeSubDomains; preload traceresponse: - - 00-69a0e9f7960e7fc4a05623358b24afb6-f74323de8715e4e1-01 + - 00-2b968b75ad0752e4a87c71d84f36ea3b-19523bb40ca8e817-01 transfer-encoding: - chunked vary: diff --git a/py/src/braintrust/integrations/anthropic/test_anthropic.py b/py/src/braintrust/integrations/anthropic/test_anthropic.py index 802792680..2de40b295 100644 --- a/py/src/braintrust/integrations/anthropic/test_anthropic.py +++ b/py/src/braintrust/integrations/anthropic/test_anthropic.py @@ -331,7 +331,7 @@ def test_anthropic_beta_messages_create_captures_compaction_metadata(memory_logg pytest.skip("On-demand compaction requires the latest Anthropic API") client = wrap_anthropic(_get_client()) - response = client.beta.messages.create( + client.beta.messages.create( model="claude-opus-5", max_tokens=512, messages=[{"role": "user", "content": "Summarize this sentence: compaction captures request metadata."}], @@ -342,7 +342,6 @@ def test_anthropic_beta_messages_create_captures_compaction_metadata(memory_logg span = find_span_by_name(memory_logger.pop(), "anthropic.messages.create") assert "error" not in span assert span["metadata"]["compaction"] == {"type": "summarize"} - assert response.stop_reason == "compaction" @pytest.mark.vcr(match_on=["method", "scheme", "host", "port", "path", "body"])