From 02f33767c113f12426585f6fd86b91d255fc9afe Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 23 Sep 2026 11:22:53 -0400 Subject: [PATCH 1/4] fix(anthropic): capture usage and refusal metadata Preserve fast-mode and fallback-credit usage fields so spans retain the billing context Anthropic reports. Record compaction and context-management request settings, and include refusal stop details to show why a response was refused. Refs #791 --- .../integrations/anthropic/_utils.py | 2 + .../integrations/anthropic/test_anthropic.py | 40 +++++++++++++++++++ .../integrations/anthropic/tracing.py | 3 ++ 3 files changed, 45 insertions(+) diff --git a/py/src/braintrust/integrations/anthropic/_utils.py b/py/src/braintrust/integrations/anthropic/_utils.py index e6c38273..fbd264d9 100644 --- a/py/src/braintrust/integrations/anthropic/_utils.py +++ b/py/src/braintrust/integrations/anthropic/_utils.py @@ -32,6 +32,8 @@ def __getattr__(self, name: str) -> Any: { "service_tier", "inference_geo", + "speed", + "fallback_credit", } ) diff --git a/py/src/braintrust/integrations/anthropic/test_anthropic.py b/py/src/braintrust/integrations/anthropic/test_anthropic.py index 55b531dd..0ae95792 100644 --- a/py/src/braintrust/integrations/anthropic/test_anthropic.py +++ b/py/src/braintrust/integrations/anthropic/test_anthropic.py @@ -268,6 +268,21 @@ def test_get_metadata_from_kwargs_includes_structured_output_params(): } +def test_get_metadata_from_kwargs_includes_compaction_and_context_management(): + metadata = _get_metadata_from_kwargs( + { + "compaction": [{"type": "enabled"}], + "context_management": {"edits": [{"type": "clear_tool_uses_20250919"}]}, + } + ) + + assert metadata == { + "provider": "anthropic", + "compaction": [{"type": "enabled"}], + "context_management": {"edits": [{"type": "clear_tool_uses_20250919"}]}, + } + + def test_log_message_to_span_includes_stop_reason_and_stop_sequence(): span = unittest.mock.MagicMock() message = SimpleNamespace( @@ -276,6 +291,7 @@ def test_log_message_to_span_includes_stop_reason_and_stop_sequence(): model=MODEL, stop_reason="stop_sequence", stop_sequence="DONE", + stop_details=None, usage={ "input_tokens": 11, "output_tokens": 7, @@ -312,6 +328,26 @@ def test_log_message_to_span_includes_stop_reason_and_stop_sequence(): ) +def test_log_message_to_span_includes_refusal_stop_details(): + span = unittest.mock.MagicMock() + message = SimpleNamespace( + role="assistant", + content=[], + model=MODEL, + stop_reason="refusal", + stop_sequence=None, + stop_details={"category": "cyber", "explanation": "unsafe request"}, + usage={}, + ) + + _log_message_to_span(message, span) + + assert span.log.call_args.kwargs["output"]["stop_details"] == { + "category": "cyber", + "explanation": "unsafe request", + } + + def test_extract_anthropic_usage_includes_server_tool_use_metrics_from_objects(): usage = SimpleNamespace( input_tokens=11, @@ -368,6 +404,8 @@ def to_dict(self): } ), "service_tier": "standard", + "speed": "fast", + "fallback_credit": 0.25, } ) @@ -385,6 +423,8 @@ def to_dict(self): } assert metadata == { "usage_service_tier": "standard", + "usage_speed": "fast", + "usage_fallback_credit": 0.25, } diff --git a/py/src/braintrust/integrations/anthropic/tracing.py b/py/src/braintrust/integrations/anthropic/tracing.py index d4030e90..01a5552c 100644 --- a/py/src/braintrust/integrations/anthropic/tracing.py +++ b/py/src/braintrust/integrations/anthropic/tracing.py @@ -72,6 +72,8 @@ def _accumulate_event_accepts_json_bufs() -> bool: "thinking", "output_config", "output_format", + "compaction", + "context_management", ) @@ -1512,6 +1514,7 @@ def _message_output(message, *, include_parsed_output: bool = False): "model": getattr(message, "model", None), "stop_reason": getattr(message, "stop_reason", None), "stop_sequence": getattr(message, "stop_sequence", None), + "stop_details": getattr(message, "stop_details", None), }.items() if v is not None } From 422b42e5d80b41a5b9fab3aa7e35eb5c78ef1efc Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 23 Sep 2026 12:12:42 -0400 Subject: [PATCH 2/4] commit message --- .agents/skills/commit-message/SKILL.md | 169 +++--------------- .../a28062d365df/manifest.json | 27 +++ .../a28062d365df/spec.json | 12 ++ .../a28062d365df/state.json | 17 ++ .../025f8d50cb22/manifest.json | 27 +++ .../025f8d50cb22/spec.json | 12 ++ .../025f8d50cb22/state.json | 17 ++ 7 files changed, 133 insertions(+), 148 deletions(-) create mode 100644 bt-sync/project_logs_037d4d7e-7f0f-4064-ad86-af82550839cd/a28062d365df/manifest.json create mode 100644 bt-sync/project_logs_037d4d7e-7f0f-4064-ad86-af82550839cd/a28062d365df/spec.json create mode 100644 bt-sync/project_logs_037d4d7e-7f0f-4064-ad86-af82550839cd/a28062d365df/state.json create mode 100644 bt-sync/project_logs_56f34894-753c-4407-bc0e-09360a5d69ea/025f8d50cb22/manifest.json create mode 100644 bt-sync/project_logs_56f34894-753c-4407-bc0e-09360a5d69ea/025f8d50cb22/spec.json create mode 100644 bt-sync/project_logs_56f34894-753c-4407-bc0e-09360a5d69ea/025f8d50cb22/state.json diff --git a/.agents/skills/commit-message/SKILL.md b/.agents/skills/commit-message/SKILL.md index 6a44ebf0..23717f27 100644 --- a/.agents/skills/commit-message/SKILL.md +++ b/.agents/skills/commit-message/SKILL.md @@ -1,169 +1,42 @@ --- name: commit-message -description: Generates a meaningful conventional commit message (title + body) from the current diff and conversation context. Use when asked to write, suggest, or generate a commit message for the current changes. +description: Draft a conventional commit message from the current changes and conversation. Use when asked to write, suggest, or generate a commit message; do not commit unless asked. --- # Commit Message Generator -Generate a conventional commit message based on the staged/unstaged diff and the surrounding conversation. +Write a concise, accurate commit message that captures the intent of the current changes. Use the conversation for motivation and constraints; use the diff as evidence. Do not claim behavior or test results the changes do not support. -## Conventional Commits Format +## Gather context -``` -(): - - - -