superbryn-pipecat-observer 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SuperBryn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,418 @@
1
+ Metadata-Version: 2.4
2
+ Name: superbryn-pipecat-observer
3
+ Version: 0.1.1
4
+ Summary: Track and evaluate Pipecat agent sessions with automatic metrics, transcripts, and usage analytics
5
+ Author-email: superbryndev <support@superbryndev.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/superbryndev/superbryn-pipecat-observer
8
+ Project-URL: Documentation, https://docs.superbryn.com/monitor/integrations#pipecat-sdk
9
+ Project-URL: Repository, https://github.com/superbryndev/superbryn-pipecat-observer
10
+ Project-URL: Issues, https://github.com/superbryndev/superbryn-pipecat-observer/issues
11
+ Keywords: pipecat,agents,analytics,metrics,evaluation,voice-ai,observability
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Topic :: Communications :: Telephony
21
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: pipecat-ai>=0.0.50
26
+ Requires-Dist: aiohttp>=3.9.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0; extra == "dev"
29
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
30
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # SuperBryn Pipecat Observer
34
+
35
+ [![PyPI version](https://badge.fury.io/py/superbryn-pipecat-observer.svg)](https://badge.fury.io/py/superbryn-pipecat-observer)
36
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
37
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
38
+
39
+ **Track and evaluate your [Pipecat](https://github.com/pipecat-ai/pipecat) voice AI agents with just 2 lines of code.**
40
+
41
+ Automatically capture transcripts, usage metrics, latency data, and session analytics from your Pipecat pipelines. Perfect for monitoring, debugging, and optimizing your voice AI applications.
42
+
43
+ ## ✨ Features
44
+
45
+ - 🎯 **2-Line Integration** - Add to any Pipecat agent in seconds
46
+ - 📝 **Precise Transcripts** - Speaker turns with timestamps from `TranscriptionFrame` and `TextFrame` events
47
+ - 📊 **Usage Metrics** - Track LLM tokens, TTS character counts, STT duration
48
+ - ⚡ **Latency Tracking** - Response time between user speech end and bot response start (avg + p95)
49
+ - 🔍 **Auto-Detection** - Automatically extracts models, providers, and voice IDs from your services
50
+ - 📞 **Telephony Ready** - Pass `from_number` / `to_number` / `transport` for SIP / Daily / Twilio / WebRTC calls
51
+ - 🎥 **Recording URLs** - Forward egress recording links if your transport produces them
52
+ - 🛡️ **Fail-Open** - Never crashes your pipeline if telemetry delivery fails
53
+ - 🔐 **Secure** - API key authentication with HTTPS webhook delivery
54
+ - 🔄 **Frame-Version Tolerant** - Detects frames by class name so a Pipecat upgrade won't hard-break the observer
55
+
56
+ ## 🚀 Quick Start
57
+
58
+ ### Prerequisites
59
+
60
+ 1. **Get your API key** from [https://app.superbryn.com/api-keys](https://app.superbryn.com/api-keys)
61
+ 2. **Set environment variable:**
62
+ ```bash
63
+ export SUPERBRYN_API_KEY=your_api_key_here
64
+ ```
65
+
66
+ ### Installation
67
+
68
+ ```bash
69
+ pip install superbryn-pipecat-observer
70
+ ```
71
+
72
+ ### Integration (2 Lines)
73
+
74
+ Add these lines to your Pipecat agent:
75
+
76
+ ```python
77
+ from pipecat.pipeline.task import PipelineTask, PipelineParams
78
+ from superbryn_pipecat_observer import SuperbrynObserver # 1. Import
79
+
80
+ task = PipelineTask(
81
+ pipeline,
82
+ params=PipelineParams(
83
+ enable_usage_metrics=True, # required for token / TTS char counts
84
+ observers=[SuperbrynObserver(agent_name="support-bot")], # 2. Add observer
85
+ ),
86
+ )
87
+ ```
88
+
89
+ **That's it!** 🎉 Every completed call shows up in your SuperBryn **Monitor → Calls** view within seconds of session end.
90
+
91
+ > ⚠️ **Important:** `enable_usage_metrics=True` must be set on `PipelineParams` for LLM token counts and TTS character counts to be captured.
92
+
93
+ ## 📖 Full Example
94
+
95
+ Here's a complete working example:
96
+
97
+ ```python
98
+ import os
99
+
100
+ from pipecat.pipeline.pipeline import Pipeline
101
+ from pipecat.pipeline.runner import PipelineRunner
102
+ from pipecat.pipeline.task import PipelineParams, PipelineTask
103
+ from pipecat.services.cartesia.tts import CartesiaTTSService
104
+ from pipecat.services.deepgram.stt import DeepgramSTTService
105
+ from pipecat.services.openai.llm import OpenAILLMService
106
+ from pipecat.transports.network.fastapi_websocket import FastAPIWebsocketTransport
107
+
108
+ from superbryn_pipecat_observer import SuperbrynObserver
109
+
110
+
111
+ async def main(transport: FastAPIWebsocketTransport) -> None:
112
+ stt = DeepgramSTTService(api_key=os.environ["DEEPGRAM_API_KEY"])
113
+ llm = OpenAILLMService(api_key=os.environ["OPENAI_API_KEY"], model="gpt-4o-mini")
114
+ tts = CartesiaTTSService(
115
+ api_key=os.environ["CARTESIA_API_KEY"],
116
+ voice_id="your-voice-id",
117
+ )
118
+
119
+ pipeline = Pipeline([
120
+ transport.input(),
121
+ stt,
122
+ llm,
123
+ tts,
124
+ transport.output(),
125
+ ])
126
+
127
+ # Drop in the observer — that's the whole integration
128
+ task = PipelineTask(
129
+ pipeline,
130
+ params=PipelineParams(
131
+ enable_usage_metrics=True,
132
+ observers=[
133
+ SuperbrynObserver(
134
+ agent_name="support-bot",
135
+ transport="websocket",
136
+ ),
137
+ ],
138
+ ),
139
+ )
140
+
141
+ await PipelineRunner().run(task)
142
+ ```
143
+
144
+ ## 🔧 Configuration
145
+
146
+ ### Environment Variables
147
+
148
+ | Variable | Required | Description | Default |
149
+ |----------|----------|-------------|---------|
150
+ | `SUPERBRYN_API_KEY` | ✅ Yes | API key for webhook authentication | - |
151
+ | `AGENT_ID` | ⚪ Optional | Unique agent identifier stamped on every call | `"pipecat-agent"` |
152
+ | `VERSION_ID` | ⚪ Optional | Agent version identifier | `"v1"` |
153
+
154
+ ### Setting Environment Variables
155
+
156
+ **Linux/Mac:**
157
+ ```bash
158
+ export SUPERBRYN_API_KEY=your_api_key_here
159
+ ```
160
+
161
+ **Windows (CMD):**
162
+ ```cmd
163
+ set SUPERBRYN_API_KEY=your_api_key_here
164
+ ```
165
+
166
+ **Windows (PowerShell):**
167
+ ```powershell
168
+ $env:SUPERBRYN_API_KEY="your_api_key_here"
169
+ ```
170
+
171
+ **Docker:**
172
+ ```bash
173
+ docker run -e SUPERBRYN_API_KEY=your_api_key_here ...
174
+ ```
175
+
176
+ **.env file:**
177
+ ```env
178
+ SUPERBRYN_API_KEY=your_api_key_here
179
+ AGENT_ID=customer-support-bot
180
+ VERSION_ID=v1.2.0
181
+ ```
182
+
183
+ ## 📊 What Gets Tracked
184
+
185
+ ### Transcript Data
186
+ - Speaker turns (`user` / `agent`)
187
+ - Per-turn `start_time_ms` / `end_time_ms` (relative to call start)
188
+ - Per-turn confidence score (when STT provides it)
189
+ - Per-bot-turn `latency_ms` (gap between user stop and bot response start)
190
+ - Empty turns are filtered out before send
191
+
192
+ ### Usage Metrics (`MetricsFrame`)
193
+ Captured automatically when `enable_usage_metrics=True`:
194
+ - **LLM:** input tokens, output tokens, model, provider (from `LLMUsageMetricsData`)
195
+ - **TTS:** character count, model, provider, voice ID (from `TTSUsageMetricsData`)
196
+ - **STT:** model, provider (audio duration is reserved for future use — Pipecat does not currently emit an STT usage metric)
197
+
198
+ ### Latency Metrics
199
+ - Per-turn response delay (user stop → bot speak start)
200
+ - Aggregated **average** and **p95** across the call
201
+ - Surfaced under `call.latency` in the payload
202
+
203
+ ### Session Metadata
204
+ - Agent ID, agent name, transport (e.g. `daily`, `twilio`, `webrtc`)
205
+ - LLM / STT / TTS provider, model, voice ID
206
+ - Pipeline / SDK version tag
207
+ - Optional `recording_url`, `from_number`, `to_number`
208
+ - Any `extra_metadata` you pass in
209
+ - Call end reason (`completed` / `cancelled`)
210
+
211
+ ## 🔍 How It Works
212
+
213
+ 1. **Pipeline Observation** - Registered via `PipelineParams(observers=[...])` — runs **alongside** your pipeline, not inside it
214
+ 2. **Frame Inspection** - `on_push_frame` watches every frame flowing between processors and aggregates by class name (so a Pipecat upgrade doesn't break it)
215
+ 3. **Auto-Detection** - Inspects the module path of each service (`*.stt.*`, `*.llm.*`, `*.tts.*`) to tag providers automatically
216
+ 4. **Webhook Delivery** - When `on_pipeline_finished` fires, builds a normalized call payload and POSTs it to SuperBryn
217
+
218
+ ### Webhook Payload Format
219
+
220
+ ```json
221
+ {
222
+ "event": "call.completed",
223
+ "sdk_version": "@superbryn/pipecat-observer@0.1.0",
224
+ "call": {
225
+ "id": "550e8400-e29b-41d4-a716-446655440000",
226
+ "session_id": "550e8400-e29b-41d4-a716-446655440000",
227
+ "started_at": "2026-06-15T12:00:00.000+00:00",
228
+ "ended_at": "2026-06-15T12:05:30.000+00:00",
229
+ "duration_seconds": 330.0,
230
+ "call_end_reason": "completed",
231
+ "from_number": "+15551234567",
232
+ "to_number": "+15557654321",
233
+ "transcript": {
234
+ "turns": [
235
+ {
236
+ "speaker": "user",
237
+ "text": "Hello, how are you?",
238
+ "start_time_ms": 5000,
239
+ "end_time_ms": 5000,
240
+ "confidence": null
241
+ },
242
+ {
243
+ "speaker": "agent",
244
+ "text": "I'm doing great, thanks for asking!",
245
+ "start_time_ms": 7000,
246
+ "end_time_ms": 11000,
247
+ "latency_ms": 2000
248
+ }
249
+ ]
250
+ },
251
+ "recording_url": "https://...",
252
+ "metadata": {
253
+ "agent_id": "support-bot",
254
+ "agent_name": "support-bot",
255
+ "transport": "daily",
256
+ "llm_provider": "openai",
257
+ "llm_model": "gpt-4o-mini",
258
+ "stt_provider": "deepgram",
259
+ "stt_model": "nova-3",
260
+ "tts_provider": "cartesia",
261
+ "tts_model": "sonic-english",
262
+ "tts_voice_id": "...",
263
+ "pipeline_version": "@superbryn/pipecat-observer@0.1.0"
264
+ },
265
+ "usage": {
266
+ "llm_input_tokens": 1250,
267
+ "llm_output_tokens": 850,
268
+ "stt_duration_seconds": 0.0,
269
+ "tts_characters": 1200
270
+ },
271
+ "latency": {
272
+ "avg_ms": 750.5,
273
+ "p95_ms": 1240.0
274
+ }
275
+ }
276
+ }
277
+ ```
278
+
279
+ #### Field availability notes
280
+
281
+ - **`transcript.turns[].confidence`** — present in the schema for forward compatibility, but Pipecat's stable `TranscriptionFrame` (as of 1.3.0) does not carry a confidence score, so this field is `null` in practice today.
282
+ - **`usage.stt_duration_seconds`** — placeholder; Pipecat 1.3.0 does not emit an STT usage metric (no `STTUsageMetricsData` exists upstream), so this field is always `0.0`. It will start populating automatically once Pipecat ships STT usage metrics.
283
+ - **`recording_url`, `from_number`, `to_number`, `transport`** — only set if you pass them into `SuperbrynObserver(...)`. Otherwise `null`.
284
+
285
+ ## 🛠️ Advanced Usage
286
+
287
+ ### Custom API Key
288
+
289
+ Pass the API key directly instead of using the environment variable:
290
+
291
+ ```python
292
+ SuperbrynObserver(
293
+ agent_name="support-bot",
294
+ api_key="sb_live_...",
295
+ )
296
+ ```
297
+
298
+ ### Telephony / Transport Metadata
299
+
300
+ ```python
301
+ SuperbrynObserver(
302
+ agent_name="support-bot",
303
+ transport="twilio", # "daily" | "twilio" | "webrtc" | "websocket" | ...
304
+ from_number="+15551234567",
305
+ to_number="+15557654321",
306
+ recording_url="https://...", # if your transport produces one
307
+ )
308
+ ```
309
+
310
+ ### Custom Metadata
311
+
312
+ Attach any key/value pairs you want to see on the call record:
313
+
314
+ ```python
315
+ SuperbrynObserver(
316
+ agent_name="support-bot",
317
+ extra_metadata={
318
+ "campaign": "summer-promo",
319
+ "tenant_id": "acme-corp",
320
+ "experiment": "prompt-v3",
321
+ },
322
+ )
323
+ ```
324
+
325
+ ### Explicit Agent ID
326
+
327
+ Override the `AGENT_ID` env var per-observer:
328
+
329
+ ```python
330
+ SuperbrynObserver(
331
+ agent_name="support-bot",
332
+ agent_id="prod-support-v3",
333
+ )
334
+ ```
335
+
336
+ ## 🐛 Troubleshooting
337
+
338
+ ### Webhook Not Sending
339
+
340
+ **Check API Key:**
341
+ ```bash
342
+ echo $SUPERBRYN_API_KEY
343
+ ```
344
+
345
+ **Enable Debug Logging:**
346
+ ```python
347
+ import logging
348
+ logging.basicConfig(level=logging.DEBUG)
349
+ logging.getLogger("superbryn_pipecat_observer").setLevel(logging.DEBUG)
350
+ ```
351
+
352
+ **Look for these log messages:**
353
+ - `SUPERBRYN_PIPECAT_CALL_STARTED` - Observer initialized for this session
354
+ - `SUPERBRYN_PIPECAT_SENDING` - Webhook about to be sent
355
+ - `SUPERBRYN_PIPECAT_SENT` - Webhook delivered successfully
356
+ - `SUPERBRYN_PIPECAT_AUTH_FAILED` - Invalid or revoked API key (401/403)
357
+ - `SUPERBRYN_PIPECAT_HTTP_*` - Non-2xx response from server
358
+ - `SUPERBRYN_PIPECAT_ERROR` - Network / exception during delivery
359
+ - `SUPERBRYN_PIPECAT_SKIPPED` - No API key configured (observer no-ops)
360
+ - `SUPERBRYN_PIPECAT_MISSING_AIOHTTP` - `aiohttp` not installed in the runtime
361
+
362
+ ### Common Errors
363
+
364
+ | Error | Cause | Solution |
365
+ |-------|-------|----------|
366
+ | `SUPERBRYN_API_KEY not configured` | Missing API key | Set `SUPERBRYN_API_KEY` environment variable |
367
+ | `SUPERBRYN_PIPECAT_AUTH_FAILED (401)` | Invalid API key | Verify the key in SuperBryn Monitor → API keys |
368
+ | `SUPERBRYN_PIPECAT_AUTH_FAILED (403)` | Expired / disabled key | Generate a new API key |
369
+ | `SUPERBRYN_PIPECAT_MISSING_AIOHTTP` | `aiohttp` missing | `pip install aiohttp>=3.9.0` |
370
+
371
+ ### Missing Usage Metrics
372
+
373
+ Pipecat only emits `MetricsFrame`s when usage metrics are enabled at the task level:
374
+
375
+ ```python
376
+ PipelineParams(enable_usage_metrics=True, observers=[...])
377
+ ```
378
+
379
+ Without this flag, you'll still get the transcript, latency, and provider detection — but `llm_input_tokens`, `llm_output_tokens`, and `tts_characters` will be `0`.
380
+
381
+ ### Provider Detection Issues
382
+
383
+ The observer auto-detects providers from the producing service's module path and model name. Supported providers include:
384
+
385
+ **LLM:** OpenAI, Anthropic, Google (Gemini), Meta (Llama), Mistral, Cohere, Perplexity, Groq, Together AI, Replicate, Hugging Face
386
+
387
+ **STT:** Deepgram, AssemblyAI, Rev.ai, Speechmatics, Gladia, OpenAI Whisper
388
+
389
+ **TTS:** ElevenLabs, Cartesia, PlayHT, Resemble AI, Murf, WellSaid Labs, Speechify, Sarvam, Azure, AWS Polly, Google Cloud
390
+
391
+ **Transport:** Daily, Twilio, LiveKit, Vonage
392
+
393
+ If your provider isn't detected, it will show as `"unknown"` but the call still tracks normally.
394
+
395
+ ## 🤝 Contributing
396
+
397
+ Contributions are welcome! Please feel free to submit a Pull Request.
398
+
399
+ ## 📄 License
400
+
401
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
402
+
403
+ ## 🔗 Links
404
+
405
+ - [Pipecat Documentation](https://docs.pipecat.ai/)
406
+ - [GitHub Repository](https://github.com/superbryndev/superbryn-pipecat-observer)
407
+ - [Issue Tracker](https://github.com/superbryndev/superbryn-pipecat-observer/issues)
408
+ - [Get API Key](https://app.superbryn.com/api-keys)
409
+
410
+ ## 💡 Support
411
+
412
+ - 📧 Email: support@superbryn.com
413
+ - 💬 GitHub Issues: [Report a bug](https://github.com/superbryndev/superbryn-pipecat-observer/issues)
414
+ - 📚 Documentation: [README](https://github.com/superbryndev/superbryn-pipecat-observer#readme)
415
+
416
+ ---
417
+
418
+ Made with ❤️ by [SuperBryn](https://www.superbryn.com)