Skip to main content

Introduction

Voice-enabled AI applications present unique challenges when it comes to testing, monitoring, and iterating on your prompts and models. This guide demonstrates how Freeplay’s observability and prompt management tools can support your development workflow when building voice applications. In this example, we show how to use Freeplay together with Pipecat and Twilio.

What is Pipecat?

Pipecat is a powerful open source framework for building voice-enabled, real-time, multimodal AI applications. When paired with Twilio for real-time voice over the phone, Pipecat enables teams to quickly build audio-based agentic systems that combine both user and bot audio with LLM interactions. This combination creates a strong foundation for the core application, but building a high-quality generative AI product also requires robust monitoring, evaluation, and continuous experimentation. This is where Freeplay helps.

Using Freeplay for Rapid Iteration and Observability

When it comes to monitoring and improving a voice agent, teams often struggle with:
  • Multi-modal Observability: Tracking and analyzing model inputs and outputs across different data types (audio, text, images, files, etc.)
  • Quality Evaluation: Understanding how your application performs in real user scenarios and using evaluation criteria relevant to your product
  • Experimentation & Iteration: Systematically versioning, testing, and deploying changes to prompts, tools, and/or models
  • Team Collaboration: Keeping all team members on the same page when it comes to testing and understanding quality (including non-developers)
Freeplay addresses these challenges by providing a comprehensive solution for prompt and model management, observability, and evaluation that works seamlessly across modalities/data formats — including audio. And Freeplay makes it easy for both technical and non-technical team members to fully participate in the product development and optimization process.

What You’ll Be Able to Monitor

Once implemented, you’ll be able to view complete user interactions in Freeplay, including:
  • Audio recordings from the user and bot turns
  • Transcribed text for easy review and analysis
  • LLM responses with full context
  • Cost & latency metrics for performance optimization
  • Evaluation results against your quality criteria
Once implemented, you’ll be able to view complete user interactions in Freeplay, including:
  • Audio recordings
  • Transcribed text
  • LLM responses
  • Cost & latency metrics
  • Evaluation results

Integration Approaches

Freeplay provides seamless integration with Pipecat to log audio interactions and LLM responses for comprehensive testing and evaluation of your voice agents.

Option 1: Processor Integration

  • How it works: Directly intercepts frames within the pipeline processing flow
  • Trade-off: Adds minimal latency as processing happens inline
  • Best for: Cases where you need direct frame manipulation or synchronous processing
  • Documentation: Pipecat Processors
  • Full Example: FreeplayProcessor
  • How it works: Uses callbacks to log data asynchronously in the background
  • Trade-off: Zero impact on pipeline latency since logging happens outside the main flow
  • Best for: Voice agents where low latency is critical
  • Documentation: Pipecat Observer Pattern
  • Full Example: FreeplayObserver
We recommend the Observer pattern: Since latency is crucial for voice agents, the Observer approach ensures your audio pipeline runs at maximum speed while still capturing all necessary data for Freeplay.

Conversation Flow in a Pipecat + Twilio + Freeplay Integration

Pipecat Pipeline with Freeplay The above image shows how Freeplay integrates into the pipeline. Regardless if you are using the Observer or Processor methods, the logic is very similar. Once both user and bot audio is received and complete, a turn can be logged to Freeplay. This flow ensures comprehensive logging while maintaining optimal performance for real-time voice interactions.

Implementation Guide FreeplayObserver

Pro Tip: AudioBufferProcessor

We highly recommend using Pipecat’s AudioBufferProcessor alongside the FreeplayObserver. This well-tested utility:
  • Formats audio data consistently for logging
  • Provides reliable callbacks for conversation turn detection
  • Simplifies audio handling and storage
This implementation guide uses the Twilio-Chatbot example provided by Pipecat—a chatbot accessed via phone application powered by Twilio. This integration allows you to log audio interactions and LLM responses to Freeplay for comprehensive testing and evaluation of your audio agents.

Prerequisites

Before starting, make sure you have:
  1. A Freeplay account set up (follow our quick start guide)
  2. Your prompts configured in Freeplay (follow our prompting guide)
  3. A working Pipecat + Twilio application
For a complete code example, see our FreeplayObserver Pipecat Recipe.

Step 1: Import Prompt Configuration from Freeplay

First, fetch your prompt configuration from Freeplay and prepare it for use in your Pipecat pipeline:
Why bind the prompt? This approach allows you to fetch the prompt once and reuse it throughout the conversation, avoiding repeated API calls to Freeplay while still allowing you to add new variables and information at each conversation turn.

Step 2: Create Your Freeplay Observer

Create a FreeplayObserver to handle conversation memory, frame monitoring, and data logging. See the full code here.

Step 3: Configure Your Pipeline with Audio Buffering

Set up your Pipecat pipeline with the FreeplayObserver and audio buffering capabilities:

Step 4: Set Up Audio Capture Callbacks & Configure Pipeline

Configure callbacks to capture audio at the optimal moments:
  1. Add the FreeplayObserver to Your Pipeline
  2. Initialize at Conversation Level The FreeplayObserver must be initialized at the conversation level to properly track the entire interaction flow.
  3. Automatic Frame Processing As audio frames pass through the observer’s on_push_frame method, it automatically updates the processor variables with both user and bot audio data and metadata.
  4. Recording with AudioBufferProcessor Callbacks To determine the optimal timing for recording to Freeplay, we recommend using AudioBufferProcessor callbacks:
    1. on_bot_turn_audio_data - Captures when the bot completes its audio response
    2. on_user_turn_audio_data - Captures when the user finishes speaking
These callbacks provide the most reliable trigger points for logging complete conversation turns.

Alternative: FreeplayProcessor Integration

Step 1: Import Your Prompt from Freeplay & Pass to the LLMProcessor

Note, here we get an unformatted prompt from Freeplay and then bind it, this allows us to pass it to the system and not have to make repeated calls to retrieve the llm prompt from Freeplay. The binding allows us to add new variables and information at each turn of the conversation. You can see morehere.

Step 2: Create a Freeplay Processor

The processor handles the memory of the conversation, processing of key frames, and and keeps track of information to log to Freeplay. This inherits from FrameProcessor in Pipecat. See the full code implementation here.

Note: It is required to modify the processes_frame function in pipecat’s base_llm.py to pass along the OpenAILLMContext frame, this makes the handling easier in the FreeplayLLMLogger - process_frame:

Step 3: Add the FreeplayProcessor To Your Pipeline

Initialize your FreeplayProcessor and add it as a step in your pipeline. It is recommended that you add this after the STT or the audioBuffer steps in your pipeline so that all of the information needed is available when you log to Freeplay.

Step 4: Start logging completions

Begin capturing real user interactions in Freeplay, this is a function of the FreeplayProcessor. The audio is being added to the conversation history for proper tracking.

Helpful resources:

Configure LiteLLM Proxy Models in Freeplay Security Overview