Pipecat Flows
Learn how to create structured conversations using Pipecat’s flow system
Pipecat Flows provides a framework for building structured conversations in your AI applications. It enables you to create both predefined conversation paths and dynamically generated flows while handling the complexities of state management and LLM interactions.
The framework consists of:
- A Python module for building conversation flows with Pipecat
- A visual editor for designing and exporting flow configurations
Key Concepts
- Nodes: Represent conversation states with specific messages and available functions
- Messages: Set the role and tasks for each node
- Functions: Define actions and transitions (Node functions for operations, Edge functions for transitions)
- Actions: Execute operations during state transitions (pre/post actions)
- State Management: Handle conversation state and data persistence
Example Flows
Movie Explorer (Static)
A static flow demonstrating movie exploration using OpenAI. Shows real API integration with TMDB, structured data collection, and state management.
Insurance Policy (Dynamic)
A dynamic flow using Google Gemini that adapts policy recommendations based on user responses. Demonstrates runtime node creation and conditional paths.
These examples are fully functional and can be run locally. Make sure you have the required dependencies installed and API keys configured.
When to Use Static vs Dynamic Flows
Static Flows are ideal when:
- Conversation structure is known upfront
- Paths follow predefined patterns
- Flow can be fully configured in advance
- Example: Customer service scripts, intake forms
Dynamic Flows are better when:
- Paths depend on external data
- Flow structure needs runtime modification
- Complex decision trees are involved
- Example: Personalized recommendations, adaptive workflows
Installation
If you’re already using Pipecat:
If you’re starting fresh:
💡 Want to design your flows visually? Try the online Flow Editor
Core Concepts
Designing Conversation Flows
Functions in Pipecat Flows serve two key purposes:
- interfacing with external systems and APIs
- advancing the conversation to the next node
Function Handlers
When you need to collect data, validate input, or retrieve information, add a handler to your function. These handlers are async functions that execute when the LLM calls the function, allowing you to interact with databases, APIs, or other external services:
Transitioning Between Nodes
To advance the conversation, Pipecat Flows offers two approaches based on your flow type:
For static flows, use the transition_to
property to specify the next node:
For dynamic flows, use a transition callback to determine the next node at runtime:
You can combine both approaches: use handlers to process data and transitions to advance the conversation, creating flows that are both functional and conversational.
Node Structure
Each node in your flow represents a conversation state and consists of three main components:
Messages
Nodes use two types of messages to control the conversation:
- Role Messages: Define the bot’s personality or role (optional)
- Task Messages: Define what the bot should do in the current node
Role messages are typically defined in your initial node and inherited by subsequent nodes, while task messages are specific to each node’s purpose.
Functions
Functions in Pipecat Flows can:
- Process data (using
handler
) - Create transitions (using
transition_to
) - Do both simultaneously
This leads to two conceptual types of functions:
Node Functions
Functions that process data within a state. They typically:
- Have a
handler
to interface with external systems or APIs - May optionally include
transition_to
to move to another state after processing
Edge Functions
Functions that create transitions between states. They:
- Must have
transition_to
to specify the next state - May optionally include a
handler
to perform operations during transition
A function’s behavior is determined by its properties:
handler
only: Process data, stay in current statetransition_to
only: Pure transition to next state- Both: Process data, then transition
Actions
Actions are operations that execute during state transitions, with two distinct timing options:
Pre-Actions
Execute before LLM inference. Useful for:
- Providing immediate feedback while waiting for LLM responses
- Bridging gaps during longer function calls
- Setting up state or context
Avoid mixing tts_say
actions with chat completions as this may result in a
conversation flow that feels unnatural. tts_say
are best used as filler
words when the LLM will take time to generate an completion.
Post-Actions
Execute after LLM inference completes. Useful for:
- Cleanup operations
- State finalization
- Ensuring proper sequence of operations
Timing Considerations
- Pre-actions: Execute immediately, before any LLM processing begins
- LLM Inference: Processes the node’s messages and functions
- Post-actions: Execute only after LLM processing and TTS completion
For example, when using end_conversation
as a post-action, the sequence is:
- LLM generates response
- TTS speaks the response
- End conversation action executes
This ordering ensures proper completion of all operations.
State Management
The state
variable in FlowManager is a shared dictionary that persists throughout the conversation. Think of it as a conversation memory that lets you:
- Store user information
- Track conversation progress
- Share data between nodes
- Inform decision-making
Here’s a practical example of a pizza ordering flow:
In this example:
select_size
initializes the order and stores the sizeselect_toppings
builds a list of toppingsfinalize_order
uses the stored information to process the complete order
The state variable makes it easy to:
- Build up information across multiple interactions
- Access previous choices when needed
- Validate the complete order
- Calculate final results
This is particularly useful when information needs to be collected across multiple conversation turns or when later decisions depend on earlier choices.
LLM Provider Support
Pipecat Flows automatically handles format differences between LLM providers:
OpenAI Format
Anthropic Format
Google (Gemini) Format
You don’t need to handle these differences manually - Pipecat Flows adapts your configuration to the correct format based on your LLM provider.
Implementation Approaches
Static Flows
Static flows use a configuration-driven approach where the entire conversation structure is defined upfront.
Basic Setup
Example Configuration
Transition Best Practices
- Use
transition_to
to make state changes explicit - Combine handlers with transitions when appropriate
- Keep transitions focused on single responsibilities
- Use clear, descriptive names for target nodes
- Validate all transition targets exist
- Test both successful and failed transitions
Dynamic Flows
Dynamic flows create and modify conversation paths at runtime based on data or business logic.
Basic Setup
Node Creation
Best Practices
- Keep state in flow_manager.state
- Create separate functions for node creation
- Handle errors gracefully in transitions
- Document state dependencies
- Test node creation and transitions thoroughly
Flow Editor
The Pipecat Flow Editor provides a visual interface for creating and managing conversation flows. It offers a node-based interface that makes it easier to design, visualize, and modify your flows.
Visual Design
Node Types
-
Start Node (Green): Entry point of your flow
-
Flow Nodes (Blue): Intermediate states
-
End Node (Red): Final state
-
Function Nodes:
- Edge Functions (Purple): Create transitions
- Node Functions (Orange): Perform operations
- Edge Functions (Purple): Create transitions
Naming Conventions
- Start Node: Use descriptive names (e.g., “greeting”, “welcome”)
- Flow Nodes: Name based on purpose (e.g., “collect_info”, “verify_data”)
- End Node: Conventionally named “end”
- Functions: Use clear, action-oriented names
Function Configuration
When using the Flow Editor, function handlers can be specified using the __function__:
token:
The handler will be looked up in your main script when the flow is executed.
When function handlers are specified in the flow editor, they will be exported
with the __function__:
token.
Using the Editor
Creating a New Flow
- Start with a descriptively named Start Node
- Add Flow Nodes for each conversation state
- Connect nodes using Edge Functions
- Add Node Functions for operations
- Include an End Node
Import/Export
Tips
- Use the visual preview to verify flow logic
- Test exported configurations
- Document node purposes and transitions
- Keep flows modular and maintainable
Try the editor at flows.pipecat.ai