From 5fd2952ea91ba0f41c3aaa46aad47243d5550f46 Mon Sep 17 00:00:00 2001 From: Starfolk Date: Fri, 17 Jul 2026 16:11:27 +0000 Subject: [PATCH] fix(cohere): drop redundant _try_to_dict pass in tool-call iteration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `_iter_tool_calls` ran `_try_to_dict(output)` (Pydantic `model_dump`) on every chat/stream response just to probe for `tool_calls`, even when none were present. Replaced with `_get_field(output, "tool_calls")`, which already handles both dict and Pydantic-object shapes. Downstream tool-call helpers already read via `_get_field`, so behavior is preserved and the extra recursive walk on top of `SpanImpl.log_internal`'s `bt_safe_deep_copy` is gone. Same spirit as #583 (anthropic) — Braintrust serializes at send/log time, so integrations shouldn't pre-serialize. Co-Authored-By: Claude Opus 4.7 --- py/src/braintrust/integrations/cohere/tracing.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/py/src/braintrust/integrations/cohere/tracing.py b/py/src/braintrust/integrations/cohere/tracing.py index 5bf72cd0..cbd73b4c 100644 --- a/py/src/braintrust/integrations/cohere/tracing.py +++ b/py/src/braintrust/integrations/cohere/tracing.py @@ -632,10 +632,7 @@ def _tool_call_metadata(tool_call: Any) -> dict[str, Any] | None: def _iter_tool_calls(output: Any): if output is None: return - output_dict = output if isinstance(output, dict) else _try_to_dict(output) - if not isinstance(output_dict, dict): - return - tool_calls = output_dict.get("tool_calls") + tool_calls = _get_field(output, "tool_calls") if not isinstance(tool_calls, list): return for tool_call in tool_calls: