From 0d0498748ad1459c8f763961801d46c2a7f43304 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 4 Aug 2026 18:59:20 -0400 Subject: [PATCH] fix(livekit): disable audio attachments by default Stop collecting and attaching agent playback audio unless BRAINTRUST_CAPTURE_AGENT_AUDIO_ATTACHMENTS is explicitly enabled. Preserve agent_speaking spans and transcripts when attachments are disabled. --- py/src/braintrust/integrations/livekit_agents/__init__.py | 6 +++--- .../integrations/livekit_agents/test_livekit_agents.py | 5 +++-- py/src/braintrust/integrations/livekit_agents/tracing.py | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/py/src/braintrust/integrations/livekit_agents/__init__.py b/py/src/braintrust/integrations/livekit_agents/__init__.py index 42f1db5b..588053f1 100644 --- a/py/src/braintrust/integrations/livekit_agents/__init__.py +++ b/py/src/braintrust/integrations/livekit_agents/__init__.py @@ -5,9 +5,9 @@ def setup_livekit_agents() -> bool: """Set up LiveKit Agents tracing. - Set ``BRAINTRUST_CAPTURE_AGENT_AUDIO_ATTACHMENTS=false`` to omit agent - playback audio attachments while preserving the ``agent_speaking`` spans - and transcripts. + Agent playback audio attachments are disabled by default. Set + ``BRAINTRUST_CAPTURE_AGENT_AUDIO_ATTACHMENTS=true`` to include them on + ``agent_speaking`` spans. """ return LiveKitAgentsIntegration.setup() diff --git a/py/src/braintrust/integrations/livekit_agents/test_livekit_agents.py b/py/src/braintrust/integrations/livekit_agents/test_livekit_agents.py index 78909e9d..1512c7b9 100644 --- a/py/src/braintrust/integrations/livekit_agents/test_livekit_agents.py +++ b/py/src/braintrust/integrations/livekit_agents/test_livekit_agents.py @@ -225,7 +225,7 @@ async def capture_frame(frame): monkeypatch.delenv("BRAINTRUST_CAPTURE_AGENT_AUDIO_ATTACHMENTS", raising=False) assert await tracing.traced_audio_output_capture_frame(capture_frame, output, (frame,), {}) is frame - assert bytes(getattr(output, tracing._PLAYBACK_AUDIO_ATTR)) == frame.data + assert getattr(output, tracing._PLAYBACK_AUDIO_ATTR, None) is None monkeypatch.setenv("BRAINTRUST_CAPTURE_AGENT_AUDIO_ATTACHMENTS", "false") assert await tracing.traced_audio_output_capture_frame(capture_frame, output, (frame,), {}) is frame @@ -238,7 +238,8 @@ async def capture_frame(frame): @pytest.mark.asyncio @pytest.mark.vcr -async def test_livekit_agents_agent_speaking_e2e(memory_logger, livekit_server): +async def test_livekit_agents_agent_speaking_e2e(memory_logger, livekit_server, monkeypatch): + monkeypatch.setenv("BRAINTRUST_CAPTURE_AGENT_AUDIO_ATTACHMENTS", "true") assert setup_livekit_agents() from livekit.agents import Agent, AgentSession diff --git a/py/src/braintrust/integrations/livekit_agents/tracing.py b/py/src/braintrust/integrations/livekit_agents/tracing.py index c3192111..84783e5a 100644 --- a/py/src/braintrust/integrations/livekit_agents/tracing.py +++ b/py/src/braintrust/integrations/livekit_agents/tracing.py @@ -440,7 +440,7 @@ async def traced_audio_output_capture_frame( if getattr(instance, _PLAYBACK_HANDLER_ATTACHED_ATTR, False): if getattr(instance, _PLAYBACK_START_ATTR, None) is None: setattr(instance, _PLAYBACK_START_ATTR, time.time()) - if BraintrustEnv.CAPTURE_AGENT_AUDIO_ATTACHMENTS.get(True): + if BraintrustEnv.CAPTURE_AGENT_AUDIO_ATTACHMENTS.get(False): _capture_playback_audio(instance, args[0] if args else kwargs.get("frame")) else: _clear_playback_audio(instance) @@ -680,7 +680,7 @@ def _pop_playback_audio(obj: Any) -> Attachment | None: audio = getattr(obj, _PLAYBACK_AUDIO_ATTR, None) metadata = getattr(obj, _PLAYBACK_AUDIO_METADATA_ATTR, None) or {} _clear_playback_audio(obj) - if not BraintrustEnv.CAPTURE_AGENT_AUDIO_ATTACHMENTS.get(True) or not audio: + if not BraintrustEnv.CAPTURE_AGENT_AUDIO_ATTACHMENTS.get(False) or not audio: return None sample_rate = metadata.get("sample_rate") num_channels = metadata.get("num_channels")